submissions: reintroduce mapfix fields

This commit is contained in:
Quaternions 2025-04-01 14:34:06 -07:00
parent de8f869b5b
commit 37560ac5d2
Signed by: Quaternions
GPG Key ID: D0DF5964F79AC131
2 changed files with 22 additions and 0 deletions
pkg

@ -23,6 +23,9 @@ const (
type Mapfix struct {
ID int64 `gorm:"primaryKey"`
DisplayName string
Creator string
GameID int32
CreatedAt time.Time
UpdatedAt time.Time
Submitter int64 // UserID

@ -95,6 +95,9 @@ func (svc *Service) CreateMapfix(ctx context.Context, request *api.MapfixCreate)
mapfix, err := svc.DB.Mapfixes().Create(ctx, model.Mapfix{
ID: 0,
DisplayName: request.DisplayName,
Creator: request.Creator,
GameID: request.GameID,
Submitter: int64(userId),
AssetID: request.AssetID,
AssetVersion: request.AssetVersion,
@ -122,6 +125,9 @@ func (svc *Service) GetMapfix(ctx context.Context, params api.GetMapfixParams) (
}
return &api.Mapfix{
ID: mapfix.ID,
DisplayName: mapfix.DisplayName,
Creator: mapfix.Creator,
GameID: mapfix.GameID,
CreatedAt: mapfix.CreatedAt.Unix(),
UpdatedAt: mapfix.UpdatedAt.Unix(),
Submitter: int64(mapfix.Submitter),
@ -142,6 +148,16 @@ func (svc *Service) GetMapfix(ctx context.Context, params api.GetMapfixParams) (
func (svc *Service) ListMapfixes(ctx context.Context, params api.ListMapfixesParams) ([]api.Mapfix, error) {
filter := datastore.Optional()
if params.DisplayName.IsSet(){
filter.Add("display_name", params.DisplayName.Value)
}
if params.Creator.IsSet(){
filter.Add("creator", params.Creator.Value)
}
if params.GameID.IsSet(){
filter.Add("game_id", params.GameID.Value)
}
sort := datastore.ListSort(params.Sort.Or(int32(datastore.ListSortDisabled)))
items, err := svc.DB.Mapfixes().List(ctx, filter, model.Page{
@ -156,6 +172,9 @@ func (svc *Service) ListMapfixes(ctx context.Context, params api.ListMapfixesPar
for _, item := range items {
resp = append(resp, api.Mapfix{
ID: item.ID,
DisplayName: item.DisplayName,
Creator: item.Creator,
GameID: item.GameID,
CreatedAt: item.CreatedAt.Unix(),
UpdatedAt: item.UpdatedAt.Unix(),
Submitter: int64(item.Submitter),