Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIN-301] 出席 API のロギングとエラーハンドリングの改善、および Swagger ドキュメントの修正 #329

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions controllers/attendance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

yuminn-k marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
21 changes: 19 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const docTemplate = `{
"Bearer": []
}
],
"description": "複数の出席情報を作成または更新します。'Attendance', 'Tardy', 'Absence'のいずれかのステータスを持つことができます。",
"description": "複数の出席情報を作成または更新します。'ATTENDANCE', 'TARDY', 'ABSENCE'のいずれかのステータスを持つことができます。",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -3114,14 +3114,31 @@ const docTemplate = `{
},
"isAttendance": {
"description": "出席, 遅刻, 欠席",
"type": "string"
"allOf": [
{
"$ref": "#/definitions/models.AttendanceType"
}
]
},
"uid": {
"description": "User ID",
"type": "integer"
}
}
},
"models.AttendanceType": {
"type": "string",
"enum": [
"ATTENDANCE",
"TARDY",
"ABSENCE"
],
"x-enum-varnames": [
"AttendanceStatus",
"TardyStatus",
"AbsenceStatus"
]
},
"models.Class": {
"type": "object",
"properties": {
yuminn-k marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
21 changes: 19 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Bearer": []
}
],
"description": "複数の出席情報を作成または更新します。'Attendance', 'Tardy', 'Absence'のいずれかのステータスを持つことができます。",
"description": "複数の出席情報を作成または更新します。'ATTENDANCE', 'TARDY', 'ABSENCE'のいずれかのステータスを持つことができます。",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -3103,14 +3103,31 @@
},
"isAttendance": {
"description": "出席, 遅刻, 欠席",
"type": "string"
"allOf": [
{
"$ref": "#/definitions/models.AttendanceType"
}
]
},
"uid": {
"description": "User ID",
"type": "integer"
}
}
},
"models.AttendanceType": {
"type": "string",
"enum": [
"ATTENDANCE",
"TARDY",
"ABSENCE"
],
"x-enum-varnames": [
"AttendanceStatus",
"TardyStatus",
"AbsenceStatus"
]
},
"models.Class": {
"type": "object",
"properties": {
yuminn-k marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
15 changes: 13 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -203,7 +214,7 @@ paths:
post:
consumes:
- application/json
description: 複数の出席情報を作成または更新します。'Attendance', 'Tardy', 'Absence'のいずれかのステータスを持つことができます。
description: 複数の出席情報を作成または更新します。'ATTENDANCE', 'TARDY', 'ABSENCE'のいずれかのステータスを持つことができます。
parameters:
- description: 出席情報
in: body
yuminn-k marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
9 changes: 8 additions & 1 deletion repositories/attendance_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package repositories
import (
"github.com/YJU-OKURA/project_minori-gin-deployment-repo/models"
"gorm.io/gorm"
"log"
)

// AttendanceRepository インタフェース
Expand Down Expand Up @@ -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
}

yuminn-k marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading