Skip to content

Commit

Permalink
VIC-1759: See appointment notes in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanalicic committed Nov 15, 2022
1 parent 830e02f commit 92096d9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 70 deletions.
18 changes: 0 additions & 18 deletions api/appointmentservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,29 +221,11 @@ components:
EnquiryAppointmentDTO:
type: object
required:
- title
- userName
- counselorEmail
- date
properties:
title:
type: string
example: Intro appointment between counselor and advice seeker
userName:
type: string
example: adviceSeeker1
counselorEmail:
type: string
example: [email protected]
date:
type: string
example: Fri Sep 30 18:31:00 GMT+04:00 2022
duration:
type: string
example: 30
note:
type: string
example: some note
language:
$ref: '#/components/schemas/LanguageCode'
t:
Expand Down
2 changes: 1 addition & 1 deletion services/messageservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ components:
- "USER_MUTED"
- "USER_UNMUTED"
- "E2EE_ACTIVATED"
- "APPOINTMENT_SET"
- "INITIAL_APPOINTMENT_DEFINED"

UserDTO:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import de.caritas.cob.userservice.api.facade.CreateEnquiryMessageFacade;
import de.caritas.cob.userservice.api.facade.assignsession.AssignEnquiryFacade;
import de.caritas.cob.userservice.api.helper.AuthenticatedUser;
import de.caritas.cob.userservice.api.model.AppointmentData;
import de.caritas.cob.userservice.api.model.Consultant;
import de.caritas.cob.userservice.api.model.EnquiryData;
import de.caritas.cob.userservice.api.port.in.Organizing;
Expand Down Expand Up @@ -155,15 +154,6 @@ public ResponseEntity<CreateEnquiryMessageResponseDTO> createEnquiryAppointment(
var user = this.userAccountProvider.retrieveValidatedUser();
var rocketChatCredentials =
RocketChatCredentials.builder().rocketChatToken(rcToken).rocketChatUserId(rcUserId).build();

AppointmentData appointmentData =
new AppointmentData(
enquiryAppointmentDTO.getTitle(),
enquiryAppointmentDTO.getUserName(),
enquiryAppointmentDTO.getCounselorEmail(),
enquiryAppointmentDTO.getDate(),
enquiryAppointmentDTO.getDuration(),
enquiryAppointmentDTO.getNote());
var enquiryData =
new EnquiryData(
user,
Expand All @@ -173,7 +163,7 @@ public ResponseEntity<CreateEnquiryMessageResponseDTO> createEnquiryAppointment(
rocketChatCredentials,
enquiryAppointmentDTO.getT(),
enquiryAppointmentDTO.getOrg(),
appointmentData);
enquiryAppointmentDTO.getCounselorEmail());

var response = createEnquiryMessageFacade.createEnquiryMessage(enquiryData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public CreateEnquiryMessageResponseDTO createEnquiryMessage(EnquiryData enquiryD
consultantAgency
.getConsultant()
.getEmail()
.equals(enquiryData.getAppointmentData().getCounselor()))
.equals(enquiryData.getConsultantEmail()))
.collect(Collectors.toList());
} else {
agencyList = consultantAgencyService.findConsultantsByAgencyId(session.getAgencyId());
Expand All @@ -125,9 +125,13 @@ public CreateEnquiryMessageResponseDTO createEnquiryMessage(EnquiryData enquiryD
enquiryData.getUser(),
enquiryData.getRocketChatCredentials(),
createEnquiryExceptionInformation);
MessageResponseDTO messageResponse = null;
MessageResponseDTO messageResponse;

if (!isAppointmentEnquiryMessage(enquiryData)) {
if (isAppointmentEnquiryMessage(enquiryData)) {
messageResponse =
messageServiceProvider.assignUserToRocketChatGroup(
rcGroupId, createEnquiryExceptionInformation);
} else {
var rocketChatData =
new RocketChatData(
enquiryData.getMessage(),
Expand All @@ -139,6 +143,7 @@ public CreateEnquiryMessageResponseDTO createEnquiryMessage(EnquiryData enquiryD
messageServiceProvider.postEnquiryMessage(
rocketChatData, createEnquiryExceptionInformation);
}

messageServiceProvider.postWelcomeMessageIfConfigured(
rcGroupId,
enquiryData.getUser(),
Expand Down Expand Up @@ -168,7 +173,7 @@ public CreateEnquiryMessageResponseDTO createEnquiryMessage(EnquiryData enquiryD
return new CreateEnquiryMessageResponseDTO()
.rcGroupId(rcGroupId)
.sessionId(enquiryData.getSessionId())
.t(messageResponse != null ? messageResponse.getT() : "");
.t(messageResponse.getT());

} catch (CreateEnquiryException exception) {
doRollback(exception.getExceptionInformation(), enquiryData.getRocketChatCredentials());
Expand All @@ -178,7 +183,7 @@ public CreateEnquiryMessageResponseDTO createEnquiryMessage(EnquiryData enquiryD
}

private boolean isAppointmentEnquiryMessage(EnquiryData enquiryData) {
return enquiryData.getAppointmentData() != null;
return enquiryData.getConsultantEmail() != null;
}

private void checkIfKeycloakAndRocketChatUsernamesMatch(String rcUserId, User user) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public class EnquiryData {
private final RocketChatCredentials rocketChatCredentials;
private String type;
private String org;
private AppointmentData appointmentData;
private String consultantEmail;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import static org.apache.commons.lang3.BooleanUtils.isFalse;
import static org.apache.commons.lang3.BooleanUtils.isTrue;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.caritas.cob.userservice.api.adapters.rocketchat.RocketChatCredentialsProvider;
import de.caritas.cob.userservice.api.config.apiclient.MessageServiceApiControllerFactory;
import de.caritas.cob.userservice.api.container.CreateEnquiryExceptionInformation;
Expand All @@ -14,7 +12,6 @@
import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatPostWelcomeMessageException;
import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatUserNotInitializedException;
import de.caritas.cob.userservice.api.helper.UsernameTranscoder;
import de.caritas.cob.userservice.api.model.AppointmentData;
import de.caritas.cob.userservice.api.model.User;
import de.caritas.cob.userservice.api.service.httpheader.SecurityHeaderSupplier;
import de.caritas.cob.userservice.api.service.httpheader.TenantHeaderSupplier;
Expand Down Expand Up @@ -152,22 +149,16 @@ public void postFurtherStepsOrSaveSessionDataMessageIfConfigured(
}
}

public MessageResponseDTO postSendAppointmentBookedMessage(
String rcGroupId,
CreateEnquiryExceptionInformation exceptionInformation,
AppointmentData appointmentData)
public MessageResponseDTO assignUserToRocketChatGroup(
String rcGroupId, CreateEnquiryExceptionInformation exceptionInformation)
throws RocketChatPostFurtherStepsMessageException {
MessageControllerApi controllerApi = messageServiceApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
try {
ObjectMapper mapper = new ObjectMapper();
return controllerApi.saveAliasMessageWithContent(
rcGroupId,
new AliasMessageDTO()
.messageType(MessageType.APPOINTMENT_SET)
.content(mapper.writeValueAsString(appointmentData)));
rcGroupId, new AliasMessageDTO().messageType(MessageType.INITIAL_APPOINTMENT_DEFINED));

} catch (RestClientException | JsonProcessingException exception) {
} catch (RestClientException exception) {
throw new RocketChatPostFurtherStepsMessageException(
String.format(
"Could not post further steps message in Rocket.Chat group with id %s", rcGroupId),
Expand Down

0 comments on commit 92096d9

Please sign in to comment.