This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user