diff --git a/docs/docs.go b/docs/docs.go index 5772fbc..83a28be 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -407,6 +407,34 @@ const docTemplate = `{ } } } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "퀴즈를 삭제합니다.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "퀴즈" + ], + "summary": "퀴즈 삭제", + "parameters": [ + { + "type": "integer", + "description": "Quiz ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": {} } }, "/quizpaper": { diff --git a/docs/swagger.json b/docs/swagger.json index 2c5fd43..2f862e8 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -399,6 +399,34 @@ } } } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "퀴즈를 삭제합니다.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "퀴즈" + ], + "summary": "퀴즈 삭제", + "parameters": [ + { + "type": "integer", + "description": "Quiz ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": {} } }, "/quizpaper": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 9d786fa..3873954 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -908,6 +908,24 @@ paths: tags: - 퀴즈 /quiz/{id}: + delete: + consumes: + - application/json + description: 퀴즈를 삭제합니다. + parameters: + - description: Quiz ID + in: path + name: id + required: true + type: integer + produces: + - application/json + responses: {} + security: + - Bearer: [] + summary: 퀴즈 삭제 + tags: + - 퀴즈 get: consumes: - application/json diff --git a/internal/controllers/quiz.go b/internal/controllers/quiz.go index 493e5dd..020d90f 100644 --- a/internal/controllers/quiz.go +++ b/internal/controllers/quiz.go @@ -20,6 +20,7 @@ type QuizController interface { Find(*gin.Context) Create(*gin.Context) Update(*gin.Context) + Delete(*gin.Context) } type quizController struct { @@ -241,3 +242,39 @@ func (controller *quizController) Update(c *gin.Context) { c.JSON(http.StatusOK, result) } + +// Delete Quiz +// +// @Summary 퀴즈 삭제 +// @Description 퀴즈를 삭제합니다. +// @Tags 퀴즈 +// +// @Accept json +// @Produce json +// +// @Security Bearer +// +// @Param id path int64 true "Quiz ID" +// +// @Router /quiz/{id} [delete] +func (controller *quizController) Delete(c *gin.Context) { + id, err := strconv.ParseInt(c.Param("id"), 10, 64) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + + _, err = controller.service.Find(id) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + + err = controller.service.Delete(id) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + return + } + + c.JSON(http.StatusOK, gin.H{"message": "success"}) +} diff --git a/internal/controllers/userquiz.go b/internal/controllers/userquiz.go index fe06e42..1057d66 100644 --- a/internal/controllers/userquiz.go +++ b/internal/controllers/userquiz.go @@ -26,7 +26,7 @@ type userQuizController struct { service services.UserQuizService } -func NewUserQuizController(service services.UserQuizService) QuizController { +func NewUserQuizController(service services.UserQuizService) UserQuizController { return &userQuizController{ service: service, } diff --git a/internal/routers/quiz.go b/internal/routers/quiz.go index a740b05..080b1b1 100644 --- a/internal/routers/quiz.go +++ b/internal/routers/quiz.go @@ -47,4 +47,5 @@ func (r *quizRouter) SetQuizRouter() { group.GET("/:id", middleware.Auth("admin"), r.controller.Find) group.POST("", middleware.Auth("admin"), r.controller.Create) group.PUT("/:id", middleware.Auth("admin"), r.controller.Update) + group.DELETE("/:id", middleware.Auth("admin"), r.controller.Delete) }