From 7aba869a395c03f70634689704acc2bd77913878 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Thu, 14 Sep 2023 17:17:02 +0200 Subject: [PATCH 1/2] fix: pass tenantId for booking created statistics --- services/statisticsservice.yaml | 4 ++++ services/useradminservice.yaml | 11 +++++++++++ .../calcom/service/CalcomWebhookHandlerService.java | 12 ++++++++---- .../event/BookingCreatedStatisticsEvent.java | 7 +++++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/services/statisticsservice.yaml b/services/statisticsservice.yaml index a72dd82..618d961 100644 --- a/services/statisticsservice.yaml +++ b/services/statisticsservice.yaml @@ -200,6 +200,10 @@ components: type: integer adviceSeekerId: type: string + tenantId: + type: integer + format: int64 + description: The id of the tenant BookingRescheduledStatisticsEventMessage: type: object diff --git a/services/useradminservice.yaml b/services/useradminservice.yaml index cc0c4df..4e40711 100644 --- a/services/useradminservice.yaml +++ b/services/useradminservice.yaml @@ -716,6 +716,17 @@ components: type: array items: $ref: './../services/agencyadminservice.yaml#/components/schemas/AgencyAdminResponseDTO' + isGroupchatConsultant: + $ref: '#/components/schemas/IsGroupchatConsultant' + tenantId: + type: integer + tenantName: + type: string + + IsGroupchatConsultant: + type: boolean + example: true + AskerResponseDTO: type: object diff --git a/src/main/java/com/vi/appointmentservice/api/calcom/service/CalcomWebhookHandlerService.java b/src/main/java/com/vi/appointmentservice/api/calcom/service/CalcomWebhookHandlerService.java index 1b9977e..4722a33 100644 --- a/src/main/java/com/vi/appointmentservice/api/calcom/service/CalcomWebhookHandlerService.java +++ b/src/main/java/com/vi/appointmentservice/api/calcom/service/CalcomWebhookHandlerService.java @@ -20,6 +20,7 @@ import com.vi.appointmentservice.model.CalcomUserToConsultant; import com.vi.appointmentservice.repository.CalcomBookingToAskerRepository; import com.vi.appointmentservice.repository.UserToConsultantRepository; +import com.vi.appointmentservice.useradminservice.generated.web.model.ConsultantDTO; import com.vi.appointmentservice.userservice.generated.web.model.EnquiryAppointmentDTO; import java.util.Optional; import java.util.UUID; @@ -118,15 +119,17 @@ private EnquiryAppointmentDTO getEnquiryAppointmentDTO(CalcomWebhookInputPayload } private String getConsultantId(Integer bookingId) { + return getConsultantByBookingId(bookingId).getId(); + } + + private ConsultantDTO getConsultantByBookingId(Integer bookingId) { CalcomBooking booking = calComBookingService.getBookingById(Long.valueOf(bookingId)); Optional calcomUserToConsultant = this.userToConsultantRepository .findByCalComUserId( Long.valueOf(booking.getUserId())); if (calcomUserToConsultant.isPresent()) { String consultantId = calcomUserToConsultant.get().getConsultantId(); - com.vi.appointmentservice.useradminservice.generated.web.model.ConsultantDTO consultant = null; - consultant = this.adminUserService.getConsultantById(consultantId); - return consultant.getId(); + return this.adminUserService.getConsultantById(consultantId); } else { throw new InternalServerErrorException( "Could not find calcomUserToConsultant for bookingId " + bookingId); @@ -165,8 +168,9 @@ private void createBookingAskerRelation(CalcomWebhookInputPayload payload, private void createStatisticsEvent(String eventType, CalcomWebhookInputPayload payload) { switch (eventType) { case "BOOKING_CREATED": + var consultant = this.getConsultantByBookingId(payload.getBookingId()); statisticsService.fireEvent(new BookingCreatedStatisticsEvent(payload, - this.getConsultantId(payload.getBookingId()))); + consultant.getId(), Long.valueOf(consultant.getTenantId()))); break; case "BOOKING_RESCHEDULED": statisticsService.fireEvent(new BookingRescheduledStatisticsEvent(payload, diff --git a/src/main/java/com/vi/appointmentservice/api/service/statistics/event/BookingCreatedStatisticsEvent.java b/src/main/java/com/vi/appointmentservice/api/service/statistics/event/BookingCreatedStatisticsEvent.java index 162cae8..ed56948 100644 --- a/src/main/java/com/vi/appointmentservice/api/service/statistics/event/BookingCreatedStatisticsEvent.java +++ b/src/main/java/com/vi/appointmentservice/api/service/statistics/event/BookingCreatedStatisticsEvent.java @@ -23,10 +23,12 @@ public class BookingCreatedStatisticsEvent implements StatisticsEvent { private static final EventType EVENT_TYPE = EventType.BOOKING_CREATED; private final CalcomWebhookInputPayload payload; private final String consultantId; + private final Long tenantId; - public BookingCreatedStatisticsEvent(CalcomWebhookInputPayload payload, String consultantId){ + public BookingCreatedStatisticsEvent(CalcomWebhookInputPayload payload, String consultantId, Long tenantId){ this.payload = payload; this.consultantId = consultantId; + this.tenantId = tenantId; OBJECT_MAPPER.registerModule(new JavaTimeModule()); OBJECT_MAPPER.registerModule(buildSimpleModule()); } @@ -58,7 +60,8 @@ public Optional getPayload() { .endTime(toIsoTime(payload.getEndTime().toLocalDateTime())) .uid(payload.getUid()) .bookingId(payload.getBookingId()) - .adviceSeekerId(payload.getMetadata().getUser()); + .adviceSeekerId(payload.getMetadata().getUser()) + .tenantId(tenantId); try { return Optional.of(OBJECT_MAPPER.writeValueAsString(bookingCreatedStatisticsEventMessage)); From 16d92e432bccbe5da25d94dbea46d059ba1aed65 Mon Sep 17 00:00:00 2001 From: tkuzynow Date: Fri, 15 Sep 2023 09:23:05 +0200 Subject: [PATCH 2/2] fix: pass tenantId for booking created statistics --- .../api/calcom/service/CalcomWebhookHandlerService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/vi/appointmentservice/api/calcom/service/CalcomWebhookHandlerService.java b/src/main/java/com/vi/appointmentservice/api/calcom/service/CalcomWebhookHandlerService.java index 4722a33..daa970a 100644 --- a/src/main/java/com/vi/appointmentservice/api/calcom/service/CalcomWebhookHandlerService.java +++ b/src/main/java/com/vi/appointmentservice/api/calcom/service/CalcomWebhookHandlerService.java @@ -169,8 +169,9 @@ private void createStatisticsEvent(String eventType, CalcomWebhookInputPayload p switch (eventType) { case "BOOKING_CREATED": var consultant = this.getConsultantByBookingId(payload.getBookingId()); + Long tenantId = consultant.getTenantId() != null ? consultant.getTenantId().longValue() : null; statisticsService.fireEvent(new BookingCreatedStatisticsEvent(payload, - consultant.getId(), Long.valueOf(consultant.getTenantId()))); + consultant.getId(), tenantId)); break; case "BOOKING_RESCHEDULED": statisticsService.fireEvent(new BookingRescheduledStatisticsEvent(payload,