Skip to content

Commit

Permalink
fix: city response
Browse files Browse the repository at this point in the history
  • Loading branch information
shouta0715 committed Jan 11, 2024
1 parent 36e63b8 commit 0964375
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 209 deletions.
3 changes: 2 additions & 1 deletion app/domain/city_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type City struct {

type CityRepository interface {
GetByCityCode(ctx context.Context, code int32) (*City, error)
Fetch(ctx context.Context, limit int32, offset int32, search string) ([]*City, error)
FetchByName(ctx context.Context, limit int32, offset int32, search string) ([]*City, error)
Fetch(ctx context.Context, limit int32, offset int32) ([]*City, error)
FetchByPrefectureCode(ctx context.Context, limit int32, offset int32, prefectureCode int32) ([]*City, error)
}

Expand Down
24 changes: 0 additions & 24 deletions app/domain/common.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
package domain

import "time"

const (
DEFAULT_LIMIT = int32(10)
DEFAULT_OFFSET = int32(0)
)

type Response struct {
Data interface{} `json:"data"`
}

type FetchResponse struct {
Data interface{} `json:"data"`
Next interface{} `json:"next"`
}

func NewResponse(data interface{}) *Response {
return &Response{
Data: data,
}
}

func NewFetchResponse[T string | int32 | time.Time](data interface{}, next T) *FetchResponse {
return &FetchResponse{
Data: data,
Next: next,
}
}
36 changes: 0 additions & 36 deletions app/domain/common_test.go

This file was deleted.

23 changes: 19 additions & 4 deletions app/domain/mocks/city_domain.go

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

54 changes: 27 additions & 27 deletions app/infrastructure/repository/city_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,41 @@ func (r *cityRepository) GetByCityCode(ctx context.Context, code int32) (*domain

}

func (r *cityRepository) Fetch(ctx context.Context, limit int32, offset int32, search string) ([]*domain.City, error) {

if search != "" {
arg := db.ListCitiesByNameParams{
Limit: limit,
Offset: offset,
CityName: search,
}

result, err := r.query.ListCitiesByName(ctx, arg)
if err != nil {
return nil, err
}

var cities []*domain.City

for _, city := range result {
cities = append(cities, domain.NewCity(
city.CityCode,
city.CityName,
city.PrefectureCode,
city.PrefectureName,
))
}

return cities, nil
func (r *cityRepository) FetchByName(ctx context.Context, limit int32, offset int32, search string) ([]*domain.City, error) {

arg := db.ListCitiesByNameParams{
Limit: limit,
Offset: offset,
CityName: search,
}

result, err := r.query.ListCitiesByName(ctx, arg)
if err != nil {
return nil, err
}

var cities []*domain.City

for _, city := range result {
cities = append(cities, domain.NewCity(
city.CityCode,
city.CityName,
city.PrefectureCode,
city.PrefectureName,
))
}

return cities, nil
}

func (r *cityRepository) Fetch(ctx context.Context, limit int32, offset int32) ([]*domain.City, error) {
arg := db.ListCitiesParams{
Limit: limit,
Offset: offset,
}

result, err := r.query.ListCities(ctx, arg)

if err != nil {
return nil, err
}
Expand All @@ -86,7 +87,6 @@ func (r *cityRepository) Fetch(ctx context.Context, limit int32, offset int32, s
}

return cities, nil

}

func (r *cityRepository) FetchByPrefectureCode(ctx context.Context, limit int32, offset int32, prefectureCode int32) ([]*domain.City, error) {
Expand Down
Loading

0 comments on commit 0964375

Please sign in to comment.