Skip to content

Commit b025f8d

Browse files
author
Piotr Kubicki
committed
fix: spotless apply
1 parent 7f58816 commit b025f8d

File tree

10 files changed

+349
-408
lines changed

10 files changed

+349
-408
lines changed

src/main/java/com/capgemini/training/appointmentbooking/dataaccess/repository/AppointmentRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ SELECT CASE WHEN COUNT(a) > 0 THEN TRUE ELSE FALSE END
7979
WHERE t.specialist.id = :specialistId
8080
AND a.dateTime = :date
8181
AND a.status <> com.capgemini.training.appointmentbooking.common.datatype.AppointmentStatus.CANCELLED
82-
""") // TODO add checks for TreatmentEntity#durationMinutes so that within treatment time no more appoinments can be booked
82+
""") // TODO add checks for TreatmentEntity#durationMinutes so that within treatment
83+
// time no more appoinments can be booked
8384
boolean hasConflictingAppointmentBySpecialistIdAndDateTime(@Param("specialistId") Long specialistId,
8485
@Param("date") Instant date);
8586

src/main/java/com/capgemini/training/appointmentbooking/dataaccess/repository/UserRepository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
@Repository
1717
public interface UserRepository extends BaseJpaRepository<UserEntity, Long> {
18-
default List<UserEntity> findByCriteria(UserCriteria criteria) { // TODO openapi change ? -> szukanie po clientach do stworzenia appointmentów
18+
default List<UserEntity> findByCriteria(UserCriteria criteria) { // TODO openapi change ? -> szukanie po clientach
19+
// do stworzenia appointmentów
1920
Objects.requireNonNull(criteria, "criteria must not be null");
2021

2122
EntityManager entityManager = getEntityManager();

src/main/java/com/capgemini/training/appointmentbooking/logic/impl/ManageAppointmentUcImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public ManageAppointmentUcImpl(FindAppointmentUc findAppointmentUc, AppointmentR
5454
public AppointmentCto bookAppointment(@Valid AppointmentBookingEto appointmentBookingEto) {
5555
boolean hasConflict = findAppointmentUc.hasConflictingAppointment(appointmentBookingEto.specialistId(),
5656
appointmentBookingEto.dateTime());
57-
// TODO Michał will add hints regarding pessimistic locking in exercise for logic
57+
// TODO Michał will add hints regarding pessimistic locking in exercise for
58+
// logic
5859
if (hasConflict) {
5960
throw new ConflictedAppointmentException();
6061
}
@@ -81,7 +82,9 @@ public AppointmentEto updateAppointmentStatus(@NotNull Long appointmentId,
8182
private AppointmentEntity buildAppointmentEntity(@Valid AppointmentBookingEto appointmentBookingEto) {
8283
AppointmentEntity entity = new AppointmentEntity();
8384

84-
ClientEntity clientEntity = clientRepository.getReferenceById(appointmentBookingEto.clientId()); // TODO change getReferenceById to find
85+
ClientEntity clientEntity = clientRepository.getReferenceById(appointmentBookingEto.clientId()); // TODO change
86+
// getReferenceById
87+
// to find
8588
TreatmentEntity treatmentEntity = treatmentRepository.getReferenceById(appointmentBookingEto.treatmentId());
8689

8790
entity.setClient(clientEntity);

src/main/java/com/capgemini/training/appointmentbooking/service/config/ServiceMappingConfiguration.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
@Configuration
99
public class ServiceMappingConfiguration {
1010

11-
@Bean
12-
AppointmentApiMapper getAppointmentApiMapper() {
13-
return new AppointmentApiMapper();
14-
}
11+
@Bean
12+
AppointmentApiMapper getAppointmentApiMapper() {
13+
return new AppointmentApiMapper();
14+
}
1515

16-
@Bean
17-
TreatmentApiMapper getTreatmentApiMapper() {
18-
return new TreatmentApiMapper();
19-
}
16+
@Bean
17+
TreatmentApiMapper getTreatmentApiMapper() {
18+
return new TreatmentApiMapper();
19+
}
2020
}

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

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,48 @@
2323
@RequiredArgsConstructor
2424
public class AppointmentsApiController implements AppointmentsApi {
2525

26-
private final FindAppointmentUc findAppointmentUc;
27-
private final ManageAppointmentUc manageAppointmentUc;
28-
private final AppointmentApiMapper appointmentMapper;
26+
private final FindAppointmentUc findAppointmentUc;
27+
private final ManageAppointmentUc manageAppointmentUc;
28+
private final AppointmentApiMapper appointmentMapper;
2929

30-
@Override
31-
public ResponseEntity<Appointment> createAppointment(
32-
@Valid AppointmentRequest appointmentRequest) {
33-
AppointmentBookingEto bookingEto = appointmentMapper.toBookingEto(appointmentRequest);
34-
AppointmentCto created = manageAppointmentUc.bookAppointment(bookingEto);
35-
return ResponseEntity.status(201).body(appointmentMapper.toApiAppointment(created));
36-
}
30+
@Override
31+
public ResponseEntity<Appointment> createAppointment(@Valid AppointmentRequest appointmentRequest) {
32+
AppointmentBookingEto bookingEto = appointmentMapper.toBookingEto(appointmentRequest);
33+
AppointmentCto created = manageAppointmentUc.bookAppointment(bookingEto);
34+
return ResponseEntity.status(201).body(appointmentMapper.toApiAppointment(created));
35+
}
3736

38-
@Override
39-
public ResponseEntity<List<Appointment>> getAppointments(
40-
@Valid Optional<String> clientId,
41-
@Valid Optional<String> specialistId,
42-
@Valid Optional<String> status) {
37+
@Override
38+
public ResponseEntity<List<Appointment>> getAppointments(@Valid Optional<String> clientId,
39+
@Valid Optional<String> specialistId, @Valid Optional<String> status) {
4340

44-
AppointmentCriteria.AppointmentCriteriaBuilder criteria = AppointmentCriteria.builder();
45-
status.ifPresent(t -> criteria.status(AppointmentStatus.valueOf(t)));
46-
clientId.ifPresent(t -> criteria.clientId(Long.valueOf(t)));
47-
specialistId.ifPresent(t -> criteria.specialistId(Long.valueOf(t)));
41+
AppointmentCriteria.AppointmentCriteriaBuilder criteria = AppointmentCriteria.builder();
42+
status.ifPresent(t -> criteria.status(AppointmentStatus.valueOf(t)));
43+
clientId.ifPresent(t -> criteria.clientId(Long.valueOf(t)));
44+
specialistId.ifPresent(t -> criteria.specialistId(Long.valueOf(t)));
4845

49-
List<AppointmentCto> list = findAppointmentUc.findByCriteria(criteria.build());
50-
List<Appointment> result =
51-
list.stream().map(appointmentMapper::toApiAppointment).collect(Collectors.toList());
52-
return ResponseEntity.ok(result);
53-
}
46+
List<AppointmentCto> list = findAppointmentUc.findByCriteria(criteria.build());
47+
List<Appointment> result = list.stream().map(appointmentMapper::toApiAppointment).collect(Collectors.toList());
48+
return ResponseEntity.ok(result);
49+
}
5450

55-
@Override
56-
public ResponseEntity<Void> updateAppointmentStatus(
57-
String appointmentId, @Valid AppointmentStatusUpdate appointmentStatusUpdate) {
58-
Long id = Long.valueOf(appointmentId);
59-
AppointmentStatus status =
60-
AppointmentStatus.valueOf(appointmentStatusUpdate.getStatus().name());
61-
manageAppointmentUc.updateAppointmentStatus(id, status);
62-
return ResponseEntity.ok().build();
63-
}
51+
@Override
52+
public ResponseEntity<Void> updateAppointmentStatus(String appointmentId,
53+
@Valid AppointmentStatusUpdate appointmentStatusUpdate) {
54+
Long id = Long.valueOf(appointmentId);
55+
AppointmentStatus status = AppointmentStatus.valueOf(appointmentStatusUpdate.getStatus().name());
56+
manageAppointmentUc.updateAppointmentStatus(id, status);
57+
return ResponseEntity.ok().build();
58+
}
6459

65-
@Override
66-
public ResponseEntity<CheckAvailability200Response> checkAvailability(
67-
@NotNull @Valid String specialistId,
68-
@NotNull @Valid @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date dateTime) {
69-
Long specialistLongId = Long.valueOf(specialistId);
70-
boolean available =
71-
!findAppointmentUc.hasConflictingAppointment(specialistLongId, dateTime.toInstant());
60+
@Override
61+
public ResponseEntity<CheckAvailability200Response> checkAvailability(@NotNull @Valid String specialistId,
62+
@NotNull @Valid @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date dateTime) {
63+
Long specialistLongId = Long.valueOf(specialistId);
64+
boolean available = !findAppointmentUc.hasConflictingAppointment(specialistLongId, dateTime.toInstant());
7265

73-
CheckAvailability200Response response = new CheckAvailability200Response();
74-
response.setAvailable(Optional.of(available));
75-
return ResponseEntity.ok(response);
76-
}
66+
CheckAvailability200Response response = new CheckAvailability200Response();
67+
response.setAvailable(Optional.of(available));
68+
return ResponseEntity.ok(response);
69+
}
7770
}

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,30 @@
2424
@RequiredArgsConstructor
2525
public class TreatmentsApiController implements TreatmentsApi {
2626

27-
private final FindTreatmentUc findTreatmentUc;
28-
private final ManageTreatmentUc manageTreatmentUc;
29-
private final TreatmentApiMapper treatmentMapper;
27+
private final FindTreatmentUc findTreatmentUc;
28+
private final ManageTreatmentUc manageTreatmentUc;
29+
private final TreatmentApiMapper treatmentMapper;
3030

31-
@Override
32-
public ResponseEntity<Treatment> createTreatment(@Valid TreatmentRequest treatmentRequest) {
33-
TreatmentCreationTo to = treatmentMapper.toCreationTo(treatmentRequest);
34-
TreatmentCto created = manageTreatmentUc.createTreatment(to);
35-
return ResponseEntity.status(HttpStatus.CREATED).body(treatmentMapper.toApiTreatment(created));
36-
}
31+
@Override
32+
public ResponseEntity<Treatment> createTreatment(@Valid TreatmentRequest treatmentRequest) {
33+
TreatmentCreationTo to = treatmentMapper.toCreationTo(treatmentRequest);
34+
TreatmentCto created = manageTreatmentUc.createTreatment(to);
35+
return ResponseEntity.status(HttpStatus.CREATED).body(treatmentMapper.toApiTreatment(created));
36+
}
3737

38-
@Override
39-
public ResponseEntity<TreatmentDetails> getTreatmentDetails(String treatmentId) {
40-
Long id = Long.valueOf(treatmentId);
41-
Optional<TreatmentCto> optional = findTreatmentUc.findById(id);
38+
@Override
39+
public ResponseEntity<TreatmentDetails> getTreatmentDetails(String treatmentId) {
40+
Long id = Long.valueOf(treatmentId);
41+
Optional<TreatmentCto> optional = findTreatmentUc.findById(id);
4242

43-
return optional
44-
.map(treatmentMapper::toApiTreatmentDetails)
45-
.map(ResponseEntity::ok)
46-
.orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build());
47-
}
43+
return optional.map(treatmentMapper::toApiTreatmentDetails).map(ResponseEntity::ok)
44+
.orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build());
45+
}
4846

49-
@Override
50-
public ResponseEntity<List<Treatment>> getTreatments() {
51-
List<TreatmentCto> list = findTreatmentUc.findAll();
52-
List<Treatment> result =
53-
list.stream().map(treatmentMapper::toApiTreatment).collect(Collectors.toList());
54-
return ResponseEntity.ok(result);
55-
}
47+
@Override
48+
public ResponseEntity<List<Treatment>> getTreatments() {
49+
List<TreatmentCto> list = findTreatmentUc.findAll();
50+
List<Treatment> result = list.stream().map(treatmentMapper::toApiTreatment).collect(Collectors.toList());
51+
return ResponseEntity.ok(result);
52+
}
5653
}

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,26 @@
1010

1111
public class AppointmentApiMapper {
1212

13-
public AppointmentBookingEto toBookingEto(AppointmentRequest request) {
14-
return AppointmentBookingEto.builder()
15-
.clientId(request.getClientId())
16-
.treatmentId(request.getTreatmentId())
17-
.specialistId(
18-
0L) // TODO specjalista nie jest częścią requestu – usunąć to po usunięciu specialistId tylko z AppointmentBookingEto,
19-
// bo jedyne użycie AppointmentBookingEto#specialistId jest w findAppointmentUc.hasConflictingAppointment
20-
// gdzie specialistId da się wyciągnąć z treatment
21-
.dateTime(request.getDateTime().toInstant())
22-
.build();
23-
}
13+
public AppointmentBookingEto toBookingEto(AppointmentRequest request) {
14+
return AppointmentBookingEto.builder().clientId(request.getClientId()).treatmentId(request.getTreatmentId())
15+
.specialistId(0L) // TODO specjalista nie jest częścią requestu – usunąć to po usunięciu
16+
// specialistId tylko z AppointmentBookingEto,
17+
// bo jedyne użycie AppointmentBookingEto#specialistId jest w
18+
// findAppointmentUc.hasConflictingAppointment
19+
// gdzie specialistId da się wyciągnąć z treatment
20+
.dateTime(request.getDateTime().toInstant()).build();
21+
}
2422

25-
public Appointment toApiAppointment(AppointmentCto cto) {
26-
AppointmentEto appointmentEto = cto.appointmentEto();
23+
public Appointment toApiAppointment(AppointmentCto cto) {
24+
AppointmentEto appointmentEto = cto.appointmentEto();
2725

28-
Appointment result = new Appointment();
29-
result.setId(Optional.of(appointmentEto.id()));
30-
result.setClientId(Optional.of(cto.clientEto().id()));
31-
result.setTreatmentId(Optional.of(cto.treatmentCto().treatmentEto().id()));
32-
result.setDateTime(Optional.of(java.util.Date.from(appointmentEto.dateTime())));
33-
result.setStatus(Optional.of(Appointment.StatusEnum.valueOf(appointmentEto.status().name())));
34-
return result;
35-
}
26+
Appointment result = new Appointment();
27+
result.setId(Optional.of(appointmentEto.id()));
28+
result.setClientId(Optional.of(cto.clientEto().id()));
29+
result.setTreatmentId(Optional.of(cto.treatmentCto().treatmentEto().id()));
30+
result.setDateTime(Optional.of(java.util.Date.from(appointmentEto.dateTime())));
31+
result.setStatus(Optional.of(Appointment.StatusEnum.valueOf(appointmentEto.status().name())));
32+
return result;
33+
}
3634

3735
}

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

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,40 @@
1313

1414
public class TreatmentApiMapper {
1515

16-
public TreatmentCreationTo toCreationTo(TreatmentRequest request) {
17-
return TreatmentCreationTo.builder()
18-
.name(request.getName().orElse(null))
19-
.durationMinutes(request.getDuration().orElse(0))
20-
.specialistId(request.getSpecialistId().orElse(null))
21-
.description("Default description")
22-
.build();
23-
}
24-
25-
public Treatment toApiTreatment(TreatmentCto cto) {
26-
TreatmentEto eto = cto.treatmentEto();
27-
SpecialistEto specialist = cto.specialistEto();
28-
29-
Treatment result = new Treatment();
30-
result.setId(Optional.ofNullable(eto.id()));
31-
result.setName(Optional.ofNullable(eto.name()));
32-
result.setDuration(Optional.of(eto.durationMinutes()));
33-
result.setSpecialistId(Optional.ofNullable(specialist.id()));
34-
return result;
35-
}
36-
37-
public TreatmentDetails toApiTreatmentDetails(TreatmentCto cto) {
38-
TreatmentEto eto = cto.treatmentEto();
39-
SpecialistEto specialist = cto.specialistEto();
40-
41-
TreatmentDetails result = new TreatmentDetails();
42-
result.setId(Optional.ofNullable(eto.id()));
43-
result.setName(Optional.ofNullable(eto.name()));
44-
result.setDuration(Optional.of(eto.durationMinutes()));
45-
result.setSpecialistId(Optional.ofNullable(specialist.id()));
46-
47-
TreatmentDetailsAllOfSpecialist specialistDto = new TreatmentDetailsAllOfSpecialist();
48-
specialistDto.setId(Optional.ofNullable(specialist.id()));
49-
specialistDto.setName(Optional.ofNullable(specialist.specialization().name()));
50-
51-
result.setSpecialist(Optional.of(specialistDto));
52-
return result;
53-
}
16+
public TreatmentCreationTo toCreationTo(TreatmentRequest request) {
17+
return TreatmentCreationTo.builder().name(request.getName().orElse(null))
18+
.durationMinutes(request.getDuration().orElse(0)).specialistId(request.getSpecialistId().orElse(null))
19+
.description("Default description").build();
20+
}
21+
22+
public Treatment toApiTreatment(TreatmentCto cto) {
23+
TreatmentEto eto = cto.treatmentEto();
24+
SpecialistEto specialist = cto.specialistEto();
25+
26+
Treatment result = new Treatment();
27+
result.setId(Optional.ofNullable(eto.id()));
28+
result.setName(Optional.ofNullable(eto.name()));
29+
result.setDuration(Optional.of(eto.durationMinutes()));
30+
result.setSpecialistId(Optional.ofNullable(specialist.id()));
31+
return result;
32+
}
33+
34+
public TreatmentDetails toApiTreatmentDetails(TreatmentCto cto) {
35+
TreatmentEto eto = cto.treatmentEto();
36+
SpecialistEto specialist = cto.specialistEto();
37+
38+
TreatmentDetails result = new TreatmentDetails();
39+
result.setId(Optional.ofNullable(eto.id()));
40+
result.setName(Optional.ofNullable(eto.name()));
41+
result.setDuration(Optional.of(eto.durationMinutes()));
42+
result.setSpecialistId(Optional.ofNullable(specialist.id()));
43+
44+
TreatmentDetailsAllOfSpecialist specialistDto = new TreatmentDetailsAllOfSpecialist();
45+
specialistDto.setId(Optional.ofNullable(specialist.id()));
46+
specialistDto.setName(Optional.ofNullable(specialist.specialization().name()));
47+
48+
result.setSpecialist(Optional.of(specialistDto));
49+
return result;
50+
}
5451

5552
}

0 commit comments

Comments
 (0)