Skip to content

Commit

Permalink
Merge pull request #30 from ogurilab/feature/fix-menu-domain
Browse files Browse the repository at this point in the history
fix re menu
  • Loading branch information
shouta0715 authored Jan 9, 2024
2 parents e2f3a8e + 60aee69 commit 5c70342
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 1,579 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
name: Run unit Tests

on:
push:
branches: ['main', 'develop']
pull_request:
branches: ['main', 'develop']
paths:
- 'app/**'

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion app/doc/api
Submodule api updated 1 files
+228 −75 spec/open-api.yaml
32 changes: 14 additions & 18 deletions app/domain/menu_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,30 @@ type MenuWithDishes struct {
type MenuRepository interface {
Create(ctx context.Context, menu *Menu) error
GetByID(ctx context.Context, id string, city int32) (*Menu, error)
Fetch(ctx context.Context, limit int32, offset int32, city int32) ([]*Menu, error)
GetByDate(ctx context.Context, offeredAt time.Time, city int32) (*Menu, error)
FetchByRangeDate(ctx context.Context, start, end time.Time, city int32, limit int32) ([]*Menu, error)
}

type MenuWithDishesRepository interface {
GetByID(ctx context.Context, id string, city int32) (*MenuWithDishes, error)
Fetch(ctx context.Context, limit int32, offset int32, city int32) ([]*MenuWithDishes, error)
GetByDate(ctx context.Context, offeredAt time.Time, city int32) (*MenuWithDishes, error)
FetchByRangeDate(ctx context.Context, start, end time.Time, city int32, limit int32) ([]*MenuWithDishes, error)
FetchByCity(ctx context.Context, limit int32, offset int32, offered time.Time, city int32) ([]*Menu, error)
}

type MenuUsecase interface {
Create(ctx context.Context, menu *Menu) error
GetByID(ctx context.Context, id string, city int32) (*Menu, error)
Fetch(ctx context.Context, limit int32, offset int32, city int32) ([]*Menu, error)
GetByDate(ctx context.Context, offeredAt time.Time, city int32) (*Menu, error)
FetchByRangeDate(ctx context.Context, start, end time.Time, city int32, limit int32) ([]*Menu, error)
FetchByCity(ctx context.Context, limit int32, offset int32, offered time.Time, city int32) ([]*Menu, error)
}

type MenuWithDishesUsecase interface {
/************************
* MenuWithDishes
************************/

type MenuWithDishesRepository interface {
GetByID(ctx context.Context, id string, city int32) (*MenuWithDishes, error)
Fetch(ctx context.Context, limit int32, offset int32, city int32) ([]*MenuWithDishes, error)
GetByDate(ctx context.Context, offeredAt time.Time, city int32) (*MenuWithDishes, error)
FetchByRangeDate(ctx context.Context, start, end time.Time, city int32, limit int32) ([]*MenuWithDishes, error)
FetchByCity(ctx context.Context, limit int32, offset int32, offered time.Time, city int32) ([]*MenuWithDishes, error)
Fetch(ctx context.Context, limit int32, offset int32, offered time.Time) ([]*MenuWithDishes, error)
}

type MenuController interface{}
type MenuWithDishesUsecase interface {
GetByID(ctx context.Context, id string, city int32) (*MenuWithDishes, error)
FetchByCity(ctx context.Context, limit int32, offset int32, offered time.Time, city int32) ([]*MenuWithDishes, error)
Fetch(ctx context.Context, limit int32, offset int32, offered time.Time) ([]*MenuWithDishes, error)
}

func newMenu(
id string,
Expand Down
259 changes: 73 additions & 186 deletions app/domain/mocks/menu_domain.go

Large diffs are not rendered by default.

47 changes: 7 additions & 40 deletions app/infrastructure/db/query/menu.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,14 @@ FROM menus
WHERE id = sqlc.arg(id)
AND city_code = sqlc.arg(city_code);

-- name: ListMenus :many
-- name: ListMenuByCity :many
SELECT *
FROM menus AS m
WHERE city_code = sqlc.arg(city_code)
AND offered_at >= sqlc.arg(offered_at)
ORDER BY offered_at
LIMIT ? OFFSET ?;

-- name: ListMenusByOfferedAt :many
SELECT *
FROM menus
WHERE offered_at >= sqlc.arg(start_offered_at)
AND offered_at < sqlc.arg(end_offered_at)
AND city_code = sqlc.arg(city_code)
ORDER BY offered_at
LIMIT ?;

-- name: GetMenuByOfferedAt :one
SELECT *
FROM menus
WHERE offered_at = sqlc.arg(offered_at)
AND city_code = sqlc.arg(city_code);

-- name: GetMenuWithDishes :one
SELECT m.*,
JSON_ARRAYAGG(
Expand All @@ -62,7 +48,7 @@ WHERE m.id = sqlc.arg(id)
AND m.city_code = sqlc.arg(city_code)
GROUP BY m.id;

-- name: ListMenuWithDishes :many
-- name: ListMenuWithDishesByCity :many
SELECT m.*,
JSON_ARRAYAGG(
JSON_OBJECT(
Expand All @@ -77,29 +63,12 @@ SELECT m.*,
FROM menus AS m
LEFT JOIN dishes AS d ON m.id = d.menu_id
WHERE m.city_code = sqlc.arg(city_code)
AND m.offered_at >= sqlc.arg(offered_at)
GROUP BY m.id
ORDER BY offered_at
LIMIT ? OFFSET ?;

-- name: GetMenuWithDishesByOfferedAt :one
SELECT m.*,
JSON_ARRAYAGG(
JSON_OBJECT(
'id',
d.id,
'name',
d.name,
'menu_id',
d.menu_id
)
) AS dishes
FROM menus AS m
LEFT JOIN dishes AS d ON m.id = d.menu_id
WHERE m.offered_at = sqlc.arg(offered_at)
AND m.city_code = sqlc.arg(city_code)
GROUP BY m.id;

-- name: ListMenuWithDishesByOfferedAt :many
-- name: ListMenuWithDishes :many
SELECT m.*,
JSON_ARRAYAGG(
JSON_OBJECT(
Expand All @@ -113,9 +82,7 @@ SELECT m.*,
) AS dishes
FROM menus AS m
LEFT JOIN dishes AS d ON m.id = d.menu_id
WHERE m.offered_at >= sqlc.arg(start_offered_at)
AND m.offered_at <= sqlc.arg(end_offered_at)
AND m.city_code = sqlc.arg(city_code)
WHERE m.offered_at >= sqlc.arg(offered_at)
GROUP BY m.id
ORDER BY offered_at
LIMIT ?;
LIMIT ? OFFSET ?;
Loading

0 comments on commit 5c70342

Please sign in to comment.