Skip to content

Commit 29a2a39

Browse files
committed
feat: add reservatio
1 parent a5f508b commit 29a2a39

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/main/java/com/example/SorokinSpringBoot/ReservationService.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.SorokinSpringBoot;
22

33
import com.example.SorokinSpringBoot.enums.ReservationStatus;
4+
import com.example.SorokinSpringBoot.models.ReservaionEntity;
45
import com.example.SorokinSpringBoot.models.Reservation;
56
import org.springframework.stereotype.Service;
67

@@ -15,8 +16,10 @@ public class ReservationService {
1516

1617
private final Map<Long, Reservation> reservationMap;
1718
private final AtomicLong idCounter;
19+
private ReservationRepository repository;
1820

19-
public ReservationService() {
21+
public ReservationService(ReservationRepository repository) {
22+
this.repository = repository;
2023
this.reservationMap = new HashMap<>();
2124
idCounter = new AtomicLong();
2225
}
@@ -27,6 +30,20 @@ public Reservation getReservationById(Long id){
2730
}
2831

2932
public List<Reservation> findAllReservations() {
33+
34+
List<ReservaionEntity> allEntities = repository.findAll();
35+
36+
List<Reservation> reservationList = allEntities.stream()
37+
.map(it ->
38+
new Reservation(
39+
it.getId(),
40+
it.getUserId(),
41+
it.getRoomId(),
42+
it.getStartDate(),
43+
it.getEndDate(),
44+
it.getStatus()
45+
)).toList();
46+
3047
return reservationMap.values().stream().toList();
3148
}
3249

0 commit comments

Comments
 (0)