diff --git a/.github/workflows/dockerImage.yml b/.github/workflows/dockerImage.yml index 7d4f002..1af7995 100644 --- a/.github/workflows/dockerImage.yml +++ b/.github/workflows/dockerImage.yml @@ -35,7 +35,7 @@ jobs: run: mvn -B -Pprod clean package -DskipTests=true # - name: Maven Verify # run: mvn -B -Pprod clean verify -DskipTests=true - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: targetfiles path: target/*.jar @@ -49,7 +49,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Download buildfiles artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: targetfiles - name: Get current time diff --git a/pom.xml b/pom.xml index 1e1e743..030efe4 100644 --- a/pom.xml +++ b/pom.xml @@ -266,6 +266,11 @@ ${easy-random-core.version} test + + org.assertj + assertj-core + test + org.springframework.security spring-security-test diff --git a/src/main/java/com/vi/appointmentservice/api/calcom/repository/BookingRepository.java b/src/main/java/com/vi/appointmentservice/api/calcom/repository/BookingRepository.java index 72e85e4..f01b83b 100644 --- a/src/main/java/com/vi/appointmentservice/api/calcom/repository/BookingRepository.java +++ b/src/main/java/com/vi/appointmentservice/api/calcom/repository/BookingRepository.java @@ -7,40 +7,41 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import org.springframework.stereotype.Service; +import org.springframework.stereotype.Repository; -@Service +@Repository @RequiredArgsConstructor public class BookingRepository { + private static final String USER_ID = "userId"; private @Autowired NamedParameterJdbcTemplate calcomDBNamedParamterTemplate; public List getConsultantActiveBookings(Long userId) { - String QUERY = "SELECT * FROM \"Booking\" AS booking WHERE booking.status != 'cancelled' AND " - + "booking.\"userId\" = :userId AND now() < \"startTime\" order by \"startTime\" ASC"; + String query = "SELECT * FROM \"Booking\" AS booking WHERE booking.status != 'cancelled' AND " + + "booking.\"userId\" = :userId AND now() < (\"startTime\" + INTERVAL '30 minutes') order by \"startTime\" ASC"; SqlParameterSource parameters = new MapSqlParameterSource() - .addValue("userId", userId); + .addValue(USER_ID, userId); return calcomDBNamedParamterTemplate - .query(QUERY, parameters, new CalcomRepositoryBookingMapper()); + .query(query, parameters, new CalcomRepositoryBookingMapper()); } public List getConsultantExpiredBookings(Long userId) { - String QUERY = "SELECT * FROM \"Booking\" AS booking WHERE booking.status != 'cancelled' AND " - + "booking.\"userId\" = :userId AND now() > \"startTime\" order by \"startTime\" DESC"; + String query = "SELECT * FROM \"Booking\" AS booking WHERE booking.status != 'cancelled' AND " + + "booking.\"userId\" = :userId AND now() > (\"startTime\" + INTERVAL '30 minutes') order by \"startTime\" DESC"; SqlParameterSource parameters = new MapSqlParameterSource() - .addValue("userId", userId); + .addValue(USER_ID, userId); return calcomDBNamedParamterTemplate - .query(QUERY, parameters, new CalcomRepositoryBookingMapper()); + .query(query, parameters, new CalcomRepositoryBookingMapper()); } public List getConsultantCancelledBookings(Long userId) { - String QUERY = "SELECT * FROM \"Booking\" AS booking WHERE booking.status = 'cancelled' AND " + String query = "SELECT * FROM \"Booking\" AS booking WHERE booking.status = 'cancelled' AND " + "booking.\"userId\" = :userId order by \"startTime\" DESC"; SqlParameterSource parameters = new MapSqlParameterSource() - .addValue("userId", userId); + .addValue(USER_ID, userId); return calcomDBNamedParamterTemplate - .query(QUERY, parameters, new CalcomRepositoryBookingMapper()); + .query(query, parameters, new CalcomRepositoryBookingMapper()); } public CalcomBooking getBookingById(Long bookingId) { @@ -51,41 +52,41 @@ public CalcomBooking getBookingById(Long bookingId) { } public List getAskerActiveBookings(List bookingIds) { - String QUERY = "SELECT * FROM \"Booking\" AS booking WHERE booking.status != 'cancelled' AND " - + "booking.\"id\" in (:ids) AND now() < \"startTime\" order by \"startTime\" ASC"; + String query = "SELECT * FROM \"Booking\" AS booking WHERE booking.status != 'cancelled' AND " + + "booking.\"id\" in (:ids) AND now() < (\"startTime\" + INTERVAL '30 minutes') order by \"startTime\" ASC"; SqlParameterSource parameters = new MapSqlParameterSource() .addValue("ids", bookingIds); return calcomDBNamedParamterTemplate - .query(QUERY, parameters, new CalcomRepositoryBookingMapper()); + .query(query, parameters, new CalcomRepositoryBookingMapper()); } public Integer getBookingIdByUid(String uid) { - String QUERY = "SELECT \"id\" FROM \"Booking\" AS booking WHERE booking.\"uid\" = :uid LIMIT 1"; + String query = "SELECT \"id\" FROM \"Booking\" AS booking WHERE booking.\"uid\" = :uid LIMIT 1"; SqlParameterSource parameters = new MapSqlParameterSource() .addValue("uid", uid); return calcomDBNamedParamterTemplate - .queryForObject(QUERY, parameters, Integer.class); + .queryForObject(query, parameters, Integer.class); } public void deleteBooking(Long bookingId) { - String QUERY = "DELETE FROM \"Booking\" AS booking WHERE booking.\"id\" = :bookingId"; + String query = "DELETE FROM \"Booking\" AS booking WHERE booking.\"id\" = :bookingId"; SqlParameterSource parameters = new MapSqlParameterSource() .addValue("bookingId", bookingId); - calcomDBNamedParamterTemplate.update(QUERY, parameters); + calcomDBNamedParamterTemplate.update(query, parameters); } public void deleteAttendeeWithoutBooking() { - String QUERY = "DELETE FROM \"Attendee\" AS attendee WHERE attendee.\"bookingId\" IS NULL"; - calcomDBNamedParamterTemplate.update(QUERY, new MapSqlParameterSource()); + String query = "DELETE FROM \"Attendee\" AS attendee WHERE attendee.\"bookingId\" IS NULL"; + calcomDBNamedParamterTemplate.update(query, new MapSqlParameterSource()); } public void updateAttendeeEmail(final List bookingIds, final String email) { - String QUERY = "UPDATE \"Attendee\" SET \"email\"=:email WHERE \"bookingId\" IN (:bookingIds)"; + String query = "UPDATE \"Attendee\" SET \"email\"=:email WHERE \"bookingId\" IN (:bookingIds)"; SqlParameterSource parameters = new MapSqlParameterSource() .addValue("bookingIds", bookingIds) .addValue("email", email); - calcomDBNamedParamterTemplate.update(QUERY, parameters); + calcomDBNamedParamterTemplate.update(query, parameters); } public CalcomBooking getBookingByUid(String bookingUid) { @@ -96,9 +97,9 @@ public CalcomBooking getBookingByUid(String bookingUid) { } public void cancelBooking(String bookingUid) { - String QUERY = "UPDATE \"Booking\" SET status='cancelled' WHERE uid = :bookingUid"; + String query = "UPDATE \"Booking\" SET status='cancelled' WHERE uid = :bookingUid"; SqlParameterSource parameters = new MapSqlParameterSource() .addValue("bookingUid", bookingUid); - calcomDBNamedParamterTemplate.update(QUERY, parameters); + calcomDBNamedParamterTemplate.update(query, parameters); } } diff --git a/src/test/java/com/vi/appointmentservice/api/calcom/service/CalcomLocationsServiceTest.java b/src/test/java/com/vi/appointmentservice/api/calcom/service/CalcomLocationsServiceTest.java index 2bfaf41..238e177 100644 --- a/src/test/java/com/vi/appointmentservice/api/calcom/service/CalcomLocationsServiceTest.java +++ b/src/test/java/com/vi/appointmentservice/api/calcom/service/CalcomLocationsServiceTest.java @@ -1,7 +1,6 @@ package com.vi.appointmentservice.api.calcom.service; -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - +import static org.assertj.core.api.Assertions.assertThat; import com.vi.appointmentservice.api.calcom.model.LocationType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/src/test/java/com/vi/appointmentservice/api/calcom/service/EventTypeMapperTest.java b/src/test/java/com/vi/appointmentservice/api/calcom/service/EventTypeMapperTest.java index 26b2bc1..43ce5cf 100644 --- a/src/test/java/com/vi/appointmentservice/api/calcom/service/EventTypeMapperTest.java +++ b/src/test/java/com/vi/appointmentservice/api/calcom/service/EventTypeMapperTest.java @@ -1,7 +1,6 @@ package com.vi.appointmentservice.api.calcom.service; -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - +import static org.assertj.core.api.Assertions.assertThat; import com.vi.appointmentservice.api.calcom.model.CalcomEventType; import com.vi.appointmentservice.api.model.EventTypeDTO; import org.junit.jupiter.api.Test;