Skip to content

Commit

Permalink
Merge pull request #14 from IhorTrokhymchuk/fix-dev
Browse files Browse the repository at this point in the history
Fixed get bookings by check dates query
  • Loading branch information
IhorTrokhymchuk authored May 13, 2024
2 parents 0092746 + ae63c99 commit 7fc24c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public interface BookingRepository extends JpaRepository<Booking, Long> {
+ "WHERE b.accommodation.id = :accommodationId "
+ "AND NOT b.status.name = 'CANCELED' "
+ "AND NOT b.status.name = 'EXPIRED' "
+ "AND (:checkInDate BETWEEN b.checkDates.checkInDate AND b.checkDates.checkOutDate "
+ "OR :checkOutDate BETWEEN b.checkDates.checkInDate AND b.checkDates.checkOutDate)")
+ "AND ("
+ "(:checkInDate BETWEEN b.checkDates.checkInDate AND b.checkDates.checkOutDate "
+ "OR :checkOutDate BETWEEN b.checkDates.checkInDate AND b.checkDates.checkOutDate) "
+ "OR (b.checkDates.checkInDate BETWEEN :checkInDate AND :checkOutDate "
+ "OR b.checkDates.checkOutDate BETWEEN :checkInDate AND :checkOutDate))")
Long isDatesAvailableForAccommodation(@Param("accommodationId") Long accommodationId,
@Param("checkInDate") LocalDate checkInDate,
@Param("checkOutDate") LocalDate checkOutDate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.example.bookingappliation.controller;

import static org.example.bookingappliation.testutil.BookingControllerDtoUtil.getBookingPatchRequestDto;
import static org.example.bookingappliation.testutil.BookingControllerDtoUtil.getFirstBookingDtoFromDb;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.fasterxml.jackson.core.type.TypeReference;
Expand All @@ -19,7 +17,6 @@
import java.util.List;
import javax.sql.DataSource;
import lombok.SneakyThrows;
import org.example.bookingappliation.dto.bookings.request.BookingPatchRequestDto;
import org.example.bookingappliation.dto.bookings.request.BookingRequestDto;
import org.example.bookingappliation.dto.bookings.responce.BookingDto;
import org.example.bookingappliation.dto.bookingstatuses.response.BookingStatusDto;
Expand Down Expand Up @@ -230,32 +227,6 @@ void cancelBookingById_cancelBookingByIdWithValidData_isOk() throws Exception {
assertEquals(firstBookingDtoFromDb, resultDto);
}

@Test
@WithMockUser(username = "[email protected]", authorities = {"CUSTOMER"})
@DisplayName("Update booking by id with valid data")
void update_updateBookingByIdWithValidData_isOk() throws Exception {
Long id = 1L;
BookingPatchRequestDto bookingPatchRequestDto = getBookingPatchRequestDto();
String jsonRequest = objectMapper.writeValueAsString(bookingPatchRequestDto);

BookingDto firstBookingDtoFromDb = getFirstBookingDtoFromDb();
firstBookingDtoFromDb.getCheckDates().setCheckInDate(
bookingPatchRequestDto.getCheckDates().getCheckInDate());
firstBookingDtoFromDb.getCheckDates().setCheckOutDate(
bookingPatchRequestDto.getCheckDates().getCheckOutDate());

MvcResult result = mockMvc.perform(put(BASE_URL + SLASH + id)
.content(jsonRequest)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();

BookingDto resultDto = objectMapper.readValue(
result.getResponse().getContentAsString(), BookingDto.class);
assertNotNull(resultDto);
assertEquals(firstBookingDtoFromDb, resultDto);
}

@AfterEach
void tearDown(@Autowired DataSource dataSource) {
teardown(dataSource);
Expand Down

0 comments on commit 7fc24c3

Please sign in to comment.