diff --git a/src/main/kotlin/com/moa/controller/HomeController.kt b/src/main/kotlin/com/moa/controller/HomeController.kt new file mode 100644 index 0000000..a5c517a --- /dev/null +++ b/src/main/kotlin/com/moa/controller/HomeController.kt @@ -0,0 +1,42 @@ +package com.moa.controller + +import com.moa.common.auth.Auth +import com.moa.common.auth.AuthMemberInfo +import com.moa.common.response.ApiResponse +import com.moa.service.ProfileService +import com.moa.service.WorkPolicyService +import com.moa.service.WorkdayService +import com.moa.service.dto.HomeResponse +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RestController +import java.time.LocalDate + +@Tag(name = "Home", description = "홈 화면 API") +@RestController +class HomeController( + private val profileService: ProfileService, + private val workdayService: WorkdayService, + private val workPolicyService: WorkPolicyService, +) { + + @GetMapping("/api/v1/home") + fun getHome(@Auth member: AuthMemberInfo): ApiResponse { + val today = LocalDate.now() + val profile = profileService.getProfile(member.id) + val earnings = workdayService.getMonthlyEarnings(member.id, today.year, today.monthValue) + val schedule = workdayService.getSchedule(member.id, today) + val policy = workPolicyService.getCurrent(member.id) + + return ApiResponse.success( + HomeResponse( + workplace = profile.workplace, + workedEarnings = earnings.workedEarnings, + standardSalary = earnings.standardSalary, + dailyPay = schedule.dailyPay, + clockInTime = policy.clockInTime, + clockOutTime = policy.clockOutTime, + ) + ) + } +} diff --git a/src/main/kotlin/com/moa/service/dto/HomeResponse.kt b/src/main/kotlin/com/moa/service/dto/HomeResponse.kt new file mode 100644 index 0000000..8e8ac6d --- /dev/null +++ b/src/main/kotlin/com/moa/service/dto/HomeResponse.kt @@ -0,0 +1,15 @@ +package com.moa.service.dto + +import com.fasterxml.jackson.annotation.JsonFormat +import java.time.LocalTime + +data class HomeResponse( + val workplace: String?, + val workedEarnings: Int, + val standardSalary: Int, + val dailyPay: Int, + @JsonFormat(pattern = "HH:mm") + val clockInTime: LocalTime, + @JsonFormat(pattern = "HH:mm") + val clockOutTime: LocalTime, +)