Skip to content

Commit

Permalink
Merge pull request #17 from HappyScrolls/feature/#16_common_schedule
Browse files Browse the repository at this point in the history
Feature/#16 common schedule
  • Loading branch information
chs98412 authored Sep 26, 2024
2 parents e40cc13 + 483be86 commit c19a070
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ScheduleQueryService(
) {

// 특정 날짜 일정 조회
fun getScheduleByDate(accountNo: Int, searchDate: LocalDate): List<ScheduleDetailResponse> {
val schedules: List<Schedule> = scheduleRepository.findByAccountNoAndScheduleAt(accountNo, searchDate)
fun getCommonScheduleByDate(accountNo: Int, loverNo: Int, searchDate: LocalDate): List<ScheduleDetailResponse> {
val schedules: List<Schedule> = scheduleRepository.findByAccountNoInAndScheduleAtAndIsCommonIsTrue(listOf(accountNo, loverNo), searchDate)

// 조회한 일정들 -> ScheduleDetailResponse
return schedules.map { schedule -> ScheduleDetailResponse.from(schedule) }
Expand All @@ -22,7 +22,6 @@ class ScheduleQueryService(
fun getScheduleByDateExceptCommon(accountNo: Int, searchDate: LocalDate): List<ScheduleDetailResponse> {
val schedules: List<Schedule> = scheduleRepository.findByAccountNoAndScheduleAtAndIsCommonIsFalse(accountNo, searchDate)

// 조회한 일정들 -> ScheduleDetailResponse
return schedules.map { schedule -> ScheduleDetailResponse.from(schedule) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import java.time.LocalDate

interface ScheduleRepository : JpaRepository<Schedule, Int> {
// 특정 일정 조회
fun findByAccountNoAndScheduleAt(accountNo: Int, scheduleAt: LocalDate): List<Schedule>
fun findByAccountNoAndScheduleAtAndIsCommonIsFalse(accountNo: Int, scheduleAt: LocalDate): List<Schedule>
fun findByAccountNoInAndScheduleAtAndIsCommonIsTrue(accountNos: List<Int>, scheduleAt: LocalDate): List<Schedule>

// 일정 상세 조회
fun findByAccountNoAndScheduleNo(accountNo: Int, scheduleNo: Int): Schedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ScheduleHandler(
suspend fun readSchedules(request: ServerRequest): ServerResponse = withContext(Dispatchers.IO) {
val memberHeader = request.extractMemberCodeHeader()
val searchDate = request.localDateQueryParam("searchDate")
val result = scheduleQueryService.getScheduleByDate(memberHeader.no, searchDate)
val result = scheduleQueryService.getScheduleByDateExceptCommon(memberHeader.no, searchDate)
ServerResponse.ok().bodyValueAndAwait(result)
}

Expand All @@ -60,6 +60,19 @@ class ScheduleHandler(
ServerResponse.ok().bodyValueAndAwait(result)
}

suspend fun getCommonSchedules(request: ServerRequest): ServerResponse = withContext(Dispatchers.IO) {
val memberHeader = request.extractRawMemberCodeHeader()
val memberInfo = request.extractMemberCodeHeader()

val couplePartnerResponse = coupleService.getCouplePartnerInfo(memberHeader)
val partnerNo = couplePartnerResponse.no
val searchDate = request.localDateQueryParam("searchDate")

val result = scheduleQueryService.getCommonScheduleByDate(memberInfo.no, partnerNo, searchDate)

ServerResponse.ok().bodyValueAndAwait(result)
}

// 일정 삭제
suspend fun deleteSchedule(request: ServerRequest): ServerResponse = withContext(Dispatchers.IO) {
val scheduleNo = request.intPathVariable("scheduleNo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.time.LocalDateTime

data class ScheduleDetailResponse(
val scheduleNo: Int,
val accountNo: Int,
val busyLevel: String,
val scheduleName: String,
val scheduleLocation: String,
Expand All @@ -18,6 +19,7 @@ data class ScheduleDetailResponse(
// 특정 일정 조회 (엔티티 -> response)
fun from(schedule: Schedule) = ScheduleDetailResponse(
scheduleNo = schedule.scheduleNo,
accountNo = schedule.accountNo,
busyLevel = schedule.busyLevel,
scheduleName = schedule.scheduleName,
scheduleLocation = schedule.scheduleLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ScheduleRouter(private val scheduleHandler: ScheduleHandler) {

// (커플) 특정 날짜 일정 조회
GET("/couple", scheduleHandler::readCouplePartnerSchedules)

GET("/common", scheduleHandler::getCommonSchedules)
// 일정 삭제
DELETE("/{scheduleNo}", scheduleHandler::deleteSchedule)
PUT("/{scheduleNo}/status", scheduleHandler::changeStatus)
Expand Down
11 changes: 8 additions & 3 deletions src/test/http/example.http
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Member-Code: eyJubyI6MiwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9
}

### 특정 날짜 일정 조회
GET {{url}}/schedule?searchDate=2024-09-02
GET {{url}}/schedule?searchDate=2024-09-26
Content-Type: application/json
Member-Code: eyJubyI6MiwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9

Expand All @@ -42,7 +42,7 @@ Content-Type: application/json
Member-Code: eyJubyI6MSwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9

### (커플) 특정 날짜 일정 조회
GET {{url}}/schedule/couple?searchDate=2024-09-02
GET {{url}}/schedule/couple?searchDate=2024-09-26
Content-Type: application/json
Member-Code: eyJubyI6MSwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9

Expand All @@ -52,4 +52,9 @@ Content-Type: application/json

### 일정 삭제
PUT {{url}}/schedule/7/status?status=종료
Content-Type: application/json
Content-Type: application/json

### 공통 일정
GET {{url}}/schedule/common?searchDate=2024-09-26
Content-Type: application/json
Member-Code: eyJubyI6MSwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9

0 comments on commit c19a070

Please sign in to comment.