Skip to content

Commit

Permalink
feat: 이번 주차 세션 정보 조회 (#91)
Browse files Browse the repository at this point in the history
feat: 이번 주차 세션 정보 조회
  • Loading branch information
ddingmin authored Jun 8, 2024
1 parent 23b730b commit 084c3e6
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.depromeet.makers.domain.usecase

import com.depromeet.makers.domain.exception.SessionNotFoundException
import com.depromeet.makers.domain.gateway.SessionGateway
import com.depromeet.makers.domain.model.Session
import java.time.DayOfWeek
import java.time.LocalDateTime

class GetInfoSession(
private val sessionGateway: SessionGateway,
) : UseCase<GetInfoSession.GetInfoSessionInput, Session> {
data class GetInfoSessionInput(
val now: LocalDateTime,
)

override fun execute(input: GetInfoSessionInput): Session {
val monday = input.now.getMonday()

return sessionGateway.findByStartTimeBetween(
monday,
monday.plusDays(7)
) ?: throw SessionNotFoundException()
}

private fun LocalDateTime.getMonday() = this.toLocalDate().with(DayOfWeek.MONDAY).atStartOfDay()
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
package com.depromeet.makers.presentation.restapi.controller

import com.depromeet.makers.domain.usecase.CreateNewSession
import com.depromeet.makers.domain.usecase.DeleteSession
import com.depromeet.makers.domain.usecase.UpdateSession
import com.depromeet.makers.domain.usecase.UpdateSessionPlace
import com.depromeet.makers.domain.usecase.GetSessions
import com.depromeet.makers.domain.usecase.*
import com.depromeet.makers.presentation.restapi.dto.request.CreateNewSessionRequest
import com.depromeet.makers.presentation.restapi.dto.request.GetSessionsRequest
import com.depromeet.makers.presentation.restapi.dto.request.UpdateSessionPlaceRequest
import com.depromeet.makers.presentation.restapi.dto.request.UpdateSessionRequest
import com.depromeet.makers.presentation.restapi.dto.request.GetSessionsRequest
import com.depromeet.makers.presentation.restapi.dto.response.CreateNewSessionResponse
import com.depromeet.makers.presentation.restapi.dto.response.UpdateSessionPlaceResponse
import com.depromeet.makers.presentation.restapi.dto.response.UpdateSessionResponse
import com.depromeet.makers.presentation.restapi.dto.response.GetSessionsResponse
import com.depromeet.makers.presentation.restapi.dto.response.*
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*
import java.time.LocalDateTime

@Tag(name = "세션 관련 API", description = "세션의 정보를 관리하는 API")
@RestController
Expand All @@ -36,9 +23,8 @@ class SessionController(
private val updateSession: UpdateSession,
private val updateSessionPlace: UpdateSessionPlace,
private val deleteSession: DeleteSession,


) {
private val getInfoSession: GetInfoSession,
) {
@Operation(summary = "새로운 세션 생성", description = "새로운 세션을 생성합니다.")
@PreAuthorize("hasRole('ORGANIZER')")
@PostMapping
Expand Down Expand Up @@ -79,6 +65,19 @@ class SessionController(
)
}

@Operation(summary = "세션 정보 조회", description = "세션의 정보를 조회합니다.")
@GetMapping("/info")
fun getInfoSession(
): GetSessionResponse {
return GetSessionResponse.fromDomain(
getInfoSession.execute(
GetInfoSession.GetInfoSessionInput(
now = LocalDateTime.now(),
)
)
)
}

@Operation(summary = "세션 정보 수정", description = "세션의 정보를 수정합니다.")
@PreAuthorize("hasRole('ORGANIZER')")
@PutMapping("/{sessionId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.depromeet.makers.presentation.restapi.dto.response

import com.depromeet.makers.domain.model.Place
import com.depromeet.makers.domain.model.Session
import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "세션 조회 응답 DTO")
class GetSessionResponse(
@Schema(description = "세션 ID", example = "01HWPNRE5TS9S7VC99WPETE5KE")
val sessionId: String,

@Schema(description = "기수", example = "15")
val generation: Int,

@Schema(description = "주차", example = "1")
val week: Int,

@Schema(description = "세션 제목", example = "오리엔테이션")
val title: String,

@Schema(description = "세션 설명", example = "세션 설명을 입력해주세요.")
val description: String?,

@Schema(description = "시작 시간", example = "2021-10-01T19:00:00")
val startTime: String,

@Schema(description = "세션 타입", example = "ONLINE")
val sessionType: String,

@Schema(description = "장소", example = "온라인")
val place: PlaceResponse,
) {
companion object {
fun fromDomain(session: Session) = with(session) {
GetSessionResponse(
sessionId = sessionId,
generation = generation,
week = week,
title = title,
description = description,
startTime = startTime.toString(),
sessionType = sessionType.name,
place = place.let { PlaceResponse.fromDomain(it) },
)
}
}

data class PlaceResponse(
@Schema(description = "장소 이름", example = "전북 익산시 부송동 100")
val address: String,

@Schema(description = "위도", example = "35.9418")
val latitude: Double,

@Schema(description = "경도", example = "35.9418")
val longitude: Double,
) {
companion object {
fun fromDomain(place: Place) = with(place) {
PlaceResponse(
address = address,
latitude = latitude,
longitude = longitude,
)
}
}
}
}

0 comments on commit 084c3e6

Please sign in to comment.