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

feat : 05_18 OT 전 개발 #33

Merged
merged 13 commits into from
May 17, 2024
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.example.cmc_be.attendance.controller

import com.example.cmc_be.attendance.dto.AttendanceReq
import com.example.cmc_be.attendance.dto.AttendanceRes
import com.example.cmc_be.attendance.dto.req.GenerateCode
import com.example.cmc_be.attendance.dto.res.AllAttendanceInfos
import com.example.cmc_be.attendance.dto.res.AttendanceCodeRes
import com.example.cmc_be.attendance.dto.res.QrSchemata
import com.example.cmc_be.attendance.service.AttendanceService
import com.example.cmc_be.attendance.service.QrCodeService
import com.example.cmc_be.common.dto.response.CommonResponse
import com.example.cmc_be.common.exeption.BadRequestException
import com.example.cmc_be.common.response.CommonResponse
import com.example.cmc_be.domain.attendance.entity.AttendanceCode
import com.example.cmc_be.domain.attendance.exception.AttendanceErrorCode
import com.example.cmc_be.domain.generation.repository.GenerationWeeksInfoRepository
import com.example.cmc_be.domain.user.entity.User
Expand All @@ -27,12 +30,12 @@ class AdminAttendanceController(
@Operation(summary = "03-01 출석용 코드 생성(중복 생성 가능)")
fun generateCode(
@AuthenticationPrincipal user: User,
@RequestBody gernerateCode: AttendanceReq.GenerateCode
): CommonResponse<String> {
@RequestBody gernerateCode: GenerateCode
): CommonResponse<QrSchemata> {
val generationWeeksInfo = generationWeeksInfoRepository.findFirstByGenerationAndWeek(
generation = gernerateCode.generation, week = gernerateCode.week
) ?: throw BadRequestException(AttendanceErrorCode.CANNOT_ACCESS_ATEENDANCE)

return CommonResponse.onSuccess(
qrCodeService.generateCode(
generationReq = gernerateCode,
Expand All @@ -42,22 +45,29 @@ class AdminAttendanceController(
}

@GetMapping("/code")
@Operation(summary = "03-02 코드 정보 조회")
@Operation(summary = "03-02 특정 코드 정보 조회")
fun getCodeInfo(
@AuthenticationPrincipal user: User,
@Parameter(description = "코드", example = "8dFsb")
@RequestParam code: String,
): CommonResponse<AttendanceRes.AttendanceCodeDto> {
): CommonResponse<AttendanceCodeRes> {
return CommonResponse.onSuccess(qrCodeService.getCodeInfo(code))
}

@GetMapping("/code/all")
@Operation(summary = "03-03 모든 코드 정보 조회")
fun getCodeInfo(
@AuthenticationPrincipal user: User,
): CommonResponse<List<AttendanceCode>> {
return CommonResponse.onSuccess(qrCodeService.getAllCodes())
}

@GetMapping("/all")
@Operation(summary = "03-03 기수별 모든 출석 현황 체크")
@Operation(summary = "03-04 기수별 모든 출석 현황 체크")
fun getParticipantsAttendance(
@AuthenticationPrincipal user: User,
@Parameter(description = "기수", example = "13") @RequestParam generation: Int,
): CommonResponse<List<AttendanceRes.AllAttendanceInfoDto>> {
): CommonResponse<List<AllAttendanceInfos>> {
return CommonResponse.onSuccess(attendanceService.getParticipantsAttendance(generation))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.example.cmc_be.attendance.controller

import com.example.cmc_be.attendance.dto.AttendanceReq
import com.example.cmc_be.attendance.dto.AttendanceRes
import com.example.cmc_be.attendance.dto.req.AttendanceCodeReq
import com.example.cmc_be.attendance.dto.res.AttendancesDashboard
import com.example.cmc_be.attendance.service.AttendanceService
import com.example.cmc_be.common.response.CommonResponse
import com.example.cmc_be.common.dto.response.CommonResponse
import com.example.cmc_be.domain.user.entity.User
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
Expand All @@ -18,15 +18,15 @@ class AttendanceController(
) {
@GetMapping("")
@Operation(summary = "03-01 출석 현황 조회")
fun getAttendanceList(@AuthenticationPrincipal user: User): CommonResponse<AttendanceRes.GetAttendances> {
fun getAttendanceList(@AuthenticationPrincipal user: User): CommonResponse<AttendancesDashboard> {
return CommonResponse.onSuccess(attendanceService.getAttendanceList(user))
}

@PostMapping("")
@Operation(summary = "03-02 출석 체크 진행")
fun setAttendance(
@AuthenticationPrincipal user: User,
@RequestBody attendanceCode: AttendanceReq.AttendanceCode
@RequestBody attendanceCode: AttendanceCodeReq
): CommonResponse<String> {
return CommonResponse.onSuccess(attendanceService.setAttendance(user, attendanceCode))
}
Expand Down

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/kotlin/com/example/cmc_be/attendance/dto/AttendanceReq.kt

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/kotlin/com/example/cmc_be/attendance/dto/AttendanceRes.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.cmc_be.attendance.dto.req

data class AttendanceCodeReq(
val code: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.cmc_be.attendance.dto.req

import io.swagger.v3.oas.annotations.media.Schema

data class GenerateCode(
@Schema(example = "14")
val generation: Int,
@Schema(example = "1")
val week: Int,
@Schema(example = "1")
val hour: Int,
val startTime: HourAndMinute,
val endTime: HourAndMinute,
@Schema(example = "15")
val lateMinute: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.cmc_be.attendance.dto.req

import java.time.LocalTime

data class HourAndMinute(
val hour: Int,
val minute: Int
) {
fun toLocalTime(): LocalTime = LocalTime.of(hour, minute)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.cmc_be.attendance.dto.res

data class AllAttendanceInfos(
val name: String,
val role: String,
val nickname: String,
val attendanceStatus: AttendanceDashboardInfo,
val attandances: List<AttendanceInfo>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.cmc_be.attendance.dto.res

import com.fasterxml.jackson.annotation.JsonFormat
import java.time.LocalDate
import java.time.LocalTime

data class AttendanceCodeRes(
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
val availableDate: LocalDate,
val startTime: LocalTime,
val endTime: LocalTime,
val lateMinute: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.cmc_be.attendance.dto.res

import com.example.cmc_be.domain.attendance.enums.AttendanceCategory

data class AttendanceDashboardInfo(
val attendanceCount: Int,
val lateCount: Int,
val absentCount: Int
) {

companion object {
fun from(attendanceInfos: List<AttendanceInfo>): AttendanceDashboardInfo {
return AttendanceDashboardInfo(
attendanceCount = attendanceInfos.count { it.firstHour == AttendanceCategory.ATTENDANCE } + attendanceInfos.count { it.secondHour == AttendanceCategory.ATTENDANCE },
lateCount = attendanceInfos.count { it.firstHour == AttendanceCategory.LATE } + attendanceInfos.count { it.secondHour == AttendanceCategory.LATE },
absentCount = attendanceInfos.count { it.firstHour == AttendanceCategory.ABSENT } + attendanceInfos.count { it.secondHour == AttendanceCategory.ABSENT },
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.cmc_be.attendance.dto.res

import com.example.cmc_be.domain.attendance.enums.AttendanceCategory
import com.fasterxml.jackson.annotation.JsonFormat
import java.time.LocalDate

data class AttendanceInfo(
val week: Int,
val firstHour: AttendanceCategory,
val secondHour: AttendanceCategory,
val isOffline: Boolean,
val enable: Boolean,
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
val date: LocalDate
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.cmc_be.attendance.dto.res

data class AttendancesDashboard(
val attendanceStatus: AttendanceDashboardInfo,
val attandances: List<AttendanceInfo>
) {

companion object {
fun from(attendanceInfos: List<AttendanceInfo>): AttendancesDashboard {
val enableAttendances = attendanceInfos.filter { it.enable }
return AttendancesDashboard(
attendanceStatus = AttendanceDashboardInfo.from(enableAttendances),
attandances = attendanceInfos
)
}
}
}
Loading
Loading