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..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 @@ -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,10 @@ private void createBookingAskerRelation(CalcomWebhookInputPayload payload, private void createStatisticsEvent(String eventType, CalcomWebhookInputPayload payload) { 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, - this.getConsultantId(payload.getBookingId()))); + consultant.getId(), tenantId)); 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));