-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthieu Jacquot
committed
Aug 2, 2018
1 parent
c917199
commit 47e32d0
Showing
19 changed files
with
313 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package articleValidator | ||
|
||
import ( | ||
"github.com/err0r500/go-realworld-clean/domain" | ||
"github.com/err0r500/go-realworld-clean/uc" | ||
) | ||
|
||
type validator struct { | ||
} | ||
|
||
func New() uc.ArticleValidator { | ||
return validator{} | ||
} | ||
|
||
func (validator) BeforeCreationCheck(article *domain.Article) error { return nil } | ||
func (validator) BeforeUpdateCheck(article *domain.Article) error { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package slugger | ||
|
||
import ( | ||
"github.com/err0r500/go-realworld-clean/uc" | ||
"github.com/gosimple/slug" | ||
) | ||
|
||
type slugger struct{} | ||
|
||
func New() uc.Slugger { | ||
return slugger{} | ||
} | ||
|
||
func (slugger) NewSlug(initial string) string { | ||
return slug.Make(initial) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package articleRW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package commentRW | ||
|
||
import ( | ||
"sync" | ||
|
||
"errors" | ||
|
||
"github.com/err0r500/go-realworld-clean/domain" | ||
"github.com/err0r500/go-realworld-clean/uc" | ||
) | ||
|
||
type rw struct { | ||
store *sync.Map | ||
} | ||
|
||
func New() uc.CommentRW { | ||
return rw{ | ||
store: &sync.Map{}, | ||
} | ||
} | ||
|
||
func (rw rw) Create(comment domain.Comment) (*domain.Comment, error) { | ||
if _, err := rw.GetByID(comment.ID); err == nil { | ||
return nil, uc.ErrAlreadyInUse | ||
} | ||
|
||
rw.store.Store(comment.ID, comment) | ||
|
||
return rw.GetByID(comment.ID) | ||
} | ||
|
||
func (rw rw) GetByID(id int) (*domain.Comment, error) { | ||
value, ok := rw.store.Load(id) | ||
if !ok { | ||
return nil, uc.ErrNotFound | ||
} | ||
|
||
comment, ok := value.(domain.Comment) | ||
if !ok { | ||
return nil, errors.New("not an article stored at key") | ||
} | ||
|
||
return &comment, nil | ||
} | ||
|
||
func (rw rw) Delete(id int) error { | ||
rw.store.Delete(id) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package commentRW_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package tagsRW | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/err0r500/go-realworld-clean/uc" | ||
) | ||
|
||
type rw struct { | ||
store *sync.Map | ||
} | ||
|
||
func New() uc.TagsRW { | ||
return rw{ | ||
store: &sync.Map{}, | ||
} | ||
} | ||
|
||
// lots of ways to improve this (use an array as cache, use index access instead of append...) | ||
// no perf problem for now => no optimisation :) | ||
func (rw rw) GetAll() ([]string, error) { | ||
var toReturn []string | ||
|
||
rw.store.Range(func(key, value interface{}) bool { | ||
tag, ok := key.(string) | ||
if !ok { | ||
return true | ||
} | ||
toReturn = append(toReturn, tag) | ||
return true | ||
}) | ||
|
||
return toReturn, nil | ||
} | ||
|
||
func (rw rw) Add(newTags []string) error { | ||
|
||
for _, tag := range newTags { | ||
rw.store.Store(tag, true) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.