diff --git a/docs/docs.go b/docs/docs.go index b498e6d63e5a425ce81d82d31b1bb7c0acf04c4e..53551313022c11650b29700433fbe74ab2b3b930 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2729,9 +2729,7 @@ const docTemplate = `{ "description": "Information that should be available when you add a course", "type": "object", "required": [ - "abbreviation", "email", - "lecturer", "name" ], "properties": { @@ -2748,10 +2746,6 @@ const docTemplate = `{ "type": "string", "example": "someone@example.com" }, - "lecturer": { - "description": "Course Lecturer", - "type": "string" - }, "majabbr": { "description": "Course Major Abbreviation", "type": "string" diff --git a/docs/swagger.json b/docs/swagger.json index 35bc431aa7c6d69fd976b5ae111e4f89433befb6..1ac89a2a1a878a8494d4a79cea11328b62692ba1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2721,9 +2721,7 @@ "description": "Information that should be available when you add a course", "type": "object", "required": [ - "abbreviation", "email", - "lecturer", "name" ], "properties": { @@ -2740,10 +2738,6 @@ "type": "string", "example": "someone@example.com" }, - "lecturer": { - "description": "Course Lecturer", - "type": "string" - }, "majabbr": { "description": "Course Major Abbreviation", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 57767453f07d3bc013f4b6df5746e0e9e6afbb92..83c7b9731375d19f28d0a6f5912cb80018776e5a 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -102,9 +102,6 @@ definitions: description: Contributor Email example: someone@example.com type: string - lecturer: - description: Course Lecturer - type: string majabbr: description: Course Major Abbreviation type: string @@ -118,9 +115,7 @@ definitions: description: Web Token that was appended to the link type: string required: - - abbreviation - email - - lecturer - name type: object faculty.AddFacultyRequestPayload: diff --git a/model/web/course/request.go b/model/web/course/request.go index 6ff6079c34e6a58952f8b8f561ce0e2595b54ca8..f070a06a8dd18b23be95adb45bf6785f31c638cb 100644 --- a/model/web/course/request.go +++ b/model/web/course/request.go @@ -80,10 +80,7 @@ type UpdateCourseRequestPayload struct { Email string `json:"email" validate:"required,email" example:"someone@example.com"` // Course Name Abbreviation - Abbreviation string `json:"abbreviation" validate:"required"` - - // Course Lecturer - Lecturer string `json:"lecturer" validate:"required"` + Abbreviation string `json:"abbreviation"` } diff --git a/routes/quiz/route.go b/routes/quiz/route.go index e706bb19fd348df8e3a0e8d62146eb457f09165a..b4b1ce35251f1de2a60cd4e690350daa3d92c216 100644 --- a/routes/quiz/route.go +++ b/routes/quiz/route.go @@ -40,10 +40,14 @@ func (q QuizRoutes) Register(r chi.Router) { r.Get("/", q.QuizHandler.GetQuizDetail) r.Route("/", func(r chi.Router) { r.Use(guard) - r.Put("/", q.QuizHandler.NewQuiz) r.Delete("/", q.QuizHandler.DeleteQuiz) }) }) + + r.Route("/quiz", func(r chi.Router) { + r.Use(guard) + r.Put("/", q.QuizHandler.NewQuiz) + }) r.Route("/quiz/link/{id}", func(r chi.Router) { r.Use(guard) diff --git a/service/course/update.go b/service/course/update.go index 76df6c292d130c3595bbd85a1d0061c1a20ff553..0ab6dcd07eb711318a548659dde7b6fa42e1fd90 100644 --- a/service/course/update.go +++ b/service/course/update.go @@ -51,7 +51,6 @@ func (c CourseServiceImpl) UpdateCourse(payload course.UpdateCourseRequestPayloa Description: payload.Description, Email: payload.Email, Abbreviation: payload.Abbreviation, - Lecturer: payload.Lecturer, }) if err != nil { diff --git a/service/quiz/impl.go b/service/quiz/impl.go index 69c375425f121d4dfb2c740732cb89f7cce8b075..fb53a798c013f1fff684bb3eb6f6a999c9cc58b2 100644 --- a/service/quiz/impl.go +++ b/service/quiz/impl.go @@ -10,11 +10,9 @@ import ( "github.com/google/uuid" "gitlab.informatika.org/ocw/ocw-backend/model/domain/quiz" - "gitlab.informatika.org/ocw/ocw-backend/model/domain/user" userDomain "gitlab.informatika.org/ocw/ocw-backend/model/domain/user" "gitlab.informatika.org/ocw/ocw-backend/model/web" "gitlab.informatika.org/ocw/ocw-backend/model/web/auth/token" - atoken "gitlab.informatika.org/ocw/ocw-backend/model/web/auth/token" model "gitlab.informatika.org/ocw/ocw-backend/model/web/quiz" "gitlab.informatika.org/ocw/ocw-backend/provider/storage" quizRepo "gitlab.informatika.org/ocw/ocw-backend/repository/quiz" @@ -207,7 +205,7 @@ func (q QuizServiceImpl) isQuizContributor(courseId string, email string) error func (q QuizServiceImpl) NewQuiz(payload model.AddQuizRequestPayload) (*model.LinkResponse, error) { // Validate Role - claim, err := q.TokenUtil.Validate(payload.AddQuizToken, atoken.Access) + claim, err := q.TokenUtil.Validate(payload.AddQuizToken, token.Access) // Invalid Token if err != nil { @@ -215,7 +213,7 @@ func (q QuizServiceImpl) NewQuiz(payload model.AddQuizRequestPayload) (*model.Li } // Unauthorized Role - if claim.Role == user.Student { + if claim.Role == userDomain.Student { return &model.LinkResponse{}, web.NewResponseErrorFromError(err, web.UnauthorizedAccess) } @@ -233,12 +231,26 @@ func (q QuizServiceImpl) NewQuiz(payload model.AddQuizRequestPayload) (*model.Li return &model.LinkResponse{}, err } + q.QuizRepository.NewQuiz(quiz.Quiz{ + Id: uuid.New(), + Name: payload.Name, + CourseId: payload.CourseID, + CreatorEmail: claim.Email, + QuizPath: uploadLink, + }) + + if err != nil { + q.Logger.Error("Some error happened when insert to repository") + q.Logger.Error(err.Error()) + return &model.LinkResponse{}, err + } + return &model.LinkResponse{UploadLink: uploadLink}, nil } func (q QuizServiceImpl) GetQuiz(payload model.UpdateQuizRequestPayload) (*model.LinkResponse, error) { // Validate Role - claim, err := q.TokenUtil.Validate(payload.UpdateQuizToken, atoken.Access) + claim, err := q.TokenUtil.Validate(payload.UpdateQuizToken, token.Access) // Invalid Token if err != nil { @@ -246,7 +258,7 @@ func (q QuizServiceImpl) GetQuiz(payload model.UpdateQuizRequestPayload) (*model } // Unauthorized Role - if claim.Role == user.Student { + if claim.Role == userDomain.Student { return &model.LinkResponse{}, web.NewResponseErrorFromError(err, web.UnauthorizedAccess) } @@ -275,7 +287,7 @@ func (q QuizServiceImpl) GetQuiz(payload model.UpdateQuizRequestPayload) (*model func (q QuizServiceImpl) DeleteQuiz(payload model.DeleteRequestPayload) error { // Validate Role - claim, err := q.TokenUtil.Validate(payload.DeleteToken, atoken.Access) + claim, err := q.TokenUtil.Validate(payload.DeleteToken, token.Access) // Invalid Token if err != nil { @@ -283,7 +295,7 @@ func (q QuizServiceImpl) DeleteQuiz(payload model.DeleteRequestPayload) error { } // Unauthorized Role - if claim.Role == user.Student { + if claim.Role == userDomain.Student { return web.NewResponseErrorFromError(err, web.UnauthorizedAccess) }