feat: implement battle replay controller, service, and routes with Swagger documentation
Build and Release / release (push) Successful in 3m2s

This commit is contained in:
2026-05-28 02:46:48 +07:00
parent 1d0733819d
commit 54b1522db5
7 changed files with 198 additions and 0 deletions
+25
View File
@@ -2,6 +2,7 @@ package services
import (
"context"
"history-api/internal/dtos/request"
"history-api/internal/dtos/response"
"history-api/internal/models"
"history-api/internal/repositories"
@@ -13,6 +14,7 @@ import (
type BattleReplayService interface {
GetByID(ctx context.Context, id string) (*response.BattleReplayResponse, *fiber.Error)
GetByGeometryID(ctx context.Context, geometryID string) ([]*response.BattleReplayResponse, *fiber.Error)
GetByGeometryIDs(ctx context.Context, req *request.GetBattleReplaysByGeometryIDsDto) (map[string][]*response.BattleReplayResponse, *fiber.Error)
}
type battleReplayService struct {
@@ -52,3 +54,26 @@ func (s *battleReplayService) GetByGeometryID(ctx context.Context, geometryID st
return models.BattleReplaysEntityToResponse(replays), nil
}
func (s *battleReplayService) GetByGeometryIDs(ctx context.Context, req *request.GetBattleReplaysByGeometryIDsDto) (map[string][]*response.BattleReplayResponse, *fiber.Error) {
replays, err := s.battleReplayRepo.GetByGeometryIDs(ctx, req.GeometryIDs)
if err != nil {
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to get battle replays")
}
result := make(map[string][]*response.BattleReplayResponse)
for _, idStr := range req.GeometryIDs {
result[idStr] = make([]*response.BattleReplayResponse, 0)
}
for _, replay := range replays {
if replay != nil {
geomID := replay.GeometryID
if _, exists := result[geomID]; exists {
result[geomID] = append(result[geomID], replay.ToResponse())
}
}
}
return result, nil
}