Spaces:
Configuration error
Configuration error
| package options_controller | |
| import ( | |
| "net/http" | |
| "api.qobiltu.id/models" | |
| "api.qobiltu.id/response" | |
| "api.qobiltu.id/services" | |
| "github.com/gin-gonic/gin" | |
| ) | |
| type OptionsController interface { | |
| CreateOptions(ctx *gin.Context) | |
| ListOptions(ctx *gin.Context) | |
| ListOptionsBySlug(ctx *gin.Context) | |
| } | |
| type optionsController struct { | |
| optionService services.OptionsService | |
| } | |
| func NewOptionsController(optionService services.OptionsService) OptionsController { | |
| return &optionsController{ | |
| optionService: optionService, | |
| } | |
| } | |
| func (c *optionsController) CreateOptions(ctx *gin.Context) { | |
| var req []models.MultipleOptionsRequest | |
| if err := ctx.ShouldBindJSON(&req); err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| res, err := c.optionService.CreateOptions(ctx, &models.CreateOptionsRequest{ | |
| Options: req, | |
| }) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Options created successfully", res, nil) | |
| } | |
| func (c *optionsController) ListOptions(ctx *gin.Context) { | |
| res, err := c.optionService.ListOptions(ctx) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Options retrieved successfully", res.Options, nil) | |
| } | |
| func (c *optionsController) ListOptionsBySlug(ctx *gin.Context) { | |
| slug := ctx.Param("slug") | |
| res, err := c.optionService.ListOptionsBySlug(ctx, &models.ListOptionsBySlugRequest{ | |
| Slug: slug, | |
| }) | |
| if err != nil { | |
| response.HandleError(ctx, err) | |
| return | |
| } | |
| response.HandleSuccess(ctx, http.StatusOK, "Options retrieved successfully", res, nil) | |
| } | |