submissions: maps endpoints
This commit is contained in:
parent
bfd287f3cc
commit
e9f79241f1
73
pkg/service/maps.go
Normal file
73
pkg/service/maps.go
Normal file
@ -0,0 +1,73 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.itzana.me/strafesnet/go-grpc/maps"
|
||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||
)
|
||||
|
||||
// ListMaps implements listMaps operation.
|
||||
//
|
||||
// Get list of maps.
|
||||
//
|
||||
// GET /maps
|
||||
func (svc *Service) ListMaps(ctx context.Context, params api.ListMapsParams) ([]api.Map, error) {
|
||||
filter := maps.MapFilter{}
|
||||
|
||||
if params.DisplayName.IsSet(){
|
||||
filter.DisplayName = ¶ms.DisplayName.Value
|
||||
}
|
||||
if params.Creator.IsSet(){
|
||||
filter.Creator = ¶ms.Creator.Value
|
||||
}
|
||||
if params.GameID.IsSet(){
|
||||
filter.GameID = ¶ms.GameID.Value
|
||||
}
|
||||
|
||||
mapList, err := svc.Client.List(ctx, &maps.ListRequest{
|
||||
Filter: &filter,
|
||||
Page: &maps.Pagination{
|
||||
Size: params.Limit,
|
||||
Number: params.Page,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []api.Map
|
||||
for _, item := range mapList.Maps {
|
||||
resp = append(resp, api.Map{
|
||||
ID: item.ID,
|
||||
DisplayName: item.DisplayName,
|
||||
Creator: item.Creator,
|
||||
GameID: item.GameID,
|
||||
Date: item.Date,
|
||||
})
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetMap implements getScript operation.
|
||||
//
|
||||
// Get the specified script by ID.
|
||||
//
|
||||
// GET /maps/{MapID}
|
||||
func (svc *Service) GetMap(ctx context.Context, params api.GetMapParams) (*api.Map, error) {
|
||||
mapResponse, err := svc.Client.Get(ctx, &maps.IdMessage{
|
||||
ID: params.MapID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &api.Map{
|
||||
ID: mapResponse.ID,
|
||||
DisplayName: mapResponse.DisplayName,
|
||||
Creator: mapResponse.Creator,
|
||||
GameID: mapResponse.GameID,
|
||||
Date: mapResponse.Date,
|
||||
}, nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user