Skip to content

Commit

Permalink
feat: user 출석체크 조회 api 추가
Browse files Browse the repository at this point in the history
feat: user 출석체크 조회 api 추가
  • Loading branch information
Woonseok105 authored Oct 30, 2023
2 parents fbeb42c + b5a6dcd commit a98fef4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import kr.hs.dsm.inq.domain.user.persistence.Attendance
import org.springframework.data.repository.CrudRepository

interface AttendanceRepository : CrudRepository<Attendance, Long> {
fun findAllByUserId(userId: Long): List<Attendance>?
fun findByUserId(userId: Long): Attendance?
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package kr.hs.dsm.inq.domain.user.presentation

import javax.validation.Valid
import kr.hs.dsm.inq.common.dto.TokenResponse
import kr.hs.dsm.inq.domain.user.presentation.dto.UpdateUserInfoRequest
import kr.hs.dsm.inq.domain.user.presentation.dto.UserInfoResponse
import kr.hs.dsm.inq.domain.user.presentation.dto.UserSignInRequest
import kr.hs.dsm.inq.domain.user.presentation.dto.UserSignUpRequest
import kr.hs.dsm.inq.domain.user.presentation.dto.*
import kr.hs.dsm.inq.domain.user.service.UserService
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.GetMapping
Expand Down Expand Up @@ -37,8 +34,12 @@ class UserController(
userService.queryUserInfo()

@PutMapping("/profile")
fun updateUserInfo(@RequestBody request: UpdateUserInfoRequest) {
fun updateUserInfo(@Valid @RequestBody request: UpdateUserInfoRequest) {
userService.updateUserInfo(request)
}

@GetMapping("/check")
fun queryUserAttendance(): UserAttendanceResponse =
userService.queryUserAttendance()

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,20 @@ data class UserInfoResponse(
val coin: Int,
val job: String,
val jobDuration: Int
)

data class UserAttendanceResponse(
val monday: Boolean,

val tuesday: Boolean,

val wednesday: Boolean,

val thursday: Boolean,

val friday: Boolean,

val saturday: Boolean,

val sunday: Boolean,
)
21 changes: 18 additions & 3 deletions src/main/kotlin/kr/hs/dsm/inq/domain/user/service/UserService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kr.hs.dsm.inq.domain.user.service

import kr.hs.dsm.inq.common.dto.TokenResponse
import kr.hs.dsm.inq.common.util.SecurityUtil
import kr.hs.dsm.inq.domain.user.exception.AttendanceNotFound
import kr.hs.dsm.inq.domain.user.exception.PasswordMismatchException
import kr.hs.dsm.inq.domain.user.exception.UserAlreadyExist
import kr.hs.dsm.inq.domain.user.exception.UserNotFound
Expand Down Expand Up @@ -36,7 +37,6 @@ class UserService(
}

fun signUp(request: UserSignUpRequest) {

if (userRepository.existsByAccountId(request.accountId)) {
throw UserAlreadyExist
}
Expand All @@ -54,7 +54,6 @@ class UserService(
}

fun queryUserInfo(): UserInfoResponse {

val user = SecurityUtil.getCurrentUser()

return UserInfoResponse(
Expand All @@ -68,9 +67,25 @@ class UserService(

@Transactional
fun updateUserInfo(request: UpdateUserInfoRequest) {

val user = SecurityUtil.getCurrentUser()

user.updateInfo(request)
}

fun queryUserAttendance(): UserAttendanceResponse {
val user = SecurityUtil.getCurrentUser()

val attendance = attendanceRepository.findByUserId(user.id)
?: throw AttendanceNotFound

return UserAttendanceResponse(
monday = attendance.monday,
tuesday = attendance.tuesday,
wednesday = attendance.wednesday,
thursday = attendance.thursday,
friday = attendance.friday,
saturday = attendance.saturday,
sunday = attendance.sunday
)
}
}

0 comments on commit a98fef4

Please sign in to comment.