Skip to content
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
42 changes: 42 additions & 0 deletions src/main/kotlin/com/moa/controller/HomeController.kt
Original file line number Diff line number Diff line change
@@ -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<HomeResponse> {
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,
)
)
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/com/moa/service/dto/HomeResponse.kt
Original file line number Diff line number Diff line change
@@ -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,
)
Loading