Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
remove domain package as yagni
Browse files Browse the repository at this point in the history
  • Loading branch information
imantung committed Jan 23, 2021
1 parent 4d3d7a2 commit fa1eebf
Show file tree
Hide file tree
Showing 26 changed files with 336 additions and 390 deletions.
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,10 @@ Typical-Rest encourage [standard go project layout](https://github.com/golang-st
Source codes:
- [`internal`](internal): private codes for the project
- [`internal/app`](internal/app)
- [`internal/app/infra`](internal/app/infra): infrastructure for the project e.g. config and connection object
- [`internal/app/domain`](internal/app/domain)
- [`internal/app/domain/mylibrary`](internal/app/domain/mylibrary)
- [`internal/app/domain/mylibrary/controller`](internal/app/domain/mylibrary/controller): presentation for mylibrary domain
- [`internal/app/domain/mylibrary/service`](internal/app/domain/mylibrary/service): logic for mylibrary domain
- [`internal/app/domain/mymusic`](internal/app/domain/mymusic)
- [`internal/app/domain/mymusic/controller`](internal/app/domain/mymusic/controller): presentation for mymusic domain
- [`internal/app/domain/mymusic/service`](internal/app/domain/mymusic/service): logic for mymusic domain
- [`internal/app/data_access`](internal/app/data_access)
- [`internal/app/data_access/postgresdb`](internal/app/data_access/postgresdb): data access to postgresdb
- [`internal/app/data_access/mysqldb`](internal/app/data_access/mysqldb): data access to postgresdb
- [`internal/app/infra`](internal/app/infra): infrastructure for the project e.g. config and connection object
- [`internal/app/entity`](internal/app/entity): database layer entity
- [`internal/app/controller`](internal/app/controller): presentation layer
- [`internal/app/service`](internal/app/service): logic layer
- [`internal/app/generated`](internal/generated): code generated e.g. typical, grpc, xsd, etc.
- [`pkg`](pkg): shareable codes e.g. helper/utitily Library
- [`cmd`](cmd): the main package
Expand Down
16 changes: 8 additions & 8 deletions api/rest-client/mylibrary.http
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@

### Find Books

http://localhost:8089/mylibrary/books?sort=-title,created_at
http://localhost:8089/books?sort=-title,created_at

### Find Books (Pagination)

http://localhost:8089/mylibrary/books?offset=2&limit=2
http://localhost:8089/books?offset=2&limit=2


### Find One Book (Invalid ID)

http://localhost:8089/mylibrary/books/0
http://localhost:8089/books/0


### Insert Book

POST http://localhost:8089/mylibrary/books
POST http://localhost:8089/books
content-type: application/json

{
Expand All @@ -25,12 +25,12 @@ content-type: application/json

### Find One Book

http://localhost:8089/mylibrary/books/6
http://localhost:8089/books/6


### Update Book

PUT http://localhost:8089/mylibrary/books/6
PUT http://localhost:8089/books/6
content-type: application/json

{
Expand All @@ -41,7 +41,7 @@ content-type: application/json

### Patch Book

PATCH http://localhost:8089/mylibrary/books/6
PATCH http://localhost:8089/books/6
content-type: application/json

{
Expand All @@ -50,4 +50,4 @@ content-type: application/json

### Delete Book

DELETE http://localhost:8089/mylibrary/books/6
DELETE http://localhost:8089/books/6
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"

"github.com/labstack/echo/v4"
"github.com/typical-go/typical-rest-server/internal/app/data_access/postgresdb"
"github.com/typical-go/typical-rest-server/internal/app/domain/mylibrary/service"
"github.com/typical-go/typical-rest-server/internal/app/service"
"github.com/typical-go/typical-rest-server/internal/app/entity"
"github.com/typical-go/typical-rest-server/pkg/cachekit"
"github.com/typical-go/typical-rest-server/pkg/echokit"
"go.uber.org/dig"
Expand Down Expand Up @@ -36,7 +36,7 @@ func (c *BookCntrl) SetRoute(e echokit.Server) {

// Create book
func (c *BookCntrl) Create(ec echo.Context) (err error) {
var book postgresdb.Book
var book entity.Book
if err = ec.Bind(&book); err != nil {
return err
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func (c *BookCntrl) Delete(ec echo.Context) (err error) {

// Update book
func (c *BookCntrl) Update(ec echo.Context) (err error) {
var book postgresdb.Book
var book entity.Book
if err = ec.Bind(&book); err != nil {
return err
}
Expand All @@ -103,7 +103,7 @@ func (c *BookCntrl) Update(ec echo.Context) (err error) {

// Patch book
func (c *BookCntrl) Patch(ec echo.Context) (err error) {
var book postgresdb.Book
var book entity.Book
if err = ec.Bind(&book); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/golang/mock/gomock"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/require"
"github.com/typical-go/typical-rest-server/internal/app/data_access/postgresdb"
"github.com/typical-go/typical-rest-server/internal/app/domain/mylibrary/controller"
"github.com/typical-go/typical-rest-server/internal/app/domain/mylibrary/service"
"github.com/typical-go/typical-rest-server/internal/app/domain/mylibrary/service_mock"
"github.com/typical-go/typical-rest-server/internal/app/controller"
"github.com/typical-go/typical-rest-server/internal/app/entity"
"github.com/typical-go/typical-rest-server/internal/app/service"
"github.com/typical-go/typical-rest-server/internal/app/service_mock"
"github.com/typical-go/typical-rest-server/pkg/echokit"
"github.com/typical-go/typical-rest-server/pkg/echotest"
)
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestBookCntrl_FindOne(t *testing.T) {
},
},
BookCntrlFn: func(svc *service_mock.MockBookSvc) {
svc.EXPECT().FindOne(gomock.Any(), "1").Return(&postgresdb.Book{ID: 1, Title: "title1", Author: "author1"}, nil)
svc.EXPECT().FindOne(gomock.Any(), "1").Return(&entity.Book{ID: 1, Title: "title1", Author: "author1"}, nil)
},
},
{
Expand Down Expand Up @@ -141,9 +141,9 @@ func TestBookCntrl_Find(t *testing.T) {
Find(gomock.Any(), &service.FindBookReq{}).
Return(&service.FindBookResp{
TotalCount: "10",
Books: []*postgresdb.Book{
&postgresdb.Book{ID: 1, Title: "title1", Author: "author1"},
&postgresdb.Book{ID: 2, Title: "title2", Author: "author2"},
Books: []*entity.Book{
&entity.Book{ID: 1, Title: "title1", Author: "author1"},
&entity.Book{ID: 2, Title: "title2", Author: "author2"},
},
}, nil)
},
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestBookCntrl_Update(t *testing.T) {
},
BookCntrlFn: func(svc *service_mock.MockBookSvc) {
svc.EXPECT().
Update(gomock.Any(), "1", &postgresdb.Book{ID: 1, Title: "some-title", Author: "some-author"}).
Update(gomock.Any(), "1", &entity.Book{ID: 1, Title: "some-title", Author: "some-author"}).
Return(nil, errors.New("some-error"))
},
},
Expand All @@ -237,8 +237,8 @@ func TestBookCntrl_Update(t *testing.T) {
},
BookCntrlFn: func(svc *service_mock.MockBookSvc) {
svc.EXPECT().
Update(gomock.Any(), "1", &postgresdb.Book{ID: 1, Title: "some-title", Author: "some-author"}).
Return(&postgresdb.Book{ID: 1, Title: "some-title", Author: "some-author"}, nil)
Update(gomock.Any(), "1", &entity.Book{ID: 1, Title: "some-title", Author: "some-author"}).
Return(&entity.Book{ID: 1, Title: "some-title", Author: "some-author"}, nil)
},
},
}
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestBookCntrl_Patch(t *testing.T) {
},
BookCntrlFn: func(svc *service_mock.MockBookSvc) {
svc.EXPECT().
Patch(gomock.Any(), "1", &postgresdb.Book{ID: 1, Title: "some-title", Author: "some-author"}).
Patch(gomock.Any(), "1", &entity.Book{ID: 1, Title: "some-title", Author: "some-author"}).
Return(nil, errors.New("some-error"))
},
},
Expand All @@ -302,8 +302,8 @@ func TestBookCntrl_Patch(t *testing.T) {
},
BookCntrlFn: func(svc *service_mock.MockBookSvc) {
svc.EXPECT().
Patch(gomock.Any(), "1", &postgresdb.Book{ID: 1, Title: "some-title", Author: "some-author"}).
Return(&postgresdb.Book{ID: 1, Title: "some-title", Author: "some-author"}, nil)
Patch(gomock.Any(), "1", &entity.Book{ID: 1, Title: "some-title", Author: "some-author"}).
Return(&entity.Book{ID: 1, Title: "some-title", Author: "some-author"}, nil)
},
},
}
Expand Down Expand Up @@ -419,7 +419,7 @@ func TestBookCntrl_Create(t *testing.T) {
BookCntrlFn: func(svc *service_mock.MockBookSvc) {
svc.EXPECT().
Create(gomock.Any(), gomock.Any()).
Return(&postgresdb.Book{ID: 999, Author: "some-author", Title: "some-title"}, nil)
Return(&entity.Book{ID: 999, Author: "some-author", Title: "some-title"}, nil)
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"net/http"

"github.com/labstack/echo/v4"
"github.com/typical-go/typical-rest-server/internal/app/data_access/mysqldb"
"github.com/typical-go/typical-rest-server/internal/app/domain/mymusic/service"
"github.com/typical-go/typical-rest-server/internal/app/service"
"github.com/typical-go/typical-rest-server/internal/app/entity"
"github.com/typical-go/typical-rest-server/pkg/cachekit"
"github.com/typical-go/typical-rest-server/pkg/echokit"
"go.uber.org/dig"
Expand Down Expand Up @@ -36,7 +36,7 @@ func (c *SongCntrl) SetRoute(e echokit.Server) {

// Create book
func (c *SongCntrl) Create(ec echo.Context) (err error) {
var book mysqldb.Song
var book entity.Song
if err = ec.Bind(&book); err != nil {
return err
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func (c *SongCntrl) Delete(ec echo.Context) (err error) {

// Update book
func (c *SongCntrl) Update(ec echo.Context) (err error) {
var book mysqldb.Song
var book entity.Song
if err = ec.Bind(&book); err != nil {
return err
}
Expand All @@ -103,7 +103,7 @@ func (c *SongCntrl) Update(ec echo.Context) (err error) {

// Patch book
func (c *SongCntrl) Patch(ec echo.Context) (err error) {
var book mysqldb.Song
var book entity.Song
if err = ec.Bind(&book); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

"github.com/golang/mock/gomock"

"github.com/typical-go/typical-rest-server/internal/app/data_access/mysqldb"
"github.com/typical-go/typical-rest-server/internal/app/domain/mymusic/controller"
"github.com/typical-go/typical-rest-server/internal/app/domain/mymusic/service"
"github.com/typical-go/typical-rest-server/internal/app/domain/mymusic/service_mock"
"github.com/typical-go/typical-rest-server/internal/app/controller"
"github.com/typical-go/typical-rest-server/internal/app/service"
"github.com/typical-go/typical-rest-server/internal/app/service_mock"
"github.com/typical-go/typical-rest-server/internal/app/entity"
"github.com/typical-go/typical-rest-server/pkg/echokit"
"github.com/typical-go/typical-rest-server/pkg/echotest"
)
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestSongCntrl_FindOne(t *testing.T) {
},
},
SongCntrlFn: func(svc *service_mock.MockSongSvc) {
svc.EXPECT().FindOne(gomock.Any(), "1").Return(&mysqldb.Song{ID: 1, Title: "title1", Artist: "artist1"}, nil)
svc.EXPECT().FindOne(gomock.Any(), "1").Return(&entity.Song{ID: 1, Title: "title1", Artist: "artist1"}, nil)
},
},
{
Expand Down Expand Up @@ -142,9 +142,9 @@ func TestSongCntrl_Find(t *testing.T) {
svc.EXPECT().
Find(gomock.Any(), &service.FindSongReq{}).
Return(&service.FindSongResp{
Songs: []*mysqldb.Song{
&mysqldb.Song{ID: 1, Title: "title1", Artist: "artist1"},
&mysqldb.Song{ID: 2, Title: "title2", Artist: "artist2"},
Songs: []*entity.Song{
&entity.Song{ID: 1, Title: "title1", Artist: "artist1"},
&entity.Song{ID: 2, Title: "title2", Artist: "artist2"},
},
TotalCount: "10",
}, nil)
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestSongCntrl_Update(t *testing.T) {
},
SongCntrlFn: func(svc *service_mock.MockSongSvc) {
svc.EXPECT().
Update(gomock.Any(), "1", &mysqldb.Song{ID: 1, Title: "some-title", Artist: "some-artist"}).
Update(gomock.Any(), "1", &entity.Song{ID: 1, Title: "some-title", Artist: "some-artist"}).
Return(nil, errors.New("some-error"))
},
},
Expand All @@ -225,8 +225,8 @@ func TestSongCntrl_Update(t *testing.T) {
},
SongCntrlFn: func(svc *service_mock.MockSongSvc) {
svc.EXPECT().
Update(gomock.Any(), "1", &mysqldb.Song{ID: 1, Title: "some-title", Artist: "some-artist"}).
Return(&mysqldb.Song{ID: 1, Title: "some-title", Artist: "some-artist"}, nil)
Update(gomock.Any(), "1", &entity.Song{ID: 1, Title: "some-title", Artist: "some-artist"}).
Return(&entity.Song{ID: 1, Title: "some-title", Artist: "some-artist"}, nil)
},
},
}
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestSongCntrl_Patch(t *testing.T) {
},
SongCntrlFn: func(svc *service_mock.MockSongSvc) {
svc.EXPECT().
Patch(gomock.Any(), "1", &mysqldb.Song{ID: 1, Title: "some-title", Artist: "some-artist"}).
Patch(gomock.Any(), "1", &entity.Song{ID: 1, Title: "some-title", Artist: "some-artist"}).
Return(nil, errors.New("some-error"))
},
},
Expand All @@ -290,8 +290,8 @@ func TestSongCntrl_Patch(t *testing.T) {
},
SongCntrlFn: func(svc *service_mock.MockSongSvc) {
svc.EXPECT().
Patch(gomock.Any(), "1", &mysqldb.Song{ID: 1, Title: "some-title", Artist: "some-artist"}).
Return(&mysqldb.Song{ID: 1, Title: "some-title", Artist: "some-artist"}, nil)
Patch(gomock.Any(), "1", &entity.Song{ID: 1, Title: "some-title", Artist: "some-artist"}).
Return(&entity.Song{ID: 1, Title: "some-title", Artist: "some-artist"}, nil)
},
},
}
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestSongCntrl_Create(t *testing.T) {
SongCntrlFn: func(svc *service_mock.MockSongSvc) {
svc.EXPECT().
Create(gomock.Any(), gomock.Any()).
Return(&mysqldb.Song{ID: 999, Artist: "some-artist", Title: "some-title"}, nil)
Return(&entity.Song{ID: 999, Artist: "some-artist", Title: "some-title"}, nil)
},
},
}
Expand Down
25 changes: 0 additions & 25 deletions internal/app/domain/mylibrary/router.go

This file was deleted.

19 changes: 0 additions & 19 deletions internal/app/domain/mylibrary/router_test.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mysqldb
package entity

import "time"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package postgresdb
package entity

import "time"

Expand Down
Loading

0 comments on commit fa1eebf

Please sign in to comment.