quiz delete

This commit is contained in:
JongYeob Sheen 2024-01-15 23:08:05 +09:00
parent d9ecd65d75
commit b00eb7ac01
6 changed files with 113 additions and 1 deletions

View File

@ -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": {

View File

@ -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": {

View File

@ -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

View File

@ -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"})
}

View File

@ -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,
}

View File

@ -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)
}