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

fix menu order by sql #36

Merged
merged 1 commit into from
Jan 27, 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
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
Loading