Skip to content

Refactored project structure #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/assert/assert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package assert

import (
"reflect"
"testing"
)

func Equals(t *testing.T, expected interface{}, actual interface{}) {
if !reflect.DeepEqual(expected, actual) {
t.Errorf("%+v is not equal to %+v", expected, actual)
}
}
11 changes: 11 additions & 0 deletions internal/criteria/criteria.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package criteria

// CollabStyle ..
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more out of annoyance. The linter in VScode keeps complaining when you don't put a comment. I don't know how to turn off the linter rule. I'm ok to delete them. I mostly use goland, so it's not much of an issue for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There got to be a way. I would say it is ok to keep them in this PR,
and the next PR add .vscode/settings.json to turn it off and remove these comments.
And in the travis turn on any linter check. I know that go compiler do some linting itself, but don't know about which linter the vscode extension based on.

Copy link
Contributor Author

@xstrengthofonex xstrengthofonex Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have looked, but wasn't able to find a way. I ended up just creating a snippet that added them automatically.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these comments supposed to be doc generating comments?

Copy link
Collaborator

@akessner akessner Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I see these are required. We should probably add godoc to the travis yaml.
https://golang.org/doc/effective_go.html#commentary

Since these comments are actually treated like code, they probably don't break the clean code "no comment" rules. And we should probably fill them in. Thoughts?
I'll raise this on the channel.

type CollabStyle int

const (
Team CollabStyle = iota + 1
Pair
Mob
)

17 changes: 17 additions & 0 deletions internal/filter/on_collab_style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package filter

import (
"github.com/clean-code-projects/co-coders-api/internal/criteria"
"github.com/clean-code-projects/co-coders-api/internal/user"
)

// OnCollabStyle ..
func OnCollabStyle(users []user.User, coStyle criteria.CollabStyle) (matchedUsers []user.User) {
matchedUsers = []user.User{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note for later.

If we use this style on all the match filters then we will end up looping through the entire user database multiple times.
We should make note to eventually only loop through the user DB once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this

Copy link
Contributor Author

@xstrengthofonex xstrengthofonex Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also had a thought about this type of filter method. Because it's filtering out all the users that don't match with this specific criteria, if you were to use a chain of filters (in a functional way), the 'filtered out' users would not be present to be matched to other criterias. So, perhaps just returning the matching users might not be enough.

Instead we might want to consider using a new data structure that contains the user and a list of matches that have occurred. The function would be less of a filter and more of a matcher.

for _, aUser := range users {
if aUser.HasCollabStyle(coStyle) {
matchedUsers = append(matchedUsers, aUser)
}
}
return matchedUsers
}
41 changes: 41 additions & 0 deletions internal/filter/on_collab_style_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package filter_test

import (
"github.com/clean-code-projects/co-coders-api/internal/assert"
"github.com/clean-code-projects/co-coders-api/internal/criteria"
"github.com/clean-code-projects/co-coders-api/internal/filter"
"github.com/clean-code-projects/co-coders-api/internal/user"

"testing"
)

func TestFilterOnCoStyleReturnsEmpty(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We changed coStyle to colabStyle, but didn't update the test names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I forgot to update them. I'll do that.

style := criteria.Team
actual := filter.OnCollabStyle([]user.User{}, style)
assert.Equals(t, []user.User{}, actual)
}

func TestFilterOnCoStyleReturnsNoMatch(t *testing.T) {
aUser := user.New([]criteria.CollabStyle{criteria.Team})
users := []user.User{aUser}
style := criteria.Mob
actual := filter.OnCollabStyle(users, style)
assert.Equals(t, []user.User{}, actual)
}

func TestFilterOnCoStyleReturnsAMatch(t *testing.T) {
aUser := user.New([]criteria.CollabStyle{criteria.Team})
users := []user.User{aUser}
style := criteria.Team
actual := filter.OnCollabStyle(users, style)
assert.Equals(t, []user.User{aUser}, actual)
}

func TestFilterOnCoStyleSubsetReturnsAMatch(t *testing.T) {
aUser := user.New([]criteria.CollabStyle{criteria.Team, criteria.Pair})
users := []user.User{aUser}
criterion := criteria.Team
actual := filter.OnCollabStyle(users, criterion)
assert.Equals(t, []user.User{aUser}, actual)
}

23 changes: 23 additions & 0 deletions internal/user/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package user

import "github.com/clean-code-projects/co-coders-api/internal/criteria"

// User ..
type User struct {
CollabStyles []criteria.CollabStyle
}

// HasCollabStyle ..
func (u User) HasCollabStyle(collabStyle criteria.CollabStyle) bool {
for _, style := range u.CollabStyles {
if style == collabStyle {
return true
}
}
return false
}

// New ..
func New(collabStyles []criteria.CollabStyle) User {
return User{CollabStyles: collabStyles}
}
79 changes: 0 additions & 79 deletions match_test.go

This file was deleted.