Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 47d6c43

Browse files
StepFive: update SlotService.java
1 parent aee9aa0 commit 47d6c43

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

‎StepFive/src/main/java/me/oldboy/services/SlotService.java‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import java.util.Optional;
1818
import java.util.stream.Collectors;
1919

20+
/**
21+
* Service class for slots managing.
22+
*/
2023
@Service
2124
@NoArgsConstructor
2225
@AllArgsConstructor
@@ -26,6 +29,12 @@ public class SlotService {
2629
@Autowired
2730
private SlotRepository slotRepository;
2831

32+
/**
33+
* Create new slot
34+
*
35+
* @param slotCreateDeleteDto data for creating a slot
36+
* @return created slot id
37+
*/
2938
@Transactional
3039
@Measurable
3140
public Long create(SlotCreateDeleteDto slotCreateDeleteDto) {
@@ -46,11 +55,22 @@ public Long create(SlotCreateDeleteDto slotCreateDeleteDto) {
4655
return slotRepository.save(createSlot).getSlotId();
4756
}
4857

58+
/**
59+
* Find slot by ID
60+
*
61+
* @param slotId for find slot id
62+
* @return optional found slot data
63+
*/
4964
@Measurable
5065
public Optional<SlotReadUpdateDto> findById(Long slotId) {
5166
return slotRepository.findById(slotId).map(SlotMapper.INSTANCE::mapToSlotReadDto);
5267
}
5368

69+
/**
70+
* Find all available slots
71+
*
72+
* @return all slots data collection
73+
*/
5474
@Measurable
5575
public List<SlotReadUpdateDto> findAll() {
5676
return slotRepository.findAll()
@@ -59,11 +79,23 @@ public List<SlotReadUpdateDto> findAll() {
5979
.collect(Collectors.toList());
6080
}
6181

82+
/**
83+
* Find slot by number
84+
*
85+
* @param slotNumber number of slot for find
86+
* @return optional found slot data
87+
*/
6288
@Measurable
6389
public Optional<SlotReadUpdateDto> findSlotByNumber(Integer slotNumber) {
6490
return slotRepository.findBySlotNumber(slotNumber).map(SlotMapper.INSTANCE::mapToSlotReadDto);
6591
}
6692

93+
/**
94+
* Delete slot bu id
95+
*
96+
* @param slotId slot id for remove
97+
* @return true - deletion successful, false - deletion failed
98+
*/
6799
@Transactional
68100
@Measurable
69101
public boolean delete(Long slotId) {
@@ -77,6 +109,12 @@ public boolean delete(Long slotId) {
77109
return mayBeSlot.isPresent();
78110
}
79111

112+
/**
113+
* Update existent slot
114+
*
115+
* @param slotReadUpdateDto data for update slot info
116+
* @return true - update successful, false - update failed
117+
*/
80118
@Transactional
81119
@Measurable
82120
public boolean update(SlotReadUpdateDto slotReadUpdateDto) {
@@ -134,6 +172,13 @@ public boolean update(SlotReadUpdateDto slotReadUpdateDto) {
134172
}
135173

136174
/* Проверяем конфликтует ли вновь создаваемый слот (бронируемая единица) с уже существующими */
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+
*/
137182
private boolean isNewSlotConflicts(SlotCreateDeleteDto slotCreateDeleteDto) {
138183
List<Slot> allSlots = slotRepository.findAll();
139184
return allSlots.stream()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /