Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change conditions for expired and active bookings #127

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dockerImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@
<version>${easy-random-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CalcomBooking> 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<CalcomBooking> 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<CalcomBooking> 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) {
Expand All @@ -51,41 +52,41 @@ public CalcomBooking getBookingById(Long bookingId) {
}

public List<CalcomBooking> getAskerActiveBookings(List<Long> 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<Long> 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) {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading