Skip to content

Commit

Permalink
kahluaband#69 Feat: 마이페이지 예약내역 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
woogieon8on committed Nov 9, 2024
1 parent 7feca51 commit be440ed
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((authorize) -> authorize
.requestMatchers( "/api-docs/**", "/swagger-ui/**", "/swagger-ui.html/**", "/v3/api-docs/**", "/swagger-ui/index.html#/**").permitAll()
.requestMatchers("/v1/auth/sign-out/**", "v1/auth/recreate/**","/v1/user/**", "/v1/admin/**").authenticated()
.requestMatchers("v1/reservation/**").hasAnyAuthority("KAHLUA", "ADMIN")
.anyRequest().permitAll())
.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(exceptionFilter, JwtFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import kahlua.KahluaProject.dto.reservation.request.ReservationRequest;
import kahlua.KahluaProject.dto.reservation.response.ReservationListResponse;
import kahlua.KahluaProject.dto.reservation.response.ReservationResponse;
import kahlua.KahluaProject.security.AuthDetails;
import kahlua.KahluaProject.service.ReservationService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.messaging.handler.annotation.*;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -52,4 +54,10 @@ public ApiResponse<ReservationListResponse> getReservationListByDate(@RequestPar

return ApiResponse.onSuccess(reservationService.getByDate(date));
}

@GetMapping("/v1/reservation/check")
public ApiResponse<ReservationListResponse> getReservationList(@AuthenticationPrincipal AuthDetails authDetails) {

return ApiResponse.onSuccess(reservationService.getByUser(authDetails.user()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
public interface ReservationRepository extends JpaRepository<Reservation, Long> {

List<Reservation> findAllByReservationDate(LocalDate date);
List<Reservation> findAllByUser_Id(Long userId);
}
13 changes: 11 additions & 2 deletions src/main/java/kahlua/KahluaProject/service/ReservationService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kahlua.KahluaProject.service;

import jakarta.transaction.Transactional;
import kahlua.KahluaProject.converter.ReservationConverter;
import kahlua.KahluaProject.domain.reservation.Reservation;
import kahlua.KahluaProject.domain.reservation.ReservationStatus;
import kahlua.KahluaProject.domain.user.User;
Expand All @@ -15,7 +14,6 @@

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -66,6 +64,17 @@ public ReservationListResponse getByDate(LocalDate date) {
return new ReservationListResponse(reservationResponseList);
}

public ReservationListResponse getByUser(User user) {

List<Reservation> reservationList = reservationRepository.findAllByUser_Id(user.getId());

List<ReservationResponse> reservationResponseList = reservationList.stream()
.map(reservation -> toReservationResponse(reservation, user.getEmail()))
.collect(Collectors.toList());

return new ReservationListResponse(reservationResponseList);
}

// String to LocalDateTime
private LocalDate toLocalDate(String date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
Expand Down

0 comments on commit be440ed

Please sign in to comment.