fixed relationship issues
This commit is contained in:
@@ -23,7 +23,7 @@ type Season struct {
|
||||
}
|
||||
|
||||
type SeasonList struct {
|
||||
Seasons []Season
|
||||
Seasons []*Season
|
||||
Total int
|
||||
PageOpts PageOpts
|
||||
}
|
||||
@@ -50,24 +50,10 @@ func NewSeason(ctx context.Context, tx bun.Tx, name, shortname string, start tim
|
||||
}
|
||||
|
||||
func ListSeasons(ctx context.Context, tx bun.Tx, pageOpts *PageOpts) (*SeasonList, error) {
|
||||
if pageOpts == nil {
|
||||
pageOpts = &PageOpts{}
|
||||
}
|
||||
if pageOpts.Page == 0 {
|
||||
pageOpts.Page = 1
|
||||
}
|
||||
if pageOpts.PerPage == 0 {
|
||||
pageOpts.PerPage = 10
|
||||
}
|
||||
if pageOpts.Order == "" {
|
||||
pageOpts.Order = bun.OrderDesc
|
||||
}
|
||||
if pageOpts.OrderBy == "" {
|
||||
pageOpts.OrderBy = "start_date"
|
||||
}
|
||||
seasons := []Season{}
|
||||
pageOpts = setDefaultPageOpts(pageOpts, 1, 10, bun.OrderDesc, "start_date")
|
||||
seasons := new([]*Season)
|
||||
err := tx.NewSelect().
|
||||
Model(&seasons).
|
||||
Model(seasons).
|
||||
OrderBy(pageOpts.OrderBy, pageOpts.Order).
|
||||
Offset(pageOpts.PerPage * (pageOpts.Page - 1)).
|
||||
Limit(pageOpts.PerPage).
|
||||
@@ -76,13 +62,13 @@ func ListSeasons(ctx context.Context, tx bun.Tx, pageOpts *PageOpts) (*SeasonLis
|
||||
return nil, errors.Wrap(err, "tx.NewSelect")
|
||||
}
|
||||
total, err := tx.NewSelect().
|
||||
Model(&seasons).
|
||||
Model(seasons).
|
||||
Count(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "tx.NewSelect")
|
||||
}
|
||||
sl := &SeasonList{
|
||||
Seasons: seasons,
|
||||
Seasons: *seasons,
|
||||
Total: total,
|
||||
PageOpts: *pageOpts,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user