Skip to content

Commit

Permalink
Merge pull request #36 from ogurilab/feature/fix-menu-order
Browse files Browse the repository at this point in the history
fix menu order by sql
  • Loading branch information
shouta0715 authored Jan 27, 2024
2 parents f317ea6 + 420a35a commit 0be3343
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
12 changes: 6 additions & 6 deletions app/infrastructure/db/query/menu.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ WHERE id = sqlc.arg(id)
SELECT *
FROM menus AS m
WHERE city_code = sqlc.arg(city_code)
AND offered_at >= sqlc.arg(offered_at)
ORDER BY offered_at
AND offered_at <= sqlc.arg(offered_at)
ORDER BY offered_at DESC
LIMIT ? OFFSET ?;

-- name: GetMenuWithDishes :one
Expand Down Expand Up @@ -63,9 +63,9 @@ 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)
AND m.offered_at <= sqlc.arg(offered_at)
GROUP BY m.id
ORDER BY offered_at
ORDER BY offered_at DESC
LIMIT ? OFFSET ?;

-- name: ListMenuWithDishes :many
Expand All @@ -82,7 +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(offered_at)
WHERE m.offered_at <= sqlc.arg(offered_at)
GROUP BY m.id
ORDER BY offered_at
ORDER BY offered_at DESC
LIMIT ? OFFSET ?;
12 changes: 6 additions & 6 deletions app/infrastructure/db/sqlc/menu.sql.go

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

10 changes: 6 additions & 4 deletions app/infrastructure/db/sqlc/menu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,20 @@ func TestGetWithDishes(t *testing.T) {
}

func TestFetchMenuWithDishesByCity(t *testing.T) {
start := time.Now()
for i := 0; i < 10; i++ {
menu := createRandomMenu(t)
menu := createRandomMenuFromStart(t, start)

for j := 0; j < 10; j++ {
createRandomDish(t, menu.ID)
}
}

arg := ListMenuWithDishesByCityParams{
Limit: 5,
Offset: 5,
CityCode: cityCode,
Limit: 5,
Offset: 5,
CityCode: cityCode,
OfferedAt: start,
}

results, err := testQuery.ListMenuWithDishesByCity(context.Background(), arg)
Expand Down
2 changes: 1 addition & 1 deletion app/util/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func RandomYYYYMMDD() string {
func RandomDateFromStart(start time.Time) time.Time {
// YYYY-MM-DD

year := RandomInt(start.Year(), start.Year()+1000)
year := RandomInt(start.Year()-1000, start.Year())
month := RandomInt(1, 12)
day := RandomInt(1, 31)

Expand Down

0 comments on commit 0be3343

Please sign in to comment.