diff --git a/controllers/attendance_controller.go b/controllers/attendance_controller.go index 7d301fc..d5085d7 100644 --- a/controllers/attendance_controller.go +++ b/controllers/attendance_controller.go @@ -80,22 +80,29 @@ func (ac *AttendanceController) CreateOrUpdateAttendance(ctx *gin.Context) { // @Router /at/{classID} [get] // @Security Bearer func (ac *AttendanceController) GetAllAttendances(ctx *gin.Context) { + log.Println("GetAllAttendances: Request received") + classID, err := strconv.ParseUint(ctx.Param("classID"), 10, 32) if err != nil { + log.Printf("GetAllAttendances: Invalid classID: %v", err) handleServiceError(ctx, fmt.Errorf(constants.InvalidRequest)) return } + log.Printf("GetAllAttendances: Parsed classID: %d", classID) attendances, serviceErr := ac.attendanceService.GetAllAttendancesByCID(uint(classID)) if serviceErr != nil { + log.Printf("GetAllAttendances: Error retrieving attendances: %v", serviceErr) handleServiceError(ctx, serviceErr) return } if len(attendances) == 0 { + log.Println("GetAllAttendances: No attendances found") respondWithError(ctx, constants.StatusNotFound, "No attendance found") return } + log.Printf("GetAllAttendances: Found %d attendances", len(attendances)) respondWithSuccess(ctx, constants.StatusOK, attendances) } diff --git a/docs/docs.go b/docs/docs.go index c24cd4a..b09da63 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -22,7 +22,7 @@ const docTemplate = `{ "Bearer": [] } ], - "description": "複数の出席情報を作成または更新します。'Attendance', 'Tardy', 'Absence'のいずれかのステータスを持つことができます。", + "description": "複数の出席情報を作成または更新します。'ATTENDANCE', 'TARDY', 'ABSENCE'のいずれかのステータスを持つことができます。", "consumes": [ "application/json" ], @@ -3114,7 +3114,11 @@ const docTemplate = `{ }, "isAttendance": { "description": "出席, 遅刻, 欠席", - "type": "string" + "allOf": [ + { + "$ref": "#/definitions/models.AttendanceType" + } + ] }, "uid": { "description": "User ID", @@ -3122,6 +3126,19 @@ const docTemplate = `{ } } }, + "models.AttendanceType": { + "type": "string", + "enum": [ + "ATTENDANCE", + "TARDY", + "ABSENCE" + ], + "x-enum-varnames": [ + "AttendanceStatus", + "TardyStatus", + "AbsenceStatus" + ] + }, "models.Class": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 11c37e9..d95bda8 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -11,7 +11,7 @@ "Bearer": [] } ], - "description": "複数の出席情報を作成または更新します。'Attendance', 'Tardy', 'Absence'のいずれかのステータスを持つことができます。", + "description": "複数の出席情報を作成または更新します。'ATTENDANCE', 'TARDY', 'ABSENCE'のいずれかのステータスを持つことができます。", "consumes": [ "application/json" ], @@ -3103,7 +3103,11 @@ }, "isAttendance": { "description": "出席, 遅刻, 欠席", - "type": "string" + "allOf": [ + { + "$ref": "#/definitions/models.AttendanceType" + } + ] }, "uid": { "description": "User ID", @@ -3111,6 +3115,19 @@ } } }, + "models.AttendanceType": { + "type": "string", + "enum": [ + "ATTENDANCE", + "TARDY", + "ABSENCE" + ], + "x-enum-varnames": [ + "AttendanceStatus", + "TardyStatus", + "AbsenceStatus" + ] + }, "models.Class": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 540cafd..3a73082 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -102,12 +102,23 @@ definitions: id: type: integer isAttendance: + allOf: + - $ref: '#/definitions/models.AttendanceType' description: 出席, 遅刻, 欠席 - type: string uid: description: User ID type: integer type: object + models.AttendanceType: + enum: + - ATTENDANCE + - TARDY + - ABSENCE + type: string + x-enum-varnames: + - AttendanceStatus + - TardyStatus + - AbsenceStatus models.Class: properties: description: @@ -203,7 +214,7 @@ paths: post: consumes: - application/json - description: 複数の出席情報を作成または更新します。'Attendance', 'Tardy', 'Absence'のいずれかのステータスを持つことができます。 + description: 複数の出席情報を作成または更新します。'ATTENDANCE', 'TARDY', 'ABSENCE'のいずれかのステータスを持つことができます。 parameters: - description: 出席情報 in: body diff --git a/repositories/attendance_repository.go b/repositories/attendance_repository.go index 9f996c1..8a70d6d 100644 --- a/repositories/attendance_repository.go +++ b/repositories/attendance_repository.go @@ -3,6 +3,7 @@ package repositories import ( "github.com/YJU-OKURA/project_minori-gin-deployment-repo/models" "gorm.io/gorm" + "log" ) // AttendanceRepository インタフェース @@ -40,14 +41,20 @@ func (repo *attendanceRepository) GetAttendanceByUIDAndCID(uid uint, cid uint) ( // GetAllAttendancesByCID CIDによって全ての出席情報を取得 func (repo *attendanceRepository) GetAllAttendancesByCID(cid uint) ([]models.Attendance, error) { var attendances []models.Attendance + log.Printf("GetAllAttendancesByCID: Executing query for cid %d", cid) err := repo.db.Where("cid = ?", cid).Find(&attendances).Error + if err != nil { + log.Printf("GetAllAttendancesByCID: Query error: %v", err) + return nil, err + } + log.Printf("GetAllAttendancesByCID: Query successful, found %d attendances", len(attendances)) return attendances, err } // GetAttendanceByID IDによって出席情報を取得 func (repo *attendanceRepository) GetAttendanceByID(id string) (*models.Attendance, error) { var attendance models.Attendance - err := repo.db.Where("id = ?", id).First(&attendance).Error + err := repo.db.Where("csid = ?", id).First(&attendance).Error return &attendance, err }