Skip to content

Commit

Permalink
Merge pull request outman337#12 from outman337/jiaying
Browse files Browse the repository at this point in the history
add new API on May 19
  • Loading branch information
joyceZ916 authored May 20, 2023
2 parents 9bc0e72 + f6e930e commit 75b9a49
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public List<AmenityVo> listByToday(Principal principal) {
return reservationService.listByToday(user);
}

@GetMapping(value = "/reservation/date")
public List<ReservationVo> listByDate(
@RequestParam(value = "date") String date,
@RequestParam(value = "amenity_id") String amenity_id,
Principal principal
) {
User user = new User.Builder().setUsername(principal.getName()).build();
return reservationService.listByDate(date, user, amenity_id);
}

//2. get reservation by id
@GetMapping(value = "/reservation/id")
public Reservation getReservationId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public interface ReservationRepository extends JpaRepository<Reservation, Long>
@Query(value = "SELECT res FROM Reservation res WHERE res.date = ?1 AND res.start_time = ?2 AND res.end_time = ?3 and res.amenity_id=?4")
Reservation findReservationByDateAndAmenityStarttimeAndEndTime(String date, String startTime, String endTime, String amenityid);



@Query(value = "SELECT authority FROM authority WHERE username = ?1", nativeQuery = true)
String getAuth(String username);

@Query(value = "SELECT res FROM Reservation res WHERE res.date = ?1 and res.amenity_id=?2")
List<Reservation> findByDate(String date, String amenity_id);
}

Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ public List<ReservationVo> listByAll(User username) {
reservationVo.setStartTime(reservation.getStartTime());
reservationVo.setEndTime(reservation.getEndTime());
reservationVo.setReservation_name(reservation.getReservationName());
// date转为 yyyy-MM-dee
reservationVo.setDate(reservation.getDate());
voList.add(reservationVo);
}
return voList;
}

public List<ReservationVo> listByDate(String date, User user, String amenity_id) {
List<ReservationVo> voList = new ArrayList<>();
List<Reservation> byRequester = reservationRepository.findByDate(date,amenity_id);
for (Reservation reservation : byRequester) {
ReservationVo reservationVo = new ReservationVo();
reservationVo.setReservation_id(reservation.getReservationID());
reservationVo.setStartTime(reservation.getStartTime());
reservationVo.setEndTime(reservation.getEndTime());
reservationVo.setReservation_name(reservation.getReservationName());
// date转为 yyyy-MM-dee
reservationVo.setDate(reservation.getDate());
voList.add(reservationVo);
Expand Down

0 comments on commit 75b9a49

Please sign in to comment.