feat: move infra to driver
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eminetto/clean-architecture-go-v2/infra/repository"
|
"github.com/eminetto/clean-architecture-go-v2/driver/repository"
|
||||||
"github.com/eminetto/clean-architecture-go-v2/usecase/book"
|
"github.com/eminetto/clean-architecture-go-v2/usecase/book"
|
||||||
"github.com/eminetto/clean-architecture-go-v2/usecase/user"
|
"github.com/eminetto/clean-architecture-go-v2/usecase/user"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/eminetto/clean-architecture-go-v2/infra/repository"
|
"github.com/eminetto/clean-architecture-go-v2/driver/repository"
|
||||||
"github.com/eminetto/clean-architecture-go-v2/usecase/book"
|
"github.com/eminetto/clean-architecture-go-v2/usecase/book"
|
||||||
|
|
||||||
"github.com/eminetto/clean-architecture-go-v2/config"
|
"github.com/eminetto/clean-architecture-go-v2/config"
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@ services:
|
|||||||
image: mysql:5.7
|
image: mysql:5.7
|
||||||
command: --default-authentication-plugin=mysql_native_password --init-file /data/application/init.sql
|
command: --default-authentication-plugin=mysql_native_password --init-file /data/application/init.sql
|
||||||
volumes:
|
volumes:
|
||||||
- ./infra/init.sql:/data/application/init.sql
|
- ./ops/init.sql:/data/application/init.sql
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ROOT_PASSWORD: clean_architecture_go_v2
|
MYSQL_ROOT_PASSWORD: clean_architecture_go_v2
|
||||||
MYSQL_DATABASE: clean_architecture_go_v2
|
MYSQL_DATABASE: clean_architecture_go_v2
|
||||||
@@ -30,7 +30,7 @@ services:
|
|||||||
command:
|
command:
|
||||||
- --config.file=/etc/prometheus/prometheus.yml
|
- --config.file=/etc/prometheus/prometheus.yml
|
||||||
volumes:
|
volumes:
|
||||||
- ./infra/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
- ./ops/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||||
container_name: clean-architecture-go-v2-prometheus
|
container_name: clean-architecture-go-v2-prometheus
|
||||||
network_mode: "bridge"
|
network_mode: "bridge"
|
||||||
prometheus-pushgateway:
|
prometheus-pushgateway:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package repository
|
package book
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@@ -6,27 +6,27 @@ import (
|
|||||||
"github.com/eminetto/clean-architecture-go-v2/entity"
|
"github.com/eminetto/clean-architecture-go-v2/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
//BookInmem in memory repo
|
//inmem in memory repo
|
||||||
type BookInmem struct {
|
type inmem struct {
|
||||||
m map[entity.ID]*entity.Book
|
m map[entity.ID]*entity.Book
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewBookInmem create new repository
|
//newInmem create new repository
|
||||||
func NewBookInmem() *BookInmem {
|
func newInmem() *inmem {
|
||||||
var m = map[entity.ID]*entity.Book{}
|
var m = map[entity.ID]*entity.Book{}
|
||||||
return &BookInmem{
|
return &inmem{
|
||||||
m: m,
|
m: m,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create a book
|
//Create a book
|
||||||
func (r *BookInmem) Create(e *entity.Book) (entity.ID, error) {
|
func (r *inmem) Create(e *entity.Book) (entity.ID, error) {
|
||||||
r.m[e.ID] = e
|
r.m[e.ID] = e
|
||||||
return e.ID, nil
|
return e.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get a book
|
//Get a book
|
||||||
func (r *BookInmem) Get(id entity.ID) (*entity.Book, error) {
|
func (r *inmem) Get(id entity.ID) (*entity.Book, error) {
|
||||||
if r.m[id] == nil {
|
if r.m[id] == nil {
|
||||||
return nil, entity.ErrNotFound
|
return nil, entity.ErrNotFound
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ func (r *BookInmem) Get(id entity.ID) (*entity.Book, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Update a book
|
//Update a book
|
||||||
func (r *BookInmem) Update(e *entity.Book) error {
|
func (r *inmem) Update(e *entity.Book) error {
|
||||||
_, err := r.Get(e.ID)
|
_, err := r.Get(e.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -44,7 +44,7 @@ func (r *BookInmem) Update(e *entity.Book) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Search books
|
//Search books
|
||||||
func (r *BookInmem) Search(query string) ([]*entity.Book, error) {
|
func (r *inmem) Search(query string) ([]*entity.Book, error) {
|
||||||
var d []*entity.Book
|
var d []*entity.Book
|
||||||
for _, j := range r.m {
|
for _, j := range r.m {
|
||||||
if strings.Contains(strings.ToLower(j.Title), query) {
|
if strings.Contains(strings.ToLower(j.Title), query) {
|
||||||
@@ -55,7 +55,7 @@ func (r *BookInmem) Search(query string) ([]*entity.Book, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//List books
|
//List books
|
||||||
func (r *BookInmem) List() ([]*entity.Book, error) {
|
func (r *inmem) List() ([]*entity.Book, error) {
|
||||||
var d []*entity.Book
|
var d []*entity.Book
|
||||||
for _, j := range r.m {
|
for _, j := range r.m {
|
||||||
d = append(d, j)
|
d = append(d, j)
|
||||||
@@ -64,7 +64,7 @@ func (r *BookInmem) List() ([]*entity.Book, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Delete a book
|
//Delete a book
|
||||||
func (r *BookInmem) Delete(id entity.ID) error {
|
func (r *inmem) Delete(id entity.ID) error {
|
||||||
if r.m[id] == nil {
|
if r.m[id] == nil {
|
||||||
return entity.ErrNotFound
|
return entity.ErrNotFound
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eminetto/clean-architecture-go-v2/entity"
|
"github.com/eminetto/clean-architecture-go-v2/entity"
|
||||||
"github.com/eminetto/clean-architecture-go-v2/infra/repository"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -21,7 +20,7 @@ func newFixtureBook() *entity.Book {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_Create(t *testing.T) {
|
func Test_Create(t *testing.T) {
|
||||||
repo := repository.NewBookInmem()
|
repo := newInmem()
|
||||||
m := NewService(repo)
|
m := NewService(repo)
|
||||||
u := newFixtureBook()
|
u := newFixtureBook()
|
||||||
_, err := m.CreateBook(u.Title, u.Author, u.Pages, u.Quantity)
|
_, err := m.CreateBook(u.Title, u.Author, u.Pages, u.Quantity)
|
||||||
@@ -30,7 +29,7 @@ func Test_Create(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_SearchAndFind(t *testing.T) {
|
func Test_SearchAndFind(t *testing.T) {
|
||||||
repo := repository.NewBookInmem()
|
repo := newInmem()
|
||||||
m := NewService(repo)
|
m := NewService(repo)
|
||||||
u1 := newFixtureBook()
|
u1 := newFixtureBook()
|
||||||
u2 := newFixtureBook()
|
u2 := newFixtureBook()
|
||||||
@@ -63,7 +62,7 @@ func Test_SearchAndFind(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_Update(t *testing.T) {
|
func Test_Update(t *testing.T) {
|
||||||
repo := repository.NewBookInmem()
|
repo := newInmem()
|
||||||
m := NewService(repo)
|
m := NewService(repo)
|
||||||
u := newFixtureBook()
|
u := newFixtureBook()
|
||||||
id, err := m.CreateBook(u.Title, u.Author, u.Pages, u.Quantity)
|
id, err := m.CreateBook(u.Title, u.Author, u.Pages, u.Quantity)
|
||||||
@@ -77,7 +76,7 @@ func Test_Update(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDelete(t *testing.T) {
|
func TestDelete(t *testing.T) {
|
||||||
repo := repository.NewBookInmem()
|
repo := newInmem()
|
||||||
m := NewService(repo)
|
m := NewService(repo)
|
||||||
u1 := newFixtureBook()
|
u1 := newFixtureBook()
|
||||||
u2 := newFixtureBook()
|
u2 := newFixtureBook()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package repository
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -7,27 +7,27 @@ import (
|
|||||||
"github.com/eminetto/clean-architecture-go-v2/entity"
|
"github.com/eminetto/clean-architecture-go-v2/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
//UserInmem in memory repo
|
//inmem in memory repo
|
||||||
type UserInmem struct {
|
type inmem struct {
|
||||||
m map[entity.ID]*entity.User
|
m map[entity.ID]*entity.User
|
||||||
}
|
}
|
||||||
|
|
||||||
//NewUserInmem create new repository
|
//newInmem create new repository
|
||||||
func NewUserInmem() *UserInmem {
|
func newInmem() *inmem {
|
||||||
var m = map[entity.ID]*entity.User{}
|
var m = map[entity.ID]*entity.User{}
|
||||||
return &UserInmem{
|
return &inmem{
|
||||||
m: m,
|
m: m,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create an user
|
//Create an user
|
||||||
func (r *UserInmem) Create(e *entity.User) (entity.ID, error) {
|
func (r *inmem) Create(e *entity.User) (entity.ID, error) {
|
||||||
r.m[e.ID] = e
|
r.m[e.ID] = e
|
||||||
return e.ID, nil
|
return e.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get an user
|
//Get an user
|
||||||
func (r *UserInmem) Get(id entity.ID) (*entity.User, error) {
|
func (r *inmem) Get(id entity.ID) (*entity.User, error) {
|
||||||
if r.m[id] == nil {
|
if r.m[id] == nil {
|
||||||
return nil, entity.ErrNotFound
|
return nil, entity.ErrNotFound
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func (r *UserInmem) Get(id entity.ID) (*entity.User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Update an user
|
//Update an user
|
||||||
func (r *UserInmem) Update(e *entity.User) error {
|
func (r *inmem) Update(e *entity.User) error {
|
||||||
_, err := r.Get(e.ID)
|
_, err := r.Get(e.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -45,7 +45,7 @@ func (r *UserInmem) Update(e *entity.User) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Search users
|
//Search users
|
||||||
func (r *UserInmem) Search(query string) ([]*entity.User, error) {
|
func (r *inmem) Search(query string) ([]*entity.User, error) {
|
||||||
var d []*entity.User
|
var d []*entity.User
|
||||||
for _, j := range r.m {
|
for _, j := range r.m {
|
||||||
if strings.Contains(strings.ToLower(j.FirstName), query) {
|
if strings.Contains(strings.ToLower(j.FirstName), query) {
|
||||||
@@ -60,7 +60,7 @@ func (r *UserInmem) Search(query string) ([]*entity.User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//List users
|
//List users
|
||||||
func (r *UserInmem) List() ([]*entity.User, error) {
|
func (r *inmem) List() ([]*entity.User, error) {
|
||||||
var d []*entity.User
|
var d []*entity.User
|
||||||
for _, j := range r.m {
|
for _, j := range r.m {
|
||||||
d = append(d, j)
|
d = append(d, j)
|
||||||
@@ -69,7 +69,7 @@ func (r *UserInmem) List() ([]*entity.User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Delete an user
|
//Delete an user
|
||||||
func (r *UserInmem) Delete(id entity.ID) error {
|
func (r *inmem) Delete(id entity.ID) error {
|
||||||
if r.m[id] == nil {
|
if r.m[id] == nil {
|
||||||
return fmt.Errorf("not found")
|
return fmt.Errorf("not found")
|
||||||
}
|
}
|
||||||
@@ -4,8 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eminetto/clean-architecture-go-v2/infra/repository"
|
|
||||||
|
|
||||||
"github.com/eminetto/clean-architecture-go-v2/entity"
|
"github.com/eminetto/clean-architecture-go-v2/entity"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -23,7 +21,7 @@ func newFixtureUser() *entity.User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_Create(t *testing.T) {
|
func Test_Create(t *testing.T) {
|
||||||
repo := repository.NewUserInmem()
|
repo := newInmem()
|
||||||
m := NewService(repo)
|
m := NewService(repo)
|
||||||
u := newFixtureUser()
|
u := newFixtureUser()
|
||||||
_, err := m.CreateUser(u.Email, u.Password, u.FirstName, u.LastName)
|
_, err := m.CreateUser(u.Email, u.Password, u.FirstName, u.LastName)
|
||||||
@@ -33,7 +31,7 @@ func Test_Create(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_SearchAndFind(t *testing.T) {
|
func Test_SearchAndFind(t *testing.T) {
|
||||||
repo := repository.NewUserInmem()
|
repo := newInmem()
|
||||||
m := NewService(repo)
|
m := NewService(repo)
|
||||||
u1 := newFixtureUser()
|
u1 := newFixtureUser()
|
||||||
u2 := newFixtureUser()
|
u2 := newFixtureUser()
|
||||||
@@ -66,7 +64,7 @@ func Test_SearchAndFind(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_Update(t *testing.T) {
|
func Test_Update(t *testing.T) {
|
||||||
repo := repository.NewUserInmem()
|
repo := newInmem()
|
||||||
m := NewService(repo)
|
m := NewService(repo)
|
||||||
u := newFixtureUser()
|
u := newFixtureUser()
|
||||||
id, err := m.CreateUser(u.Email, u.Password, u.FirstName, u.LastName)
|
id, err := m.CreateUser(u.Email, u.Password, u.FirstName, u.LastName)
|
||||||
@@ -83,7 +81,7 @@ func Test_Update(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDelete(t *testing.T) {
|
func TestDelete(t *testing.T) {
|
||||||
repo := repository.NewUserInmem()
|
repo := newInmem()
|
||||||
m := NewService(repo)
|
m := NewService(repo)
|
||||||
u1 := newFixtureUser()
|
u1 := newFixtureUser()
|
||||||
u2 := newFixtureUser()
|
u2 := newFixtureUser()
|
||||||
|
|||||||
Reference in New Issue
Block a user