quiz가 없을 경우, userquizpaper 생성 중단
This commit is contained in:
parent
6bb8dd3ada
commit
a402f046aa
@ -1,7 +1,6 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -23,19 +22,22 @@ type UserQuizPaperController interface {
|
|||||||
type userQuizPaperController struct {
|
type userQuizPaperController struct {
|
||||||
service services.UserQuizPaperService
|
service services.UserQuizPaperService
|
||||||
userService services.UserService
|
userService services.UserService
|
||||||
|
quizService services.QuizService
|
||||||
quizPaperService services.QuizPaperService
|
quizPaperService services.QuizPaperService
|
||||||
userQuizService services.UserQuizService
|
userQuizService services.UserQuizService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUserQuizPaperController(
|
func NewUserQuizPaperController(
|
||||||
service services.UserQuizPaperService,
|
service services.UserQuizPaperService,
|
||||||
userService services.UserService,
|
quizService services.QuizService,
|
||||||
quizPaperService services.QuizPaperService,
|
quizPaperService services.QuizPaperService,
|
||||||
userQuizService services.UserQuizService,
|
userQuizService services.UserQuizService,
|
||||||
|
userService services.UserService,
|
||||||
) UserQuizPaperController {
|
) UserQuizPaperController {
|
||||||
return &userQuizPaperController{
|
return &userQuizPaperController{
|
||||||
service: service,
|
service: service,
|
||||||
userService: userService,
|
userService: userService,
|
||||||
|
quizService: quizService,
|
||||||
quizPaperService: quizPaperService,
|
quizPaperService: quizPaperService,
|
||||||
userQuizService: userQuizService,
|
userQuizService: userQuizService,
|
||||||
}
|
}
|
||||||
@ -62,13 +64,11 @@ func (controller *userQuizPaperController) List(c *gin.Context) {
|
|||||||
q := c.DefaultQuery("q", "")
|
q := c.DefaultQuery("q", "")
|
||||||
page, err := strconv.Atoi(c.DefaultQuery("page", "1"))
|
page, err := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error : page")
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
limit, err := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
limit, err := strconv.Atoi(c.DefaultQuery("limit", "10"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error : limit")
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -81,7 +81,6 @@ func (controller *userQuizPaperController) List(c *gin.Context) {
|
|||||||
|
|
||||||
totalNumber, err := controller.service.Total(q)
|
totalNumber, err := controller.service.Total(q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error : list")
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -151,20 +150,17 @@ func (controller *userQuizPaperController) Create(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("users", request.Users)
|
|
||||||
|
|
||||||
quizPaper, err := controller.quizPaperService.Find(request.QuizPaperID)
|
quizPaper, err := controller.quizPaperService.Find(request.QuizPaperID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// var users []int64
|
quizzes, err := controller.quizService.List(request.QuizPaperID, 1, 1000)
|
||||||
// err = json.Unmarshal(request.Users, &users)
|
if len(*quizzes) == 0 || err != nil {
|
||||||
// if err != nil {
|
c.JSON(http.StatusBadRequest, gin.H{"error": "No quiz"})
|
||||||
// c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
return
|
||||||
// return
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
templates := controller.service.Generate(request.Users, quizPaper)
|
templates := controller.service.Generate(request.Users, quizPaper)
|
||||||
userQuizPapers, err := controller.service.Insert(templates)
|
userQuizPapers, err := controller.service.Insert(templates)
|
||||||
@ -219,7 +215,6 @@ func (controller *userQuizPaperController) Update(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("request", request)
|
|
||||||
userQuizPaper, err := controller.service.Get(id)
|
userQuizPaper, err := controller.service.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
@ -233,30 +228,25 @@ func (controller *userQuizPaperController) Update(c *gin.Context) {
|
|||||||
userQuizPaper.TotalScore = request.TotalScore
|
userQuizPaper.TotalScore = request.TotalScore
|
||||||
|
|
||||||
if request.StartAt != "" {
|
if request.StartAt != "" {
|
||||||
fmt.Println("request.StartAt", request.StartAt)
|
|
||||||
start_at, err := time.Parse("2006-01-02T15:04:05-07:00", request.StartAt)
|
start_at, err := time.Parse("2006-01-02T15:04:05-07:00", request.StartAt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userQuizPaper.StartAt = &start_at
|
userQuizPaper.StartAt = &start_at
|
||||||
}
|
}
|
||||||
fmt.Println("start_at", start_at)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.DoneAt != "" {
|
if request.DoneAt != "" {
|
||||||
fmt.Println("request.EndAt", request.DoneAt)
|
|
||||||
done_at, err := time.Parse("2006-01-02T15:04:05-07:00", request.DoneAt)
|
done_at, err := time.Parse("2006-01-02T15:04:05-07:00", request.DoneAt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userQuizPaper.DoneAt = &done_at
|
userQuizPaper.DoneAt = &done_at
|
||||||
}
|
}
|
||||||
fmt.Println("done_at", done_at)
|
|
||||||
}
|
}
|
||||||
fmt.Println("userQuizPaper", userQuizPaper)
|
|
||||||
result, err := controller.service.Update(userQuizPaper)
|
result, err := controller.service.Update(userQuizPaper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("result", result)
|
|
||||||
c.JSON(http.StatusOK, result)
|
c.JSON(http.StatusOK, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +279,6 @@ func (controller *userQuizPaperController) Patch(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("request", request)
|
|
||||||
userQuizPaper, err := controller.service.Get(id)
|
userQuizPaper, err := controller.service.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
@ -301,21 +290,17 @@ func (controller *userQuizPaperController) Patch(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if request.StartAt != "" {
|
if request.StartAt != "" {
|
||||||
fmt.Println("request.StartAt", request.StartAt)
|
|
||||||
start_at, err := time.Parse("2006-01-02T15:04:05-07:00", request.StartAt)
|
start_at, err := time.Parse("2006-01-02T15:04:05-07:00", request.StartAt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userQuizPaper.StartAt = &start_at
|
userQuizPaper.StartAt = &start_at
|
||||||
}
|
}
|
||||||
fmt.Println("start_at", start_at)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.DoneAt != "" {
|
if request.DoneAt != "" {
|
||||||
fmt.Println("request.EndAt", request.DoneAt)
|
|
||||||
done_at, err := time.Parse("2006-01-02T15:04:05-07:00", request.DoneAt)
|
done_at, err := time.Parse("2006-01-02T15:04:05-07:00", request.DoneAt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
userQuizPaper.DoneAt = &done_at
|
userQuizPaper.DoneAt = &done_at
|
||||||
}
|
}
|
||||||
fmt.Println("done_at", done_at)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := controller.service.Update(userQuizPaper)
|
result, err := controller.service.Update(userQuizPaper)
|
||||||
@ -324,6 +309,5 @@ func (controller *userQuizPaperController) Patch(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("result", result)
|
|
||||||
c.JSON(http.StatusOK, result)
|
c.JSON(http.StatusOK, result)
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ type UserQuizPaperRouter interface {
|
|||||||
type userQuizPaperRouter struct {
|
type userQuizPaperRouter struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
repository repositories.UserQuizPaperRepository
|
repository repositories.UserQuizPaperRepository
|
||||||
|
quizRepository repositories.QuizRepository
|
||||||
service services.UserQuizPaperService
|
service services.UserQuizPaperService
|
||||||
controller controllers.UserQuizPaperController
|
controller controllers.UserQuizPaperController
|
||||||
// quizPaperRepository repositories.QuizPaperRepository
|
// quizPaperRepository repositories.QuizPaperRepository
|
||||||
@ -42,15 +43,17 @@ func NewUserQuizPaperRouter(db *gorm.DB, router *gin.Engine) *userQuizPaperRoute
|
|||||||
userQuizRepository := repositories.NewUserQuizRepository(db)
|
userQuizRepository := repositories.NewUserQuizRepository(db)
|
||||||
|
|
||||||
service := services.NewUserQuizPaperService(repository)
|
service := services.NewUserQuizPaperService(repository)
|
||||||
|
quizService := services.NewQuizService(quizRepository)
|
||||||
quizPaperService := services.NewQuizPaperService(quizPaperRepository)
|
quizPaperService := services.NewQuizPaperService(quizPaperRepository)
|
||||||
userService := services.NewUserService(userRepository, tokenRepository)
|
userService := services.NewUserService(userRepository, tokenRepository)
|
||||||
userQuizService := services.NewUserQuizService(userQuizRepository, quizRepository)
|
userQuizService := services.NewUserQuizService(userQuizRepository, quizRepository)
|
||||||
|
|
||||||
controller := controllers.NewUserQuizPaperController(service, userService, quizPaperService, userQuizService)
|
controller := controllers.NewUserQuizPaperController(service, quizService, quizPaperService, userQuizService, userService)
|
||||||
|
|
||||||
return &userQuizPaperRouter{
|
return &userQuizPaperRouter{
|
||||||
db: db,
|
db: db,
|
||||||
repository: repository,
|
repository: repository,
|
||||||
|
quizRepository: quizRepository,
|
||||||
service: service,
|
service: service,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
router: router,
|
router: router,
|
||||||
|
Loading…
Reference in New Issue
Block a user