Skip to content
Snippets Groups Projects
Verified Commit 34055cf3 authored by Bayu Samudra's avatar Bayu Samudra
Browse files

fix: bugs when id not found

parent 4728c966
2 merge requests!35Staging,!32Feat/s4 sb56 backend list latihan
Pipeline #54479 passed with stage
in 2 minutes and 33 seconds
......@@ -43,11 +43,7 @@ func (m QuizHandlerImpl) GetQuizDetail(w http.ResponseWriter, r *http.Request) {
if ok {
payload := m.WrapperUtil.ErrorResponseWrap(respErr.Error(), respErr)
if respErr.Code != "NOT_OWNER" {
m.HttpUtil.WriteJson(w, http.StatusBadRequest, payload)
} else {
m.HttpUtil.WriteJson(w, http.StatusForbidden, payload)
}
m.HttpUtil.WriteJson(w, http.StatusBadRequest, payload)
} else {
payload := m.WrapperUtil.ErrorResponseWrap("internal server error", nil)
m.HttpUtil.WriteJson(w, http.StatusInternalServerError, payload)
......
package quiz
import (
"errors"
"time"
"github.com/google/uuid"
"gitlab.informatika.org/ocw/ocw-backend/model/domain/quiz"
"gitlab.informatika.org/ocw/ocw-backend/model/web"
"gitlab.informatika.org/ocw/ocw-backend/provider/db"
"gorm.io/gorm"
)
......@@ -22,13 +24,19 @@ func New(
func (q *QuizRepositoryImpl) GetQuizes(courseId string) ([]quiz.Quiz, error) {
result := &[]quiz.Quiz{}
err := q.db.Where("course_id = ?", courseId).Find(result).Error
return *result, err
}
func (q *QuizRepositoryImpl) GetQuizDetail(quizId uuid.UUID) (*quiz.Quiz, error) {
result := &quiz.Quiz{}
err := q.db.Where("id = ?", quizId).Find(result).Error
return result, err
err := q.db.Where("id = ?", quizId).First(result).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, web.NewResponseError("Record not found", "ERR_NOT_FOUND")
}
return result, nil
}
func (q *QuizRepositoryImpl) UpdateScore(takeId uuid.UUID, score int) error {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment