From 10d1c09df1c5e22381ee1fba9634aa93255014e1 Mon Sep 17 00:00:00 2001 From: Krzysztof Sobkowiak Date: Thu, 10 Apr 2025 14:03:32 +0200 Subject: [PATCH 1/2] Zmiany w API --- api/openapi.yml | 36 +++++++++---------- .../impl/AppointmentsApiController.java | 9 +++-- .../service/impl/TreatmentsApiController.java | 3 +- .../service/mapper/AppointmentApiMapper.java | 20 ++++------- .../service/mapper/TreatmentApiMapper.java | 16 ++++----- 5 files changed, 35 insertions(+), 49 deletions(-) diff --git a/api/openapi.yml b/api/openapi.yml index 0a50467..e748e46 100644 --- a/api/openapi.yml +++ b/api/openapi.yml @@ -184,16 +184,16 @@ components: type: object properties: id: - type: string # TODO integer - format: uuid # TODO int64 -> Krzysztof - change uuid to integer or something better suited for long for Long id of Entity. Change all uuid and resign from getMostSignificantBits everywhere + type: integer + format: int64 name: type: string duration: type: integer description: Duration of the treatment in minutes specialistId: - type: string - format: uuid + type: integer + format: int64 TreatmentRequest: type: object @@ -203,8 +203,8 @@ components: duration: type: integer specialistId: - type: string - format: uuid + type: integer + format: int64 TreatmentDetails: allOf: @@ -215,8 +215,8 @@ components: type: object properties: id: - type: string - format: uuid + type: integer + format: int64 name: type: string @@ -228,11 +228,11 @@ components: - dateTime properties: clientId: - type: string - format: uuid + type: integer + format: int64 treatmentId: - type: string - format: uuid + type: integer + format: int64 dateTime: type: string format: date-time @@ -241,14 +241,14 @@ components: type: object properties: id: - type: string - format: uuid + type: integer + format: int64 clientId: - type: string - format: uuid + type: integer + format: int64 treatmentId: - type: string - format: uuid + type: integer + format: int64 dateTime: type: string format: date-time diff --git a/src/main/java/com/capgemini/training/appointmentbooking/service/impl/AppointmentsApiController.java b/src/main/java/com/capgemini/training/appointmentbooking/service/impl/AppointmentsApiController.java index 0f70312..555a11c 100644 --- a/src/main/java/com/capgemini/training/appointmentbooking/service/impl/AppointmentsApiController.java +++ b/src/main/java/com/capgemini/training/appointmentbooking/service/impl/AppointmentsApiController.java @@ -13,7 +13,6 @@ import java.util.Date; import java.util.List; import java.util.Optional; -import java.util.UUID; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; @@ -44,8 +43,8 @@ public ResponseEntity> getAppointments( AppointmentCriteria.AppointmentCriteriaBuilder criteria = AppointmentCriteria.builder(); status.ifPresent(t -> criteria.status(AppointmentStatus.valueOf(t))); - clientId.ifPresent(t -> criteria.clientId(UUID.fromString(t).getMostSignificantBits())); - specialistId.ifPresent(t -> criteria.specialistId(UUID.fromString(t).getMostSignificantBits())); // TODO Krzysztof resign from getMostSignificantBits everywhere, instewad of uuid we want integer + clientId.ifPresent(t -> criteria.clientId(Long.valueOf(t))); + specialistId.ifPresent(t -> criteria.specialistId(Long.valueOf(t))); List list = findAppointmentUc.findByCriteria(criteria.build()); List result = @@ -56,7 +55,7 @@ public ResponseEntity> getAppointments( @Override public ResponseEntity updateAppointmentStatus( String appointmentId, @Valid AppointmentStatusUpdate appointmentStatusUpdate) { - Long id = UUID.fromString(appointmentId).getMostSignificantBits(); + Long id = Long.valueOf(appointmentId); AppointmentStatus status = AppointmentStatus.valueOf(appointmentStatusUpdate.getStatus().name()); manageAppointmentUc.updateAppointmentStatus(id, status); @@ -67,7 +66,7 @@ public ResponseEntity updateAppointmentStatus( public ResponseEntity checkAvailability( @NotNull @Valid String specialistId, @NotNull @Valid @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date dateTime) { - Long specialistLongId = UUID.fromString(specialistId).getMostSignificantBits(); + Long specialistLongId = Long.valueOf(specialistId); boolean available = !findAppointmentUc.hasConflictingAppointment(specialistLongId, dateTime.toInstant()); diff --git a/src/main/java/com/capgemini/training/appointmentbooking/service/impl/TreatmentsApiController.java b/src/main/java/com/capgemini/training/appointmentbooking/service/impl/TreatmentsApiController.java index 8210b3a..128d4e0 100644 --- a/src/main/java/com/capgemini/training/appointmentbooking/service/impl/TreatmentsApiController.java +++ b/src/main/java/com/capgemini/training/appointmentbooking/service/impl/TreatmentsApiController.java @@ -12,7 +12,6 @@ import jakarta.validation.Valid; import java.util.List; import java.util.Optional; -import java.util.UUID; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -38,7 +37,7 @@ public ResponseEntity createTreatment(@Valid TreatmentRequest treatme @Override public ResponseEntity getTreatmentDetails(String treatmentId) { - Long id = UUID.fromString(treatmentId).getMostSignificantBits(); + Long id = Long.valueOf(treatmentId); Optional optional = findTreatmentUc.findById(id); return optional diff --git a/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/AppointmentApiMapper.java b/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/AppointmentApiMapper.java index c54642d..cf6d37c 100644 --- a/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/AppointmentApiMapper.java +++ b/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/AppointmentApiMapper.java @@ -1,7 +1,6 @@ package com.capgemini.training.appointmentbooking.service.mapper; import java.util.Optional; -import java.util.UUID; import com.capgemini.training.appointmentbooking.common.to.AppointmentBookingEto; import com.capgemini.training.appointmentbooking.common.to.AppointmentCto; @@ -13,10 +12,10 @@ public class AppointmentApiMapper { public AppointmentBookingEto toBookingEto(AppointmentRequest request) { return AppointmentBookingEto.builder() - .clientId(toLong(request.getClientId())) - .treatmentId(toLong(request.getTreatmentId())) + .clientId(request.getClientId()) + .treatmentId(request.getTreatmentId()) .specialistId( - 0L) // specjalista nie jest częścią requestu – może być wyciągany przez treatment + 0L) // TODO specjalista nie jest częścią requestu – usunąć to po usunięciu specialistId z encji .dateTime(request.getDateTime().toInstant()) .build(); } @@ -25,19 +24,12 @@ public Appointment toApiAppointment(AppointmentCto cto) { AppointmentEto appointmentEto = cto.appointmentEto(); Appointment result = new Appointment(); - result.setId(Optional.of(toUuid(appointmentEto.id()))); - result.setClientId(Optional.of(toUuid(cto.clientEto().id()))); - result.setTreatmentId(Optional.of(toUuid(cto.treatmentCto().treatmentEto().id()))); + result.setId(Optional.of(appointmentEto.id())); + result.setClientId(Optional.of(cto.clientEto().id())); + result.setTreatmentId(Optional.of(cto.treatmentCto().treatmentEto().id())); result.setDateTime(Optional.of(java.util.Date.from(appointmentEto.dateTime()))); result.setStatus(Optional.of(Appointment.StatusEnum.valueOf(appointmentEto.status().name()))); return result; } - private Long toLong(UUID uuid) { - return uuid.getMostSignificantBits(); - } - - private UUID toUuid(Long id) { - return new UUID(id, 0L); - } } diff --git a/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/TreatmentApiMapper.java b/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/TreatmentApiMapper.java index 8ea6c56..95ac56e 100644 --- a/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/TreatmentApiMapper.java +++ b/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/TreatmentApiMapper.java @@ -1,7 +1,6 @@ package com.capgemini.training.appointmentbooking.service.mapper; import java.util.Optional; -import java.util.UUID; import com.capgemini.training.appointmentbooking.common.to.SpecialistEto; import com.capgemini.training.appointmentbooking.common.to.TreatmentCreationTo; @@ -18,7 +17,7 @@ public TreatmentCreationTo toCreationTo(TreatmentRequest request) { return TreatmentCreationTo.builder() .name(request.getName().orElse(null)) .durationMinutes(request.getDuration().orElse(0)) - .specialistId(request.getSpecialistId().map(UUID::getMostSignificantBits).orElse(null)) + .specialistId(request.getSpecialistId().orElse(null)) .description("Default description") .build(); } @@ -28,10 +27,10 @@ public Treatment toApiTreatment(TreatmentCto cto) { SpecialistEto specialist = cto.specialistEto(); Treatment result = new Treatment(); - result.setId(Optional.ofNullable(eto.id()).map(this::toUuid)); + result.setId(Optional.ofNullable(eto.id())); result.setName(Optional.ofNullable(eto.name())); result.setDuration(Optional.of(eto.durationMinutes())); - result.setSpecialistId(Optional.ofNullable(specialist.id()).map(this::toUuid)); + result.setSpecialistId(Optional.ofNullable(specialist.id())); return result; } @@ -40,20 +39,17 @@ public TreatmentDetails toApiTreatmentDetails(TreatmentCto cto) { SpecialistEto specialist = cto.specialistEto(); TreatmentDetails result = new TreatmentDetails(); - result.setId(Optional.ofNullable(eto.id()).map(this::toUuid)); + result.setId(Optional.ofNullable(eto.id())); result.setName(Optional.ofNullable(eto.name())); result.setDuration(Optional.of(eto.durationMinutes())); - result.setSpecialistId(Optional.ofNullable(specialist.id()).map(this::toUuid)); + result.setSpecialistId(Optional.ofNullable(specialist.id())); TreatmentDetailsAllOfSpecialist specialistDto = new TreatmentDetailsAllOfSpecialist(); - specialistDto.setId(Optional.ofNullable(specialist.id()).map(this::toUuid)); + specialistDto.setId(Optional.ofNullable(specialist.id())); specialistDto.setName(Optional.ofNullable(specialist.specialization().name())); result.setSpecialist(Optional.of(specialistDto)); return result; } - private UUID toUuid(Long id) { - return new UUID(id, 0L); - } } From 2f4696637f0a75590d9e071839482a49240b014b Mon Sep 17 00:00:00 2001 From: Piotr Kubicki Date: Thu, 10 Apr 2025 14:29:55 +0200 Subject: [PATCH 2/2] chore: adjust TODO for AppointmentBookingEto#specialistId --- .../service/mapper/AppointmentApiMapper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/AppointmentApiMapper.java b/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/AppointmentApiMapper.java index cf6d37c..edb9230 100644 --- a/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/AppointmentApiMapper.java +++ b/src/main/java/com/capgemini/training/appointmentbooking/service/mapper/AppointmentApiMapper.java @@ -15,7 +15,9 @@ public AppointmentBookingEto toBookingEto(AppointmentRequest request) { .clientId(request.getClientId()) .treatmentId(request.getTreatmentId()) .specialistId( - 0L) // TODO specjalista nie jest częścią requestu – usunąć to po usunięciu specialistId z encji + 0L) // TODO specjalista nie jest częścią requestu – usunąć to po usunięciu specialistId tylko z AppointmentBookingEto, + // bo jedyne użycie AppointmentBookingEto#specialistId jest w findAppointmentUc.hasConflictingAppointment + // gdzie specialistId da się wyciągnąć z treatment .dateTime(request.getDateTime().toInstant()) .build(); }