Skip to content

Commit

Permalink
Video link added to online meeting
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanalicic committed Sep 20, 2022
1 parent 3a0099d commit d42150f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/appointmentservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ components:
description:
type: string
maxLength: 300
consultantEmail:
type: string
maxLength: 300
datetime:
type: string
format: date-time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@

import de.caritas.cob.userservice.api.adapters.web.dto.Appointment;
import de.caritas.cob.userservice.api.adapters.web.dto.AppointmentStatus;
import de.caritas.cob.userservice.api.config.auth.UserRole;
import de.caritas.cob.userservice.api.exception.httpresponses.BadRequestException;
import de.caritas.cob.userservice.api.helper.AuthenticatedUser;
import de.caritas.cob.userservice.api.model.Consultant;
import de.caritas.cob.userservice.api.port.out.ConsultantRepository;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AppointmentDtoMapper {

private final ConsultantRepository consultantRepository;

public Map<String, Object> mapOf(Appointment appointment, AuthenticatedUser authenticatedUser) {
var appointmentMap = new HashMap<String, Object>();
if (nonNull(appointment.getId())) {
Expand All @@ -22,7 +31,22 @@ public Map<String, Object> mapOf(Appointment appointment, AuthenticatedUser auth
appointmentMap.put("description", appointment.getDescription());
appointmentMap.put("datetime", appointment.getDatetime().toString());
appointmentMap.put("status", appointment.getStatus().getValue());
appointmentMap.put("consultantId", authenticatedUser.getUserId());

if (authenticatedUser.getRoles().contains(UserRole.CONSULTANT.getValue())
&& appointment.getConsultantEmail() == null) {
appointmentMap.put("consultantId", authenticatedUser.getUserId());
} else if (authenticatedUser.getRoles().contains(UserRole.TECHNICAL.getValue())
&& appointment.getConsultantEmail() != null) {
Optional<Consultant> consultant = consultantRepository
.findByEmailAndDeleteDateIsNull(appointment.getConsultantEmail());
if (!consultant.isPresent()) {
throw new BadRequestException(
"Consultant doesn't exist for give email " + appointment.getConsultantEmail());
}
appointmentMap.put("consultantId", consultant.get().getId());
} else {
throw new BadRequestException("Can not create appointment for given request.");
}

return appointmentMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ protected void configure(HttpSecurity http) throws Exception {
"/users/sessions/{sessionId:[0-9]+}/archive",
"/users/sessions/{sessionId:[0-9]+}",
"/appointments")
.hasAuthority(CONSULTANT_DEFAULT)
.hasAnyAuthority(CONSULTANT_DEFAULT, TECHNICAL_DEFAULT)
.antMatchers(HttpMethod.PUT, APPOINTMENTS_APPOINTMENT_ID + UUID_PATTERN + "}")
.hasAuthority(CONSULTANT_DEFAULT)
.antMatchers(HttpMethod.DELETE, APPOINTMENTS_APPOINTMENT_ID + UUID_PATTERN + "}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,31 @@ void getAppointmentsShouldReturnOk() throws Exception {
void postAppointmentShouldReturnCreated() throws Exception {
givenAValidAppointmentDto(null, AppointmentStatus.CREATED);
givenAValidConsultant(true);
appointment.setConsultantEmail(null);
mockMvc
.perform(
post("/appointments")
.cookie(CSRF_COOKIE)
.header(CSRF_HEADER, CSRF_VALUE)
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(appointment)))
.andExpect(status().isCreated())
.andExpect(jsonPath("id", is(notNullValue())))
.andExpect(jsonPath("description", is(appointment.getDescription())))
.andExpect(jsonPath("datetime", is(appointment.getDatetime().toString())))
.andExpect(jsonPath("status", is(appointment.getStatus().getValue())));

assertEquals(1, appointmentRepository.count());
}

@Test
@WithMockUser(authorities = AuthorityValue.TECHNICAL_DEFAULT)
void postAppointmentFromTechnicalRoleContextShouldReturnCreated() throws Exception {
givenAValidAppointmentDto(null, AppointmentStatus.CREATED);
consultant = consultantRepository.findAll().iterator().next();
when(authenticatedUser.getRoles()).thenReturn(Set.of(UserRole.TECHNICAL.getValue()));
appointment.setConsultantEmail("[email protected]");
mockMvc
.perform(
post("/appointments")
Expand Down

0 comments on commit d42150f

Please sign in to comment.