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

add: cities table and users table and data_source table #16

Merged
merged 4 commits into from
Nov 29, 2023
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sqlc:


test:
cd ${APP_PATH} && DB_SOURCE="${TEST_DB_URL}" go test -v -short -cover ./...
cd ${APP_PATH} && DB_SOURCE="${TEST_DB_URL}" go test -count=1 -v -short -cover ./...


.PHONY: up down start prod prod_stop migrateup migratedown new_migration sqlc test
56 changes: 32 additions & 24 deletions app/domain/menu_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package domain

import (
"context"
"database/sql"
"time"

"github.com/ogurilab/school-lunch-api/util"
)

type Menu struct {
ID string `json:"id"`
OfferedAt time.Time `json:"offered_at"`
PhotoUrl string `json:"photo_url"`
ElementarySchoolCalories int32 `json:"elementary_school_calories"`
JuniorHighSchoolCalories int32 `json:"junior_high_school_calories"`
ID string `json:"id"`
OfferedAt time.Time `json:"offered_at"`
PhotoUrl sql.NullString `json:"photo_url"`
ElementarySchoolCalories int32 `json:"elementary_school_calories"`
JuniorHighSchoolCalories int32 `json:"junior_high_school_calories"`
CityCode int32 `json:"city_code"`
}

type MenuWithDishes struct {
Expand All @@ -22,38 +24,39 @@ type MenuWithDishes struct {

type MenuRepository interface {
Create(ctx context.Context, menu *Menu) error
GetByID(ctx context.Context, id string) (*Menu, error)
Fetch(ctx context.Context, limit int32, offset int32) ([]*Menu, error)
GetByDate(ctx context.Context, offeredAt time.Time) (*Menu, error)
FetchByRangeDate(ctx context.Context, start, end time.Time) ([]*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) ([]*Menu, error)

// MenuWithDishes
GetByIDWithDishes(ctx context.Context, id string) (*MenuWithDishes, error)
FetchWithDishes(ctx context.Context, limit int32, offset int32) ([]*MenuWithDishes, error)
GetByDateWithDishes(ctx context.Context, offeredAt time.Time) (*MenuWithDishes, error)
FetchByRangeDateWithDishes(ctx context.Context, start, end time.Time) ([]*MenuWithDishes, error)
GetByIDWithDishes(ctx context.Context, id string, city int32) (*MenuWithDishes, error)
FetchWithDishes(ctx context.Context, limit int32, offset int32, city int32) ([]*MenuWithDishes, error)
GetByDateWithDishes(ctx context.Context, offeredAt time.Time, city int32) (*MenuWithDishes, error)
FetchByRangeDateWithDishes(ctx context.Context, start, end time.Time, city int32) ([]*MenuWithDishes, error)
}

type MenuUsecase interface {
Create(ctx context.Context, menu *Menu) error
GetByID(ctx context.Context, id string) (*Menu, error)
Fetch(ctx context.Context, limit int32, offset int32) ([]*Menu, error)
GetByDate(ctx context.Context, offeredAt time.Time) (*Menu, error)
FetchByRangeDate(ctx context.Context, start, end time.Time) ([]*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) ([]*Menu, error)

// MenuWithDishes
GetByIDWithDishes(ctx context.Context, id string) (*MenuWithDishes, error)
FetchWithDishes(ctx context.Context, limit int32, offset int32) ([]*MenuWithDishes, error)
GetByDateWithDishes(ctx context.Context, offeredAt time.Time) (*MenuWithDishes, error)
FetchByRangeDateWithDishes(ctx context.Context, start, end time.Time) ([]*MenuWithDishes, error)
GetByIDWithDishes(ctx context.Context, id string, city int32) (*MenuWithDishes, error)
FetchWithDishes(ctx context.Context, limit int32, offset int32, city int32) ([]*MenuWithDishes, error)
GetByDateWithDishes(ctx context.Context, offeredAt time.Time, city int32) (*MenuWithDishes, error)
FetchByRangeDateWithDishes(ctx context.Context, start, end time.Time, city int32) ([]*MenuWithDishes, error)
}

func newMenu(
id string,
offeredAt time.Time,
photoUrl string,
photoUrl sql.NullString,
elementarySchoolCalories int32,
juniorHighSchoolCalories int32,
cityCode int32,
) (*Menu, error) {

if _, err := util.ParseUlid(id); err != nil {
Expand All @@ -66,30 +69,34 @@ func newMenu(
PhotoUrl: photoUrl,
ElementarySchoolCalories: elementarySchoolCalories,
JuniorHighSchoolCalories: juniorHighSchoolCalories,
CityCode: cityCode,
}, nil
}

func ReNewMenu(
id string,
offeredAt time.Time,
photoUrl string,
photoUrl sql.NullString,
elementarySchoolCalories int32,
juniorHighSchoolCalories int32,
cityCode int32,
) (*Menu, error) {
return newMenu(
id,
offeredAt,
photoUrl,
elementarySchoolCalories,
juniorHighSchoolCalories,
cityCode,
)
}

func NewMenu(
offeredAt time.Time,
photoUrl string,
photoUrl sql.NullString,
elementarySchoolCalories int32,
juniorHighSchoolCalories int32,
cityCode int32,
) (*Menu, error) {
id := util.NewUlid()
return newMenu(
Expand All @@ -98,5 +105,6 @@ func NewMenu(
photoUrl,
elementarySchoolCalories,
juniorHighSchoolCalories,
cityCode,
)
}
Loading