Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.group4.ticketingservice.dto.EventCreateRequest
import com.group4.ticketingservice.dto.EventResponse
import com.group4.ticketingservice.entity.Event
import com.group4.ticketingservice.service.EventService
import com.group4.ticketingservice.utils.exception.CustomException
import com.group4.ticketingservice.utils.exception.ErrorCodes
import io.swagger.v3.oas.annotations.Hidden
import jakarta.servlet.http.HttpServletRequest
import jakarta.validation.Valid
Expand All @@ -26,6 +28,13 @@ import java.time.OffsetDateTime
class EventController @Autowired constructor(
val eventService: EventService
) {
companion object {
const val DESCENDING = "desc"
const val ASCENDING = "asc"
const val SORT_BY_DEADLINE = "deadline"
const val SORT_BY_START_DATE = "startDate"
const val SORT_BY_CREATED_AT = "createdAt"
}

// TimeE2ETest를 위한 임시 EndPoint입니다.
@Hidden
Expand Down Expand Up @@ -82,11 +91,28 @@ class EventController @Autowired constructor(
@GetMapping
fun getEvents(
request: HttpServletRequest,
@RequestParam sort: String?,
@RequestParam sort: String,
@RequestParam id: Int?,
@RequestParam time: OffsetDateTime?
): ResponseEntity<Page<Event>> {
val page = eventService.getEvents(sort, id, time)
val sortProperties = sort.split(",").toTypedArray()

val fieldName = sortProperties.getOrNull(0)
val direction = sortProperties.getOrNull(1)

when (Pair(fieldName, direction)) {
Pair(SORT_BY_DEADLINE, null),
Pair(SORT_BY_START_DATE, null),
Pair(SORT_BY_CREATED_AT, null),
Pair(SORT_BY_DEADLINE, ASCENDING),
Pair(SORT_BY_START_DATE, ASCENDING),
Pair(SORT_BY_CREATED_AT, DESCENDING) -> {
// Valid request
}
else -> throw CustomException(ErrorCodes.INVALID_SORT_FORMAT)
}

val page = eventService.getEvents(fieldName!!, id, time)

val headers = HttpHeaders()
headers.set("Content-Location", request.requestURI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ class EventService(
return eventRepository.findById(id).orElse(null)
}

fun getEvents(sort: String?, id: Int?, time: OffsetDateTime?): Page<Event> {
// val specification = EventSpecifications.withName(name)
// val lastAccessId=13
// val lastAccessTime= OffsetDateTime.of(2024,9,6,0,0,0,0, ZoneOffset.UTC)
fun getEvents(sort: String, id: Int?, time: OffsetDateTime?): Page<Event> {
return PageImpl(eventRepositorySupport.getEvent(sort, id, time))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum class ErrorCodes(val status: HttpStatus, val message: String, val errorCode
VALIDATION_FAILED(HttpStatus.BAD_REQUEST, "유효성 검증에 실패하였습니다.", 10001),
MESSAGE_NOT_READABLE(HttpStatus.BAD_REQUEST, "올바른 형식의 요청이 아닙니다", 10002),
DATE_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "예약 가능한 시간이 아닙니다.", 10003),
INVALID_SORT_FORMAT(HttpStatus.BAD_REQUEST, "지원하는 정렬 형식이 아닙니다.", 10004),

// 401 Unauthorized
LOGIN_FAIL(HttpStatus.UNAUTHORIZED, "로그인에 실패했습니다", 20000),
Expand Down