-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
251 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package admin | ||
|
||
import ( | ||
"github.com/gapidobri/prizer/internal/pkg/models/api" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
) | ||
|
||
func (s *Server) drawMethodRoutes() { | ||
group := s.engine.Group("/draw-methods") | ||
|
||
// swagger:route GET /draw-methods admin drawMethods getDrawMethods | ||
// | ||
// parameters: | ||
// + name: gameId | ||
// in: query | ||
// type: string | ||
// + name: participationMethodId | ||
// in: query | ||
// type: string | ||
// | ||
// responses: | ||
// 200: GetDrawMethodsResponse | ||
// 400: ErrorResponse | ||
// 403: ErrorResponse | ||
// 500: ErrorResponse | ||
// | ||
group.GET("", func(c *gin.Context) { | ||
var filter api.GetDrawMethodsFilter | ||
err := c.ShouldBindQuery(&filter) | ||
if err != nil { | ||
_ = c.Error(err) | ||
return | ||
} | ||
|
||
drawMethods, err := s.drawMethodService.GetDrawMethods(c.Request.Context(), filter) | ||
if err != nil { | ||
_ = c.Error(err) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, drawMethods) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package api | ||
|
||
import ( | ||
dbModels "github.com/gapidobri/prizer/internal/pkg/models/database" | ||
"github.com/gapidobri/prizer/internal/pkg/models/enums" | ||
) | ||
|
||
// swagger:model DrawMethod | ||
type DrawMethod struct { | ||
// required: true | ||
Id string `json:"draw_method_id"` | ||
|
||
// required: true | ||
GameId string `json:"game_id"` | ||
|
||
// required: true | ||
Name string `json:"name"` | ||
|
||
// required: true | ||
Method enums.DrawMethod `json:"method"` | ||
|
||
// required: true | ||
Data string `json:"data"` | ||
} | ||
|
||
func DrawMethodFromDB(drawMethod dbModels.DrawMethod) DrawMethod { | ||
return DrawMethod{ | ||
Id: drawMethod.Id, | ||
GameId: drawMethod.GameId, | ||
Name: drawMethod.Name, | ||
Method: drawMethod.Method, | ||
Data: drawMethod.Data, | ||
} | ||
} | ||
|
||
type GetDrawMethodsFilter struct { | ||
GameId *string `form:"gameId" binding:"omitnil,uuid"` | ||
ParticipationId *string `form:"participationId" binding:"omitnil,uuid"` | ||
} | ||
|
||
func (f GetDrawMethodsFilter) ToDB() dbModels.GetDrawMethodsFilter { | ||
return dbModels.GetDrawMethodsFilter{ | ||
GameId: f.GameId, | ||
ParticipationMethodId: f.ParticipationId, | ||
} | ||
} | ||
|
||
// swagger:model GetDrawMethodsResponse | ||
type GetDrawMethodsResponse []DrawMethod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package enums | ||
|
||
// swagger:enum DrawMethod | ||
type DrawMethod string | ||
|
||
const ( | ||
DrawMethodFirstN DrawMethod = "first_n" | ||
DrawMethodChance DrawMethod = "chance" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package service | ||
|
||
import ( | ||
"context" | ||
"github.com/gapidobri/prizer/internal/database" | ||
"github.com/gapidobri/prizer/internal/pkg/models/api" | ||
dbModels "github.com/gapidobri/prizer/internal/pkg/models/database" | ||
"github.com/samber/lo" | ||
) | ||
|
||
type DrawMethodService struct { | ||
drawMethodRepository database.DrawMethodRepository | ||
} | ||
|
||
func NewDrawMethodService(drawMethodRepository database.DrawMethodRepository) *DrawMethodService { | ||
return &DrawMethodService{ | ||
drawMethodRepository: drawMethodRepository, | ||
} | ||
} | ||
|
||
func (s *DrawMethodService) GetDrawMethods(ctx context.Context, filter api.GetDrawMethodsFilter) (api.GetDrawMethodsResponse, error) { | ||
drawMethods, err := s.drawMethodRepository.GetDrawMethods(ctx, filter.ToDB()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
apiDrawMethods := lo.Map(drawMethods, func(drawMethod dbModels.DrawMethod, _ int) api.DrawMethod { | ||
return api.DrawMethodFromDB(drawMethod) | ||
}) | ||
|
||
return apiDrawMethods, nil | ||
} |
Oops, something went wrong.