Skip to content
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

Dish API wIth Menu #41

Merged
merged 9 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ build_swagger:
rm -rf ${APP_PATH}/doc/swagger/statik
cd ${APP_PATH} && statik -src=./doc/swagger -dest=./doc

rebuild_prod:
$(DOCKER_COMPOSE) -f docker-compose.yaml down
$(DOCKER_COMPOSE) -f docker-compose.yaml up -d --build

# 半田市のデータをデータベースに追加
seed_handa:
docker compose cp ./ops/docker/entrypoint/data/ mysql:tmp/data/
Expand Down
2 changes: 1 addition & 1 deletion app/doc/api
Submodule api updated 1 files
+81 −5 spec/open-api.yaml
2 changes: 1 addition & 1 deletion app/doc/statik/statik.go

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions app/domain/dish_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,31 @@ type Dish struct {
Name string `json:"name"`
}

type DishWithMenuIDs struct {
Dish
MenuIDs []string `json:"menu_ids"`
}

type DishRepository interface {
Create(ctx context.Context, dish *Dish, menuID string) error
GetByID(ctx context.Context, id string) (*Dish, error)
GetByID(ctx context.Context, id string, limit int32, offset int32) (*DishWithMenuIDs, error)
GetByIdInCity(ctx context.Context, id string, limit int32, offset int32, city int32) (*DishWithMenuIDs, error)
FetchByMenuID(ctx context.Context, menuID string) ([]*Dish, error)
FetchByName(ctx context.Context, search string, limit int32, offset int32) ([]*Dish, error)
Fetch(ctx context.Context, limit int32, offset int32) ([]*Dish, error)
}

type DishUsecase interface {
Create(ctx context.Context, dish *Dish, menuID string) error
GetByID(ctx context.Context, id string) (*Dish, error)
GetByID(ctx context.Context, id string, limit int32, offset int32) (*DishWithMenuIDs, error)
GetByIdInCity(ctx context.Context, id string, limit int32, offset int32, city int32) (*DishWithMenuIDs, error)
FetchByMenuID(ctx context.Context, menuID string) ([]*Dish, error)
Fetch(ctx context.Context, search string, limit int32, offset int32) ([]*Dish, error)
}

type DishController interface {
GetByID(c echo.Context) error
GetByIdInCity(c echo.Context) error
FetchByMenuID(c echo.Context) error
Fetch(c echo.Context) error
}
Expand All @@ -49,8 +57,23 @@ func ReNewDish(id string, name string) (*Dish, error) {

return newDish(id, name)
}

func NewDish(name string) (*Dish, error) {
id := util.NewUlid()

return newDish(id, name)
}

func ReNewDishWithMenuIDs(id string, name string, menuIDs []string) (*DishWithMenuIDs, error) {

dish, err := newDish(id, name)

if err != nil {
return nil, err
}

return &DishWithMenuIDs{
Dish: *dish,
MenuIDs: menuIDs,
}, nil
}
64 changes: 54 additions & 10 deletions app/domain/mocks/dish_domain.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions app/infrastructure/db/query/dish.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@
INSERT INTO dishes (id, name)
VALUES (sqlc.arg(id), sqlc.arg(name));

-- name: GetDish :one
-- name: GetDish :many
SELECT dishes.id,
dishes.name
dishes.name,
md.menu_id AS menu_id
FROM dishes
INNER JOIN menu_dishes AS md ON dishes.id = md.dish_id
WHERE dishes.id = sqlc.arg(id)
ORDER BY dishes.id
LIMIT ? OFFSET ?;

-- name: GetDishInCity :many
SELECT dishes.id,
dishes.name,
md.menu_id AS menu_id
FROM dishes
WHERE id = sqlc.arg(id)
LIMIT 1;
INNER JOIN menu_dishes AS md ON dishes.id = md.dish_id
INNER JOIN menus AS m ON md.menu_id = m.id
WHERE dishes.id = sqlc.arg(id)
AND m.city_code = sqlc.arg(city_code)
ORDER BY dishes.id
LIMIT ? OFFSET ?;

-- name: ListDishByMenuID :many
SELECT dishes.id,
Expand Down
102 changes: 91 additions & 11 deletions app/infrastructure/db/sqlc/dish.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading