Skip to content

Commit 10d1c09

Browse files
committed
Zmiany w API
1 parent 8391313 commit 10d1c09

File tree

5 files changed

+35
-49
lines changed

5 files changed

+35
-49
lines changed

api/openapi.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,16 @@ components:
184184
type: object
185185
properties:
186186
id:
187-
type: string # TODO integer
188-
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
187+
type: integer
188+
format: int64
189189
name:
190190
type: string
191191
duration:
192192
type: integer
193193
description: Duration of the treatment in minutes
194194
specialistId:
195-
type: string
196-
format: uuid
195+
type: integer
196+
format: int64
197197

198198
TreatmentRequest:
199199
type: object
@@ -203,8 +203,8 @@ components:
203203
duration:
204204
type: integer
205205
specialistId:
206-
type: string
207-
format: uuid
206+
type: integer
207+
format: int64
208208

209209
TreatmentDetails:
210210
allOf:
@@ -215,8 +215,8 @@ components:
215215
type: object
216216
properties:
217217
id:
218-
type: string
219-
format: uuid
218+
type: integer
219+
format: int64
220220
name:
221221
type: string
222222

@@ -228,11 +228,11 @@ components:
228228
- dateTime
229229
properties:
230230
clientId:
231-
type: string
232-
format: uuid
231+
type: integer
232+
format: int64
233233
treatmentId:
234-
type: string
235-
format: uuid
234+
type: integer
235+
format: int64
236236
dateTime:
237237
type: string
238238
format: date-time
@@ -241,14 +241,14 @@ components:
241241
type: object
242242
properties:
243243
id:
244-
type: string
245-
format: uuid
244+
type: integer
245+
format: int64
246246
clientId:
247-
type: string
248-
format: uuid
247+
type: integer
248+
format: int64
249249
treatmentId:
250-
type: string
251-
format: uuid
250+
type: integer
251+
format: int64
252252
dateTime:
253253
type: string
254254
format: date-time

