fix
All checks were successful
Deploy on Master Change / deploy (push) Successful in 1m17s

This commit is contained in:
2026-07-13 11:00:17 +07:00
parent 06f2edb195
commit bad51585db
7 changed files with 125 additions and 47 deletions

View File

@@ -49,6 +49,7 @@ func AutoMigrate(db *gorm.DB) error {
&models.ClassCourse{},
&models.ClassAllowedApp{},
&models.ClassSeatingLayout{},
&models.ExamSeatingLayout{},
&models.StaffMyClass{},
&models.AppPoolEntry{},
&models.AppTemplate{},

View File

@@ -75,6 +75,65 @@ func DeleteClassSeatingLayoutHandler(db *gorm.DB) fiber.Handler {
}
}
// GET /exam-rooms/:id/seating-layout
func GetExamSeatingLayoutHandler(db *gorm.DB) fiber.Handler {
return func(c *fiber.Ctx) error {
examID, err := strconv.ParseUint(c.Params("id"), 10, 64)
if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid exam room ID"})
}
var layout models.ExamSeatingLayout
if err := db.Where("exam_room_id = ?", examID).First(&layout).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return c.JSON(fiber.Map{"layoutJson": nil})
}
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
}
return c.JSON(fiber.Map{"layoutJson": layout.LayoutJSON})
}
}
// PUT /exam-rooms/:id/seating-layout
func PutExamSeatingLayoutHandler(db *gorm.DB) fiber.Handler {
return func(c *fiber.Ctx) error {
examID, err := strconv.ParseUint(c.Params("id"), 10, 64)
if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid exam room ID"})
}
var body struct {
LayoutJSON string `json:"layoutJson"`
}
if err := c.BodyParser(&body); err != nil || body.LayoutJSON == "" {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "layoutJson is required"})
}
layout := models.ExamSeatingLayout{
ExamRoomID: uint(examID),
LayoutJSON: body.LayoutJSON,
UpdatedAt: time.Now(),
}
result := db.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "exam_room_id"}},
DoUpdates: clause.AssignmentColumns([]string{"layout_json", "updated_at"}),
}).Create(&layout)
if result.Error != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": result.Error.Error()})
}
return c.JSON(fiber.Map{"ok": true})
}
}
// DELETE /exam-rooms/:id/seating-layout
func DeleteExamSeatingLayoutHandler(db *gorm.DB) fiber.Handler {
return func(c *fiber.Ctx) error {
examID, err := strconv.ParseUint(c.Params("id"), 10, 64)
if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid exam room ID"})
}
db.Where("exam_room_id = ?", examID).Delete(&models.ExamSeatingLayout{})
return c.JSON(fiber.Map{"ok": true})
}
}
// GET /staff/my-classes
func GetMyClassesHandler(db *gorm.DB) fiber.Handler {
return func(c *fiber.Ctx) error {

View File

@@ -106,6 +106,15 @@ type ClassSeatingLayout struct {
func (ClassSeatingLayout) TableName() string { return "class_seating_layouts" }
// ExamSeatingLayout lưu sơ đồ chỗ ngồi theo phòng thi
type ExamSeatingLayout struct {
ExamRoomID uint `gorm:"column:exam_room_id;primaryKey;not null" json:"examRoomId"`
LayoutJSON string `gorm:"column:layout_json;type:longtext;not null" json:"layoutJson"`
UpdatedAt time.Time `json:"updatedAt"`
}
func (ExamSeatingLayout) TableName() string { return "exam_seating_layouts" }
// ClassAllowedApp lưu từ khóa app được mở của lớp
type ClassAllowedApp struct {
ClassRkID int64 `gorm:"column:class_rk_id;primaryKey;not null" json:"classRkId"`

View File

@@ -213,6 +213,9 @@ func main() {
staff.Post("/exam-rooms/:id/cancel", handlers.CancelExamRoomHandler(gormDB))
staff.Post("/exam-rooms/:id/assign-random", handlers.RandomAssignExamPapersHandler(gormDB))
staff.Post("/exam-rooms/:id/assign-papers-batch", handlers.AssignExamPapersBatchHandler(gormDB))
staff.Get("/exam-rooms/:id/seating-layout", handlers.GetExamSeatingLayoutHandler(gormDB))
staff.Put("/exam-rooms/:id/seating-layout", handlers.PutExamSeatingLayoutHandler(gormDB))
staff.Delete("/exam-rooms/:id/seating-layout", handlers.DeleteExamSeatingLayoutHandler(gormDB))
staff.Post("/exam-rooms/:id/send-papers", handlers.SendExamPapersHandler(gormDB))
staff.Get("/exam-rooms/:id/submissions", handlers.ListExamSubmissionsHandler(gormDB))
staff.Get("/exam-rooms/:id/submissions/download-all", handlers.DownloadAllExamSubmissionsHandler(gormDB))