17
17
import java .util .Optional ;
18
18
import java .util .stream .Collectors ;
19
19
20
+ /**
21
+ * Service class for slots managing.
22
+ */
20
23
@ Service
21
24
@ NoArgsConstructor
22
25
@ AllArgsConstructor
@@ -26,6 +29,12 @@ public class SlotService {
26
29
@ Autowired
27
30
private SlotRepository slotRepository ;
28
31
32
+ /**
33
+ * Create new slot
34
+ *
35
+ * @param slotCreateDeleteDto data for creating a slot
36
+ * @return created slot id
37
+ */
29
38
@ Transactional
30
39
@ Measurable
31
40
public Long create (SlotCreateDeleteDto slotCreateDeleteDto ) {
@@ -46,11 +55,22 @@ public Long create(SlotCreateDeleteDto slotCreateDeleteDto) {
46
55
return slotRepository .save (createSlot ).getSlotId ();
47
56
}
48
57
58
+ /**
59
+ * Find slot by ID
60
+ *
61
+ * @param slotId for find slot id
62
+ * @return optional found slot data
63
+ */
49
64
@ Measurable
50
65
public Optional <SlotReadUpdateDto > findById (Long slotId ) {
51
66
return slotRepository .findById (slotId ).map (SlotMapper .INSTANCE ::mapToSlotReadDto );
52
67
}
53
68
69
+ /**
70
+ * Find all available slots
71
+ *
72
+ * @return all slots data collection
73
+ */
54
74
@ Measurable
55
75
public List <SlotReadUpdateDto > findAll () {
56
76
return slotRepository .findAll ()
@@ -59,11 +79,23 @@ public List<SlotReadUpdateDto> findAll() {
59
79
.collect (Collectors .toList ());
60
80
}
61
81
82
+ /**
83
+ * Find slot by number
84
+ *
85
+ * @param slotNumber number of slot for find
86
+ * @return optional found slot data
87
+ */
62
88
@ Measurable
63
89
public Optional <SlotReadUpdateDto > findSlotByNumber (Integer slotNumber ) {
64
90
return slotRepository .findBySlotNumber (slotNumber ).map (SlotMapper .INSTANCE ::mapToSlotReadDto );
65
91
}
66
92
93
+ /**
94
+ * Delete slot bu id
95
+ *
96
+ * @param slotId slot id for remove
97
+ * @return true - deletion successful, false - deletion failed
98
+ */
67
99
@ Transactional
68
100
@ Measurable
69
101
public boolean delete (Long slotId ) {
@@ -77,6 +109,12 @@ public boolean delete(Long slotId) {
77
109
return mayBeSlot .isPresent ();
78
110
}
79
111
112
+ /**
113
+ * Update existent slot
114
+ *
115
+ * @param slotReadUpdateDto data for update slot info
116
+ * @return true - update successful, false - update failed
117
+ */
80
118
@ Transactional
81
119
@ Measurable
82
120
public boolean update (SlotReadUpdateDto slotReadUpdateDto ) {
@@ -134,6 +172,13 @@ public boolean update(SlotReadUpdateDto slotReadUpdateDto) {
134
172
}
135
173
136
174
/* Проверяем конфликтует ли вновь создаваемый слот (бронируемая единица) с уже существующими */
175
+
176
+ /**
177
+ * Check if there will be a time range conflict when creating a new slot or updating an existing one
178
+ *
179
+ * @param slotCreateDeleteDto for create new slot data
180
+ * @return true - there was a time range conflict, false - there is no conflict
181
+ */
137
182
private boolean isNewSlotConflicts (SlotCreateDeleteDto slotCreateDeleteDto ) {
138
183
List <Slot > allSlots = slotRepository .findAll ();
139
184
return allSlots .stream ()
0 commit comments