Skip to content

Commit

Permalink
Merge pull request #117 from Onlineberatung/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tkuzynow authored Sep 18, 2023
2 parents c2ce715 + ff30809 commit 326a2cf
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 4 additions & 0 deletions services/statisticsservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ components:
type: integer
adviceSeekerId:
type: string
tenantId:
type: integer
format: int64
description: The id of the tenant

BookingRescheduledStatisticsEventMessage:
type: object
Expand Down
11 changes: 11 additions & 0 deletions services/useradminservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> 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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -58,7 +60,8 @@ public Optional<String> 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));
Expand Down

0 comments on commit 326a2cf

Please sign in to comment.