quzuu-api-test / controllers /repair_controller.go
lifedebugger's picture
Deploy files from GitHub repository
b105c1a
package controllers
import (
"abdanhafidz.com/go-boilerplate/models/dto"
"abdanhafidz.com/go-boilerplate/services"
"github.com/gin-gonic/gin"
)
type RepairController interface {
RepairQuestionStoragePath(ctx *gin.Context)
RepairProblemSetNamingMigrate(ctx *gin.Context)
}
type repairController struct {
repairService services.RepairService
}
func NewRepairController(repairService services.RepairService) RepairController {
return &repairController{repairService: repairService}
}
// RepairQuestionStoragePath godoc
// @Summary Super Admin: Repair Question Storage Path
// @Description Replace @@PLUGINFILE@@ placeholders in questions with the storage URL and problem set ID
// @Tags Super Admin Repair
// @Accept json
// @Produce json
// @Security BearerAuth
// @Success 200 {object} dto.SuccessResponse[dto.RepairQuestionStoragePathResponse]
// @Failure 401 {object} dto.ErrorResponse
// @Failure 403 {object} dto.ErrorResponse
// @Failure 500 {object} dto.ErrorResponse
// @Router /api/v1/super-admin/repair/question/storage_path [post]
func (c *repairController) RepairQuestionStoragePath(ctx *gin.Context) {
updatedRows, err := c.repairService.RepairQuestionStoragePath(ctx.Request.Context())
ResponseJSON(ctx, gin.H{}, dto.RepairQuestionStoragePathResponse{UpdatedRows: updatedRows}, err)
}
// RepairProblemSetNamingMigrate godoc
// @Summary Super Admin: Repair Problem Set Naming Migrate
// @Description Prefix problem set titles with a custom prefix by created_at range (defaults to [MIGRATED])
// @Tags Super Admin Repair
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param request body dto.RepairProblemSetNamingMigrateRequest true "Repair Problem Set Naming Migrate Request"
// @Success 200 {object} dto.SuccessResponse[dto.RepairProblemSetNamingMigrateResponse]
// @Failure 400 {object} dto.ErrorResponse
// @Failure 401 {object} dto.ErrorResponse
// @Failure 403 {object} dto.ErrorResponse
// @Failure 500 {object} dto.ErrorResponse
// @Router /api/v1/super-admin/repair/problemset/naming/migrate [post]
func (c *repairController) RepairProblemSetNamingMigrate(ctx *gin.Context) {
req := RequestJSON[dto.RepairProblemSetNamingMigrateRequest](ctx)
if ctx.IsAborted() {
return
}
updatedRows, err := c.repairService.RepairProblemSetNamingMigrate(
ctx.Request.Context(),
req.StartDate,
req.EndDate,
req.Prefix,
)
ResponseJSON(ctx, req, dto.RepairProblemSetNamingMigrateResponse{UpdatedRows: updatedRows}, err)
}