File size: 2,636 Bytes
7c23748
 
 
 
 
 
 
 
 
 
46e3c85
7c23748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46e3c85
 
 
b105c1a
46e3c85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b105c1a
 
 
 
 
 
46e3c85
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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)
}