forked from kahluaband/Homepage_BE_SpringBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f48da62
commit f0ea027
Showing
7 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/kahlua/KahluaProject/controller/ReservationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package kahlua.KahluaProject.controller; | ||
|
||
import kahlua.KahluaProject.dto.reservation.request.ReservationProceedRequest; | ||
import kahlua.KahluaProject.dto.reservation.request.ReservationRequest; | ||
import kahlua.KahluaProject.dto.reservation.response.ReservationResponse; | ||
import kahlua.KahluaProject.service.ReservationService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.messaging.handler.annotation.*; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.Map; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ReservationController { | ||
|
||
private final ReservationService reservationService; | ||
|
||
// 예약 시간 선택한 사람에게 우선권 부여 | ||
@MessageMapping("/reserve.proceed/{date}") | ||
@SendTo("/topic/public/{date}") | ||
public ReservationResponse proceed(@DestinationVariable String reservationDate, | ||
@Header("simpSessionAttributes") Map<String, Object> simpSessionAttributes, | ||
@Payload ReservationProceedRequest reservationProceedRequest) { | ||
|
||
return reservationService.proceed(reservationProceedRequest, reservationDate, simpSessionAttributes); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/kahlua/KahluaProject/converter/ReservationConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package kahlua.KahluaProject.converter; | ||
|
||
import kahlua.KahluaProject.domain.reservation.Reservation; | ||
import kahlua.KahluaProject.dto.reservation.request.ReservationRequest; | ||
import kahlua.KahluaProject.dto.reservation.response.ReservationResponse; | ||
|
||
public class ReservationConverter { | ||
|
||
public static ReservationResponse toReservationResponse(Reservation reservation, String email) { | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/kahlua/KahluaProject/dto/reservation/request/ReservationProceedRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package kahlua.KahluaProject.dto.reservation.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import java.time.LocalTime; | ||
|
||
public record ReservationProceedRequest( | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") | ||
LocalTime startTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") | ||
LocalTime endTime | ||
) { | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/kahlua/KahluaProject/dto/reservation/request/ReservationRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package kahlua.KahluaProject.dto.reservation.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import kahlua.KahluaProject.domain.reservation.ReservationType; | ||
|
||
import java.time.LocalTime; | ||
|
||
public record ReservationRequest( | ||
ReservationType type, | ||
String clubroomUsername, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") | ||
LocalTime startTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") | ||
LocalTime endTime | ||
) { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/kahlua/KahluaProject/dto/reservation/response/ReservationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package kahlua.KahluaProject.dto.reservation.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import kahlua.KahluaProject.domain.reservation.ReservationStatus; | ||
import kahlua.KahluaProject.domain.reservation.ReservationType; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
|
||
@Builder | ||
public record ReservationResponse( | ||
Long reservationId, | ||
String email, | ||
ReservationType type, | ||
String clubroomUsername, | ||
|
||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
LocalDate reservationDate, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") | ||
LocalTime startTime, | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") | ||
LocalTime endTime, | ||
|
||
ReservationStatus status | ||
) { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/kahlua/KahluaProject/repository/ReservationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kahlua.KahluaProject.repository; | ||
|
||
import kahlua.KahluaProject.domain.reservation.Reservation; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReservationRepository extends JpaRepository<Reservation, Long> { | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/kahlua/KahluaProject/service/ReservationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package kahlua.KahluaProject.service; | ||
|
||
import kahlua.KahluaProject.converter.ReservationConverter; | ||
import kahlua.KahluaProject.domain.reservation.Reservation; | ||
import kahlua.KahluaProject.domain.reservation.ReservationStatus; | ||
import kahlua.KahluaProject.dto.reservation.request.ReservationProceedRequest; | ||
import kahlua.KahluaProject.dto.reservation.request.ReservationRequest; | ||
import kahlua.KahluaProject.dto.reservation.response.ReservationResponse; | ||
import kahlua.KahluaProject.repository.ReservationRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReservationService { | ||
|
||
private final ReservationRepository reservationRepository; | ||
|
||
public ReservationResponse proceed(ReservationProceedRequest reservationProceedRequest, String reservationDate, Map<String, Object> header) { | ||
|
||
String email = getValueFromHeader(header, "email"); | ||
|
||
return ReservationResponse.builder() | ||
.email(email) | ||
.reservationDate(toLocalDate(reservationDate)) | ||
.startTime(reservationProceedRequest.startTime()) | ||
.endTime(reservationProceedRequest.endTime()) | ||
.status(ReservationStatus.PROCEEDING) | ||
.build(); | ||
} | ||
|
||
// String to LocalDateTime | ||
private LocalDate toLocalDate(String date) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
return LocalDate.parse(date, formatter); | ||
} | ||
|
||
private ReservationResponse toReservationResponse(Reservation reservation, Map<String, Object> header) { | ||
String email = getValueFromHeader(header, "email"); | ||
|
||
return ReservationConverter.toReservationResponse(reservation, email); | ||
} | ||
|
||
private String getValueFromHeader(Map<String, Object> header, String key) { | ||
return (String)header.get(key); | ||
} | ||
|
||
} |