Skip to content

Commit

Permalink
Add getting study details api
Browse files Browse the repository at this point in the history
  • Loading branch information
mkSpace committed Jun 19, 2023
1 parent 789d56e commit 4b99075
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class StudyController(
@Operation(summary = "Study Detail API", description = "Study 상세 조회")
@GetMapping("/{studyId}")
fun getDetail(@PathVariable studyId: Long): MoitApiResponse<StudyDetailsResponse> {
return MoitApiResponse.success(StudyDetailsResponse.sample())
return MoitApiResponse.success(studyFacade.getDetails(studyId))
}

@Operation(summary = "Study Keyword API", description = "study 키워드 조회")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mashup.moit.study.controller.dto

import com.mashup.moit.domain.attendance.AttendanceStatus
import com.mashup.moit.domain.moit.Moit
import com.mashup.moit.domain.study.Study
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Size
Expand All @@ -17,7 +19,7 @@ data class StudyDetailsResponse(
@Schema(description = "Study 끝나는 날짜 및 시간")
val endAt: LocalDateTime,
@Schema(description = "Study 리마인드 날짜 및 시간")
val remindAt: LocalDateTime,
val remindAt: LocalDateTime? = null,
@Schema(description = "Study 지각 날짜 및 시간")
val lateAt: LocalDateTime,
@Schema(description = "Study 결석 날짜 및 시간")
Expand All @@ -26,15 +28,19 @@ data class StudyDetailsResponse(
val firstAttendanceUserNickname: String? = null
) {
companion object {
fun sample(): StudyDetailsResponse = StudyDetailsResponse(
moitName = "전자군단",
order = 1,
startAt = LocalDateTime.of(2023, 6, 15, 16, 0),
endAt = LocalDateTime.of(2023, 6, 15, 19, 0),
remindAt = LocalDateTime.of(2023, 6, 15, 15, 30),
lateAt = LocalDateTime.of(2023, 6, 15, 16, 30),
absenceAt = LocalDateTime.of(2023, 6, 15, 17, 0),
firstAttendanceUserNickname = null
fun of(
moit: Moit,
study: Study,
firstAttendanceUserNickname: String?
): StudyDetailsResponse = StudyDetailsResponse(
moitName = moit.name,
order = study.order,
startAt = study.startAt,
endAt = study.endAt,
remindAt = study.remindAt,
lateAt = study.lateAt,
absenceAt = study.absenceAt,
firstAttendanceUserNickname = firstAttendanceUserNickname
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package com.mashup.moit.study.facade

import com.mashup.moit.domain.moit.MoitService
import com.mashup.moit.domain.study.StudyService
import com.mashup.moit.domain.user.UserService
import com.mashup.moit.study.controller.dto.StudyAttendanceKeywordResponse
import com.mashup.moit.study.controller.dto.StudyDetailsResponse
import org.springframework.stereotype.Component

@Component
class StudyFacade(
private val studyService: StudyService
private val moitService: MoitService,
private val studyService: StudyService,
private val userService: UserService
) {
fun getAttendanceKeyword(studyId: Long): StudyAttendanceKeywordResponse {
return studyService.getAttendanceKeyword(studyId)
.let { StudyAttendanceKeywordResponse.of(it) }
}

fun getDetails(studyId: Long): StudyDetailsResponse {
val study = studyService.findById(studyId)
val moit = moitService.findById(study.moitId)
val firstAttendanceUserNickname = study.firstAttendanceUserId?.let(userService::findByIdOrNull)?.nickname
return StudyDetailsResponse.of(moit, study, firstAttendanceUserNickname)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ class MoitService(

return moit.toDomain()
}

fun findById(moitId: Long): Moit {
return moitRepository.findById(moitId)
.orElseThrow { throw MoitException.of(MoitExceptionType.NOT_EXIST) }
.toDomain()
}
}
14 changes: 11 additions & 3 deletions moit-domain/src/main/kotlin/com/mashup/moit/domain/study/Study.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package com.mashup.moit.domain.study

import java.time.LocalDateTime

data class Study(
val id: Long,
val moitId: Long,
val order: Int
val id: Long,
val moitId: Long,
val order: Int,
val startAt: LocalDateTime,
val endAt: LocalDateTime,
val remindAt: LocalDateTime?,
val lateAt: LocalDateTime,
val absenceAt: LocalDateTime,
val firstAttendanceUserId: Long? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,11 @@ class StudyEntity(
id = id,
moitId = moitId,
order = order,
startAt = startAt,
endAt = endAt,
remindAt = remindAt,
lateAt = lateAt,
absenceAt = absenceAt,
firstAttendanceUserId = firstAttendanceUserId
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ class StudyService(
null
}
}

fun getAttendanceKeyword(studyId: Long): String? {
return studyRepository.findById(studyId)
.orElseThrow{ MoitException.of(MoitExceptionType.NOT_EXIST)}
.orElseThrow { MoitException.of(MoitExceptionType.NOT_EXIST) }
.attendanceCode
}

fun findById(studyId: Long): Study {
return studyRepository.findById(studyId)
.orElseThrow { MoitException.of(MoitExceptionType.NOT_EXIST) }
.toDomain()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mashup.moit.domain.user

import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service

@Service
Expand All @@ -10,4 +11,8 @@ class UserService(
return userRepository.findByIdIn(ids)
.map { it.toDomain() }
}

fun findByIdOrNull(userId: Long): User? {
return userRepository.findByIdOrNull(userId)?.toDomain()
}
}

0 comments on commit 4b99075

Please sign in to comment.