Spaces:
Runtime error
Runtime error
Commit ·
d0e1b44
1
Parent(s): 1b4f42f
Deploy files from GitHub repository
Browse filesFiles changed (10)
- .env.example+2-3
- Quzuu_API_Collection.postman_collection.json+81-3
- Quzuu_Dev_Environment.postman_environment.json+6
- controllers/event_exam_controller.go+97-64
- models/dto/event_dto.go+19-13
- models/entity/entity.go+7
- repositories/event_exam_attempt_repository.go+103-2
- router/event_exam_proctoring_router.go+1-1
- router/event_exam_router.go+1
- services/event_exam_service.go+24-2
11 unmodified lines1213141516171819202111 unmodified linesXENDIT_CALLBACK_TOKEN =MAILGUN_API_KEY =MAILGUN_DOMAIN =MAILGUN_SENDER =MAILGUN_API_BASE_URL = https://api.mailgun.netSMTP_HOST = smtp.mailgun.orgSMTP_PORT = 587SMTP_USERNAME =SMTP_PASSWORD =SMTP_SENDER =11 unmodified lines12131415161718192011 unmodified linesXENDIT_CALLBACK_TOKEN =MAILGUN_API_KEY =MAILGUN_DOMAIN =MAILGUN_API_BASE_URL = https://api.mailgun.netSMTP_HOST =SMTP_PORT =SMTP_USERNAME =SMTP_PASSWORD =SMTP_SENDER =
628 unmodified lines6296306316326336346 unmodified lines64164264364464564664716 unmodified lines664665666667668669670671672673674675676677678628 unmodified lines},"response": []},{"name": "Exam Scoreboard","request": {6 unmodified lines}],"url": {"raw": "{{base_url}}/api/v1/events/:event_slug/:exam_slug/scoreboard?limit=10&page=1&sortBy=score&order=desc","host": ["{{base_url}}"],16 unmodified lines"value": "1","description": "Page number"},{"key": "sortBy","value": "score","description": "Sort field: 'score' (default) or 'duration'"},{"key": "order","value": "desc","description": "Sort order: 'asc' or 'desc'"}],"variable": [628 unmodified lines6296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007016 unmodified lines70870971071171271371416 unmodified lines731732733734735736737738739740741742743744745746747748749750751752753754755756628 unmodified lines},"response": []},{"name": "Event Scoreboard","request": {"method": "GET","header": [{"key": "Authorization","value": "Bearer {{access_token}}","type": "text"}],"url": {"raw": "{{base_url}}/api/v1/events/:event_slug/scoreboard?limit=10&page=1&search=&sortBy=total_score&orderBy=desc","host": ["{{base_url}}"],"path": ["api","v1","events",":event_slug","scoreboard"],"query": [{"key": "limit","value": "10","description": "Number of items per page (max 100)"},{"key": "page","value": "1","description": "Page number"},{"key": "search","value": "","description": "Search keyword"},{"key": "sortBy","value": "total_score","description": "Sort field: 'total_score' (default), 'score', 'username', or 'full_name'"},{"key": "orderBy","value": "desc","description": "Sort order: 'asc' or 'desc'"},{"key": "order","value": "desc","disabled": true,"description": "Alias for sort order (backward compatibility)"}],"variable": [{"key": "event_slug","value": ""}]},"description": "Retrieve a paginated scoreboard of participants ranked by total score across all exams in an event"},"response": []},{"name": "Exam Scoreboard","request": {6 unmodified lines}],"url": {"raw": "{{base_url}}/api/v1/events/:event_slug/:exam_slug/scoreboard?limit=10&page=1&search=&sortBy=score&orderBy=desc","host": ["{{base_url}}"],16 unmodified lines"value": "1","description": "Page number"},{"key": "search","value": "","description": "Search keyword"},{"key": "sortBy","value": "score","description": "Sort field: 'score' (default), 'duration', 'username', or 'full_name'"},{"key": "orderBy","value": "desc","description": "Sort order: 'asc' or 'desc'"},{"key": "order","value": "desc","disabled": true,"description": "Alias for sort order (backward compatibility)"}],"variable": [
78 unmodified lines79808182838478 unmodified lines"enabled": true,"type": "default"},{"key": "log_id","value": "",78 unmodified lines79808182838485868788899078 unmodified lines"enabled": true,"type": "default"},{"key": "orderBy","value": "","enabled": true,"type": "default"},{"key": "log_id","value": "",
1234567891011121314151 unmodified line17181920212237 unmodified lines60616263646566676869707172737475767 unmodified lines84858687888990919293949596979812 unmodified lines1111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401415 unmodified lines147148149150151152153154155156157158159160161162163164165166167168169170171172173174175package controllersimport ("strconv""abdanhafidz.com/go-boilerplate/models/dto"entity "abdanhafidz.com/go-boilerplate/models/entity"http_error "abdanhafidz.com/go-boilerplate/models/error""abdanhafidz.com/go-boilerplate/services""github.com/gin-gonic/gin""github.com/google/uuid")type EventExamController interface {Attempt(ctx *gin.Context)1 unmodified lineSubmit(ctx *gin.Context)List(ctx *gin.Context)Scoreboard(ctx *gin.Context)}type eventExamController struct {37 unmodified lines// @Success 200 {object} dto.SuccessResponse[dto.AnswerEventExamRequest]// @Failure 400 {object} dto.ErrorResponse// @Router /api/v1/events/{event_slug}/exam/{attempt_id}/answer_question [post]func (c *eventExamController) Answer(ctx *gin.Context) {eventSlug := ctx.Param("event_slug")attemptId, err := uuid.Parse(ctx.Param("attempt_id"))if err != nil {ResponseJSON[any](ctx, gin.H{"attempt_id": ctx.Param("attempt_id")}, nil, http_error.INVALID_TOKEN)return}req := RequestJSON[dto.AnswerEventExamRequest](ctx)res, err := c.eventExamService.AnswerEventExam(ctx.Request.Context(), eventSlug, attemptId, req.QuestionId, req.Answer)ResponseJSON(ctx, gin.H{"cp_grader_result": res}, req, err)}// Submit Exam Event godoc// @Summary Submit Exam Event7 unmodified lines// @Failure 400 {object} dto.ErrorResponse// @Router /api/v1/events/{event_slug}/exam/{attempt_id}/submit [post]func (c *eventExamController) Submit(ctx *gin.Context) {attemptId, err := uuid.Parse(ctx.Param("attempt_id"))if err != nil {ResponseJSON[any](ctx, gin.H{"attempt_id": ctx.Param("attempt_id")}, nil, http_error.INVALID_TOKEN)return}res, err := c.eventExamService.SubmitEventExam(ctx.Request.Context(), attemptId)ResponseJSON(ctx, gin.H{}, res, err)}// List Exam by Event godoc// @Summary List Exams by Event12 unmodified linesResponseJSON(ctx, gin.H{}, res, err)}// Scoreboard godoc// @Summary Exam Scoreboard// @Description Retrieve a paginated scoreboard of participants ranked by their performance in a specific exam within an event// @Tags Exam Event// @Accept json// @Produce json// @Param event_slug path string true "Event Slug"// @Param exam_slug path string true "Exam Slug"// @Param limit query int false "Number of items per page" default(10)// @Param page query int false "Page number" default(1)// @Param sortBy query string false "Sort field: 'score' (default) or 'duration'"// @Param order query string false "Sort order: 'asc' or 'desc'"// @Success 200 {object} dto.SuccessResponse[[]dto.ExamScoreboardItem]// @Failure 400 {object} dto.ErrorResponse// @Security BearerAuth// @Router /api/v1/events/{event_slug}/{exam_slug}/scoreboard [get]func (c *eventExamController) Scoreboard(ctx *gin.Context) {eventSlug := ctx.Param("event_slug")examSlug := ctx.Param("exam_slug")accountId := ParseAccountId(ctx)limit, _ := strconv.Atoi(ctx.DefaultQuery("limit", "10"))page, _ := strconv.Atoi(ctx.DefaultQuery("page", "1"))sortBy := ctx.DefaultQuery("sortBy", "score")order := ctx.DefaultQuery("order", "desc")if limit < 1 {limit = 105 unmodified lines}offset := (page - 1) * limitp := entity.Pagination{Limit: limit, Offset: offset, SortBy: sortBy, Order: order}list, total, err := c.eventExamService.Scoreboard(ctx.Request.Context(), eventSlug, examSlug, accountId, p)var totalPages intif total == 0 {totalPages = 1} else {totalPages = int((total + int64(limit) - 1) / int64(limit))}if page > totalPages {page = totalPagesoffset = (page - 1) * limitp.Offset = offsetlist, total, err = c.eventExamService.Scoreboard(ctx.Request.Context(), eventSlug, examSlug, accountId, p)}meta := gin.H{"totalItems": total,"totalPages": totalPages,"currentPage": page,}ResponseJSON(ctx, meta, list, err)}1234567891011121314151 unmodified line1718192021222337 unmodified lines61626364656667686970717273747576777 unmodified lines85868788899091929394959697989912 unmodified lines1121131141151161171181191201211221231241251265 unmodified lines132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208package controllersimport ("strconv""abdanhafidz.com/go-boilerplate/models/dto"entity "abdanhafidz.com/go-boilerplate/models/entity"http_error "abdanhafidz.com/go-boilerplate/models/error""abdanhafidz.com/go-boilerplate/services""github.com/gin-gonic/gin""github.com/google/uuid")type EventExamController interface {Attempt(ctx *gin.Context)1 unmodified lineSubmit(ctx *gin.Context)List(ctx *gin.Context)Scoreboard(ctx *gin.Context)EventScoreboard(ctx *gin.Context)}type eventExamController struct {37 unmodified lines// @Success 200 {object} dto.SuccessResponse[dto.AnswerEventExamRequest]// @Failure 400 {object} dto.ErrorResponse// @Router /api/v1/events/{event_slug}/exam/{attempt_id}/answer_question [post]func (c *eventExamController) Answer(ctx *gin.Context) {eventSlug := ctx.Param("event_slug")attemptId, err := uuid.Parse(ctx.Param("attempt_id"))if err != nil {ResponseJSON[any](ctx, gin.H{"attempt_id": ctx.Param("attempt_id")}, nil, http_error.INVALID_TOKEN)return}req := RequestJSON[dto.AnswerEventExamRequest](ctx)res, err := c.eventExamService.AnswerEventExam(ctx.Request.Context(), eventSlug, attemptId, req.QuestionId, req.Answer)ResponseJSON(ctx, gin.H{"cp_grader_result": res}, req, err)}// Submit Exam Event godoc// @Summary Submit Exam Event7 unmodified lines// @Failure 400 {object} dto.ErrorResponse// @Router /api/v1/events/{event_slug}/exam/{attempt_id}/submit [post]func (c *eventExamController) Submit(ctx *gin.Context) {attemptId, err := uuid.Parse(ctx.Param("attempt_id"))if err != nil {ResponseJSON[any](ctx, gin.H{"attempt_id": ctx.Param("attempt_id")}, nil, http_error.INVALID_TOKEN)return}res, err := c.eventExamService.SubmitEventExam(ctx.Request.Context(), attemptId)ResponseJSON(ctx, gin.H{}, res, err)}// List Exam by Event godoc// @Summary List Exams by Event12 unmodified linesResponseJSON(ctx, gin.H{}, res, err)}func parseScoreboardPagination(ctx *gin.Context, defaultSort string, defaultOrder string) (int, int, entity.Pagination) {limit, _ := strconv.Atoi(ctx.DefaultQuery("limit", "10"))page, _ := strconv.Atoi(ctx.DefaultQuery("page", "1"))search := ctx.DefaultQuery("search", "")sortBy := ctx.DefaultQuery("sortBy", defaultSort)order := ctx.DefaultQuery("orderBy", "")if order == "" {order = ctx.DefaultQuery("order", defaultOrder)}if limit < 1 {limit = 105 unmodified lines}offset := (page - 1) * limitreturn limit, page, entity.Pagination{Limit: limit, Offset: offset, Search: search, SortBy: sortBy, Order: order}}func buildPaginationMeta(limit int, page int, total int64) gin.H {totalPages := 1if total > 0 {totalPages = int((total + int64(limit) - 1) / int64(limit))}if page > totalPages {page = totalPages}return gin.H{"totalItems": total,"totalPages": totalPages,"currentPage": page,"limit": limit,}}// Scoreboard godoc// @Summary Exam Scoreboard// @Description Retrieve a paginated scoreboard of participants ranked by their performance in a specific exam within an event// @Tags Exam Event// @Accept json// @Produce json// @Param event_slug path string true "Event Slug"// @Param exam_slug path string true "Exam Slug"// @Param limit query int false "Number of items per page" default(10)// @Param page query int false "Page number" default(1)// @Param search query string false "Search keyword"// @Param sortBy query string false "Sort field: 'score' (default) or 'duration'"// @Param orderBy query string false "Sort order: 'asc' or 'desc'"// @Param order query string false "Sort order alias: 'asc' or 'desc'"// @Success 200 {object} dto.SuccessResponse[[]dto.ExamScoreboardItem]// @Failure 400 {object} dto.ErrorResponse// @Security BearerAuth// @Router /api/v1/events/{event_slug}/{exam_slug}/scoreboard [get]func (c *eventExamController) Scoreboard(ctx *gin.Context) {eventSlug := ctx.Param("event_slug")examSlug := ctx.Param("exam_slug")accountId := ParseAccountId(ctx)limit, page, p := parseScoreboardPagination(ctx, "score", "desc")list, total, err := c.eventExamService.Scoreboard(ctx.Request.Context(), eventSlug, examSlug, accountId, p)meta := buildPaginationMeta(limit, page, total)ResponseJSON(ctx, meta, list, err)}// Event Scoreboard godoc// @Summary Event Scoreboard// @Description Retrieve a paginated scoreboard of participants based on total score across all exams in an event// @Tags Exam Event// @Accept json// @Produce json// @Param event_slug path string true "Event Slug"// @Param limit query int false "Number of items per page" default(10)// @Param page query int false "Page number" default(1)// @Param search query string false "Search keyword"// @Param sortBy query string false "Sort field: 'total_score' (default), 'username', or 'full_name'"// @Param orderBy query string false "Sort order: 'asc' or 'desc'"// @Param order query string false "Sort order alias: 'asc' or 'desc'"// @Success 200 {object} dto.SuccessResponse[[]dto.EventScoreboardItem]// @Failure 400 {object} dto.ErrorResponse// @Security BearerAuth// @Router /api/v1/events/{event_slug}/scoreboard [get]func (c *eventExamController) EventScoreboard(ctx *gin.Context) {eventSlug := ctx.Param("event_slug")accountId := ParseAccountId(ctx)limit, page, p := parseScoreboardPagination(ctx, "total_score", "desc")list, total, err := c.eventExamService.EventScoreboard(ctx.Request.Context(), eventSlug, accountId, p)meta := buildPaginationMeta(limit, page, total)ResponseJSON(ctx, meta, list, err)}
20 unmodified lines212223242526272829303132333435363738394041424315 unmodified lines59606162636420 unmodified lines}type CreateEventRequest struct {Title string `json:"title" binding:"required"`StartEvent string `json:"start_event" binding:"required"`EndEvent string `json:"end_event" binding:"required"`Overview string `json:"overview" binding:"required"`ImgBanner string `json:"img_banner" binding:"required"`EventCode string `json:"event_code"`IsPublic bool `json:"is_public"`Price float64 `json:"price"`}type UpdateEventRequest struct {Title string `json:"title"`StartEvent string `json:"start_event"`EndEvent string `json:"end_event"`Overview string `json:"overview"`ImgBanner string `json:"img_banner"`IsPublic *bool `json:"is_public"`Price *float64 `json:"price"`}15 unmodified linesDuration string `json:"duration"`}type AdminEventResponse struct {entity.EventsParticipantCount int64 `json:"participant_count"`20 unmodified lines212223242526272829303132333435363738394041424315 unmodified lines59606162636465666768697020 unmodified lines}type CreateEventRequest struct {Title string `json:"title" binding:"required"`StartEvent string `json:"start_event" binding:"required"`EndEvent string `json:"end_event" binding:"required"`Overview string `json:"overview" binding:"required"`ImgBanner string `json:"img_banner" binding:"required"`EventCode string `json:"event_code"`IsPublic bool `json:"is_public"`Price float64 `json:"price"`}type UpdateEventRequest struct {Title string `json:"title"`StartEvent string `json:"start_event"`EndEvent string `json:"end_event"`Overview string `json:"overview"`ImgBanner string `json:"img_banner"`IsPublic *bool `json:"is_public"`Price *float64 `json:"price"`}15 unmodified linesDuration string `json:"duration"`}type EventScoreboardItem struct {Username string `json:"username"`FullName string `json:"full_name,omitempty"`TotalScore float32 `json:"total_score"`}type AdminEventResponse struct {entity.EventsParticipantCount int64 `json:"participant_count"`
286 unmodified lines287288289290291292286 unmodified linesDurationSeconds int64}type EventExamAttempt struct {Id uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id_attempt"`AccountId uuid.UUID `json:"id_account,omitempty"`286 unmodified lines287288289290291292293294295296297298299286 unmodified linesDurationSeconds int64}type EventScoreboardEntry struct {AccountId uuid.UUIDUsername stringFullName stringTotalScore float32}type EventExamAttempt struct {Id uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id_attempt"`AccountId uuid.UUID `json:"id_account,omitempty"`
1 unmodified line2345676 unmodified lines14151617181956 unmodified lines7677787980812 unmodified lines84858687888910 unmodified lines10010110210310410510610710810911011111216 unmodified lines1291301311 unmodified lineimport ("context"entity "abdanhafidz.com/go-boilerplate/models/entity""github.com/google/uuid"6 unmodified linesGetByEventExam(ctx context.Context, eventId uuid.UUID, examId uuid.UUID, accountId uuid.UUID) (entity.EventExamAttempt, error)Update(ctx context.Context, a *entity.EventExamAttempt) errorGetScoreboard(ctx context.Context, eventId uuid.UUID, examId uuid.UUID, p entity.Pagination) ([]entity.ExamScoreboardEntry, int64, error)}type eventExamAttemptRepository struct{ db *gorm.DB }56 unmodified linescase "duration":col = "duration_seconds"ord = "ASC"}if p.Order == "asc" {2 unmodified linesord = "DESC"}rawSQL := `SELECTa.id AS account_id,10 unmodified linesJOIN exam_event_attempt eea ON eea.id = r.attempt_idJOIN account a ON a.id = eea.account_idLEFT JOIN account_details ad ON ad.account_id = a.idWHERE eea.event_id = ? AND eea.exam_id = ?ORDER BY ` + col + ` ` + ord + `LIMIT ? OFFSET ?`var rows []rawRowif err := r.db.WithContext(ctx).Raw(rawSQL, eventId, examId, p.Limit, p.Offset).Scan(&rows).Error; err != nil {return nil, 0, err}16 unmodified linesreturn entries, total, nil}1 unmodified line23456786 unmodified lines1516171819202156 unmodified lines7879808182838485868788892 unmodified lines929394959697989910010110210310410510610710 unmodified lines11811912012112212312412512612712812913013116 unmodified lines1481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312321 unmodified lineimport ("context""strings"entity "abdanhafidz.com/go-boilerplate/models/entity""github.com/google/uuid"6 unmodified linesGetByEventExam(ctx context.Context, eventId uuid.UUID, examId uuid.UUID, accountId uuid.UUID) (entity.EventExamAttempt, error)Update(ctx context.Context, a *entity.EventExamAttempt) errorGetScoreboard(ctx context.Context, eventId uuid.UUID, examId uuid.UUID, p entity.Pagination) ([]entity.ExamScoreboardEntry, int64, error)GetEventScoreboard(ctx context.Context, eventId uuid.UUID, p entity.Pagination) ([]entity.EventScoreboardEntry, int64, error)}type eventExamAttemptRepository struct{ db *gorm.DB }56 unmodified linescase "duration":col = "duration_seconds"ord = "ASC"case "username":col = "a.username"ord = "ASC"case "full_name":col = "COALESCE(ad.full_name, '')"ord = "ASC"}if p.Order == "asc" {2 unmodified linesord = "DESC"}whereSQL := "WHERE eea.event_id = ? AND eea.exam_id = ?"args := []any{eventId, examId}search := strings.TrimSpace(p.Search)if search != "" {like := "%" + search + "%"whereSQL += " AND (a.username ILIKE ? OR COALESCE(ad.full_name, '') ILIKE ?)"args = append(args, like, like)}rawSQL := `SELECTa.id AS account_id,10 unmodified linesJOIN exam_event_attempt eea ON eea.id = r.attempt_idJOIN account a ON a.id = eea.account_idLEFT JOIN account_details ad ON ad.account_id = a.id` + whereSQL + `ORDER BY ` + col + ` ` + ord + `LIMIT ? OFFSET ?`var rows []rawRowargs = append(args, p.Limit, p.Offset)if err := r.db.WithContext(ctx).Raw(rawSQL, args...).Scan(&rows).Error; err != nil {return nil, 0, err}16 unmodified linesreturn entries, total, nil}func (r *eventExamAttemptRepository) GetEventScoreboard(ctx context.Context, eventId uuid.UUID, p entity.Pagination) ([]entity.EventScoreboardEntry, int64, error) {type rawRow struct {AccountId stringUsername stringFullName stringTotalScore float32TotalCount int64}col := "total_score"ord := "DESC"switch p.SortBy {case "username":col = "a.username"ord = "ASC"case "full_name":col = "COALESCE(ad.full_name, '')"ord = "ASC"case "total_score", "score":col = "total_score"ord = "DESC"}if p.Order == "asc" {ord = "ASC"} else if p.Order == "desc" {ord = "DESC"}whereSQL := "WHERE eea.event_id = ?"args := []any{eventId}search := strings.TrimSpace(p.Search)if search != "" {like := "%" + search + "%"whereSQL += " AND (a.username ILIKE ? OR COALESCE(ad.full_name, '') ILIKE ?)"args = append(args, like, like)}rawSQL := `SELECTa.id AS account_id,a.username AS username,COALESCE(ad.full_name, '') AS full_name,SUM(r.final_score) AS total_score,COUNT(*) OVER() AS total_countFROM result rJOIN exam_event_attempt eea ON eea.id = r.attempt_idJOIN account a ON a.id = eea.account_idLEFT JOIN account_details ad ON ad.account_id = a.id` + whereSQL + `GROUP BY a.id, a.username, ad.full_nameORDER BY ` + col + ` ` + ord + `LIMIT ? OFFSET ?`var rows []rawRowargs = append(args, p.Limit, p.Offset)if err := r.db.WithContext(ctx).Raw(rawSQL, args...).Scan(&rows).Error; err != nil {return nil, 0, err}var total int64if len(rows) > 0 {total = rows[0].TotalCount}entries := make([]entity.EventScoreboardEntry, 0, len(rows))for _, row := range rows {id, _ := uuid.Parse(row.AccountId)entries = append(entries, entity.EventScoreboardEntry{AccountId: id,Username: row.Username,FullName: row.FullName,TotalScore: row.TotalScore,})}return entries, total, nil}
9 unmodified lines101112131415169 unmodified linesauth := middleware.ProvideAuthenticationMiddleware()// Group under api/v1/events to match existing event structurerouterGroup := router.Group("api/v1/proctoring"){// :event_slug and :exam_slug are kept for context/consistency with other routes,// even if not strictly used for lookup (IDs are in body/query).9 unmodified lines101112131415169 unmodified linesauth := middleware.ProvideAuthenticationMiddleware()// Group under api/v1/events to match existing event structurerouterGroup := router.Group("api/v1/events"){// :event_slug and :exam_slug are kept for context/consistency with other routes,// even if not strictly used for lookup (IDs are in body/query).
13 unmodified lines14151617181913 unmodified linesrouterGroup.GET("/:event_slug/exam/:exam_slug/attempt", auth.VerifyAccount, eventExamController.Attempt)routerGroup.POST("/:event_slug/exam/:attempt_id/answer_question", auth.VerifyAccount, eventExamController.Answer)routerGroup.POST("/:event_slug/exam/:attempt_id/submit", auth.VerifyAccount, eventExamController.Submit)routerGroup.GET("/:event_slug/:exam_slug/scoreboard", auth.VerifyAccount, eventExamController.Scoreboard)}}13 unmodified lines1415161718192013 unmodified linesrouterGroup.GET("/:event_slug/exam/:exam_slug/attempt", auth.VerifyAccount, eventExamController.Attempt)routerGroup.POST("/:event_slug/exam/:attempt_id/answer_question", auth.VerifyAccount, eventExamController.Answer)routerGroup.POST("/:event_slug/exam/:attempt_id/submit", auth.VerifyAccount, eventExamController.Submit)routerGroup.GET("/:event_slug/scoreboard", auth.VerifyAccount, eventExamController.EventScoreboard)routerGroup.GET("/:event_slug/:exam_slug/scoreboard", auth.VerifyAccount, eventExamController.Scoreboard)}}
25 unmodified lines262728293031234 unmodified lines266267268269270271272273233 unmodified lines50750850925 unmodified linesSubmitEventExam(ctx context.Context, attemptId uuid.UUID) (result entity.Result, err error)AnswerEventExam(ctx context.Context, eventSlug string, attemptId uuid.UUID, questionId uuid.UUID, answer []string) (entity.CPQuestionVerdict, error)Scoreboard(ctx context.Context, eventSlug string, examSlug string, accountId uuid.UUID, p entity.Pagination) ([]dto.ExamScoreboardItem, int64, error)}type evaluator func(answer []string) (float32, entity.CPQuestionVerdict)234 unmodified lines}attemptStatus, eventExamAttempt, err := s.GetEventExamAttempt(ctx, eventSlug, examSlug, accountId)if err != nil {return entity.EventExamAttempt{}, err}233 unmodified linesreturn items, total, nil}25 unmodified lines26272829303132234 unmodified lines267268269270271272233 unmodified lines50650750850951051151251351451551651751851952052152252352452552652752852953053125 unmodified linesSubmitEventExam(ctx context.Context, attemptId uuid.UUID) (result entity.Result, err error)AnswerEventExam(ctx context.Context, eventSlug string, attemptId uuid.UUID, questionId uuid.UUID, answer []string) (entity.CPQuestionVerdict, error)Scoreboard(ctx context.Context, eventSlug string, examSlug string, accountId uuid.UUID, p entity.Pagination) ([]dto.ExamScoreboardItem, int64, error)EventScoreboard(ctx context.Context, eventSlug string, accountId uuid.UUID, p entity.Pagination) ([]dto.EventScoreboardItem, int64, error)}type evaluator func(answer []string) (float32, entity.CPQuestionVerdict)234 unmodified lines}attemptStatus, eventExamAttempt, err := s.GetEventExamAttempt(ctx, eventSlug, examSlug, accountId)if err != nil {return entity.EventExamAttempt{}, err}233 unmodified linesreturn items, total, nil}func (s *eventExamService) EventScoreboard(ctx context.Context, eventSlug string, accountId uuid.UUID, p entity.Pagination) ([]dto.EventScoreboardItem, int64, error) {ev, err := s.eventService.DetailBySlug(ctx, eventSlug, accountId)if err != nil {return nil, 0, err}entries, total, err := s.eventExamAttemptRepo.GetEventScoreboard(ctx, ev.Data.Id, p)if err != nil {return nil, 0, err}items := make([]dto.EventScoreboardItem, 0, len(entries))for _, entry := range entries {items = append(items, dto.EventScoreboardItem{Username: entry.Username,FullName: entry.FullName,TotalScore: entry.TotalScore,})}return items, total, nil}
.env.example+2-3
Quzuu_API_Collection.postman_collection.json+81-3
Quzuu_Dev_Environment.postman_environment.json+6
controllers/event_exam_controller.go+97-64
models/dto/event_dto.go+19-13
models/entity/entity.go+7
repositories/event_exam_attempt_repository.go+103-2
router/event_exam_proctoring_router.go+1-1
router/event_exam_router.go+1
services/event_exam_service.go+24-2