src/main/java/com/capgemini/training/appointmentbooking/service/impl/AppointmentsApiController.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.Date;
1414
import java.util.List;
1515
import java.util.Optional;
16-
import java.util.UUID;
1716
import java.util.stream.Collectors;
1817
import lombok.RequiredArgsConstructor;
1918
import org.springframework.format.annotation.DateTimeFormat;
@@ -44,8 +43,8 @@ public ResponseEntity<List<Appointment>> getAppointments(
4443

4544
AppointmentCriteria.AppointmentCriteriaBuilder criteria = AppointmentCriteria.builder();
4645
status.ifPresent(t -> criteria.status(AppointmentStatus.valueOf(t)));
47-
clientId.ifPresent(t -> criteria.clientId(UUID.fromString(t).getMostSignificantBits()));
48-
specialistId.ifPresent(t -> criteria.specialistId(UUID.fromString(t).getMostSignificantBits())); // TODO Krzysztof resign from getMostSignificantBits everywhere, instewad of uuid we want integer
46+
clientId.ifPresent(t -> criteria.clientId(Long.valueOf(t)));
47+
specialistId.ifPresent(t -> criteria.specialistId(Long.valueOf(t)));
4948

5049
List<AppointmentCto> list = findAppointmentUc.findByCriteria(criteria.build());
5150
List<Appointment> result =
@@ -56,7 +55,7 @@ public ResponseEntity<List<Appointment>> getAppointments(
5655
@Override
5756
public ResponseEntity<Void> updateAppointmentStatus(
5857
String appointmentId, @Valid AppointmentStatusUpdate appointmentStatusUpdate) {
59-
Long id = UUID.fromString(appointmentId).getMostSignificantBits();
58+
Long id = Long.valueOf(appointmentId);
6059
AppointmentStatus status =
6160
AppointmentStatus.valueOf(appointmentStatusUpdate.getStatus().name());
6261
manageAppointmentUc.updateAppointmentStatus(id, status);
@@ -67,7 +66,7 @@ public ResponseEntity<Void> updateAppointmentStatus(
6766
public ResponseEntity<CheckAvailability200Response> checkAvailability(
6867
@NotNull @Valid String specialistId,
6968
@NotNull @Valid @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date dateTime) {
70-
Long specialistLongId = UUID.fromString(specialistId).getMostSignificantBits();
69+
Long specialistLongId = Long.valueOf(specialistId);
7170
boolean available =
7271
!findAppointmentUc.hasConflictingAppointment(specialistLongId, dateTime.toInstant());
7372

src/main/java/com/capgemini/training/appointmentbooking/service/impl/TreatmentsApiController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import jakarta.validation.Valid;
1313
import java.util.List;
1414
import java.util.Optional;
15-
import java.util.UUID;
1615
import java.util.stream.Collectors;
1716
import lombok.RequiredArgsConstructor;
1817
import org.springframework.http.HttpStatus;
@@ -38,7 +37,7 @@ public ResponseEntity<Treatment> createTreatment(@Valid TreatmentRequest treatme
3837

3938
@Override
4039
public ResponseEntity<TreatmentDetails> getTreatmentDetails(String treatmentId) {
41-
Long id = UUID.fromString(treatmentId).getMostSignificantBits();
40+
Long id = Long.valueOf(treatmentId);
4241
Optional<TreatmentCto> optional = findTreatmentUc.findById(id);
4342

4443
return optional
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.capgemini.training.appointmentbooking.service.mapper;
22

33
import java.util.Optional;
4-
import java.util.UUID;
54

65
import com.capgemini.training.appointmentbooking.common.to.AppointmentBookingEto;
76
import com.capgemini.training.appointmentbooking.common.to.AppointmentCto;
@@ -13,10 +12,10 @@ public class AppointmentApiMapper {
1312

1413
public AppointmentBookingEto toBookingEto(AppointmentRequest request) {
1514
return AppointmentBookingEto.builder()
16-
.clientId(toLong(request.getClientId()))
17-
.treatmentId(toLong(request.getTreatmentId()))
15+
.clientId(request.getClientId())
16+
.treatmentId(request.getTreatmentId())
1817
.specialistId(
19-
0L) // specjalista nie jest częścią requestu – może być wyciągany przez treatment
18+
0L) // TODO specjalista nie jest częścią requestu – usunąć to po usunięciu specialistId z encji
2019
.dateTime(request.getDateTime().toInstant())
2120
.build();
2221
}
@@ -25,19 +24,12 @@ public Appointment toApiAppointment(AppointmentCto cto) {
2524
AppointmentEto appointmentEto = cto.appointmentEto();
2625

2726
Appointment result = new Appointment();
28-
result.setId(Optional.of(toUuid(appointmentEto.id())));
29-
result.setClientId(Optional.of(toUuid(cto.clientEto().id())));
30-
result.setTreatmentId(Optional.of(toUuid(cto.treatmentCto().treatmentEto().id())));
27+
result.setId(Optional.of(appointmentEto.id()));
28+
result.setClientId(Optional.of(cto.clientEto().id()));
29+
result.setTreatmentId(Optional.of(cto.treatmentCto().treatmentEto().id()));
3130
result.setDateTime(Optional.of(java.util.Date.from(appointmentEto.dateTime())));
3231
result.setStatus(Optional.of(Appointment.StatusEnum.valueOf(appointmentEto.status().name())));
3332
return result;
3433
}
3534

36-
private Long toLong(UUID uuid) {
37-
return uuid.getMostSignificantBits();
38-
}
39-
40-
private UUID toUuid(Long id) {
41-
return new UUID(id, 0L);
42-
}
4335
}

src/main/java/com/capgemini/training/appointmentbooking/service/mapper/TreatmentApiMapper.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.capgemini.training.appointmentbooking.service.mapper;
22

33
import java.util.Optional;
4-
import java.util.UUID;
54

65
import com.capgemini.training.appointmentbooking.common.to.SpecialistEto;
76
import com.capgemini.training.appointmentbooking.common.to.TreatmentCreationTo;
@@ -18,7 +17,7 @@ public TreatmentCreationTo toCreationTo(TreatmentRequest request) {
1817
return TreatmentCreationTo.builder()
1918
.name(request.getName().orElse(null))
2019
.durationMinutes(request.getDuration().orElse(0))
21-
.specialistId(request.getSpecialistId().map(UUID::getMostSignificantBits).orElse(null))
20+
.specialistId(request.getSpecialistId().orElse(null))
2221
.description("Default description")
2322
.build();
2423
}
@@ -28,10 +27,10 @@ public Treatment toApiTreatment(TreatmentCto cto) {
2827
SpecialistEto specialist = cto.specialistEto();
2928

3029
Treatment result = new Treatment();
31-
result.setId(Optional.ofNullable(eto.id()).map(this::toUuid));
30+
result.setId(Optional.ofNullable(eto.id()));
3231
result.setName(Optional.ofNullable(eto.name()));
3332
result.setDuration(Optional.of(eto.durationMinutes()));
34-
result.setSpecialistId(Optional.ofNullable(specialist.id()).map(this::toUuid));
33+
result.setSpecialistId(Optional.ofNullable(specialist.id()));
3534
return result;
3635
}
3736

@@ -40,20 +39,17 @@ public TreatmentDetails toApiTreatmentDetails(TreatmentCto cto) {
4039
SpecialistEto specialist = cto.specialistEto();
4140

4241
TreatmentDetails result = new TreatmentDetails();
43-
result.setId(Optional.ofNullable(eto.id()).map(this::toUuid));
42+
result.setId(Optional.ofNullable(eto.id()));
4443
result.setName(Optional.ofNullable(eto.name()));
4544
result.setDuration(Optional.of(eto.durationMinutes()));
46-
result.setSpecialistId(Optional.ofNullable(specialist.id()).map(this::toUuid));
45+
result.setSpecialistId(Optional.ofNullable(specialist.id()));
4746

4847
TreatmentDetailsAllOfSpecialist specialistDto = new TreatmentDetailsAllOfSpecialist();
49-
specialistDto.setId(Optional.ofNullable(specialist.id()).map(this::toUuid));
48+
specialistDto.setId(Optional.ofNullable(specialist.id()));
5049
specialistDto.setName(Optional.ofNullable(specialist.specialization().name()));
5150

5251
result.setSpecialist(Optional.of(specialistDto));
5352
return result;
5453
}
5554

56-
private UUID toUuid(Long id) {
57-
return new UUID(id, 0L);
58-
}
5955
}

0 commit comments

Comments
 (0)