File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
src/main/java/com/example/SorokinSpringBoot Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 11package com .example .SorokinSpringBoot ;
22
33import com .example .SorokinSpringBoot .enums .ReservationStatus ;
4+ import com .example .SorokinSpringBoot .models .ReservaionEntity ;
45import com .example .SorokinSpringBoot .models .Reservation ;
56import 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
You can’t perform that action at this time.
0 commit comments