From e9f79241f10c4ab9f8da1273ff182c3bac8a9481 Mon Sep 17 00:00:00 2001 From: Quaternions <krakow20@gmail.com> Date: Tue, 1 Apr 2025 16:48:49 -0700 Subject: [PATCH] submissions: maps endpoints --- pkg/service/maps.go | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 pkg/service/maps.go diff --git a/pkg/service/maps.go b/pkg/service/maps.go new file mode 100644 index 0000000..f789da6 --- /dev/null +++ b/pkg/service/maps.go @@ -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 +}