Commit changes 2
Some checks failed
Android Test / validate-and-test (pull_request) Has been cancelled
Some checks failed
Android Test / validate-and-test (pull_request) Has been cancelled
This commit is contained in:
@@ -4,6 +4,7 @@ import com.example.nto.entity.Booking;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,4 +10,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface PlaceRepository extends JpaRepository<Place, Long> {
|
||||
Place findById(long placeId);
|
||||
}
|
||||
|
||||
@@ -101,20 +101,16 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
if (!CheckAuthorization(code))
|
||||
return new ResponseEntity<>("кода не существует", HttpStatus.UNAUTHORIZED);
|
||||
|
||||
Map<String, List<Place>> freePlacesMap = GetFreeBookings(code);
|
||||
if (!freePlacesMap.containsKey(bookingInfo.date.toString()))
|
||||
return new ResponseEntity<>("что-то пошло не так", HttpStatus.BAD_REQUEST);
|
||||
List<Place> freePlaces = freePlacesMap.get(bookingInfo.date.toString());
|
||||
for (int i = 0; i < freePlaces.size(); i++) {
|
||||
if (freePlaces.get(i).getId() == bookingInfo.placeId) {
|
||||
bookingRepository.save(Booking.builder()
|
||||
.date(bookingInfo.date)
|
||||
.place(freePlaces.get(i))
|
||||
.employee(employeeRepository.findByCode(code).get())
|
||||
.build());
|
||||
return new ResponseEntity<>("бронирование успешно создано", HttpStatus.CREATED);
|
||||
}
|
||||
List<Booking> allBookings = bookingRepository.findAll();
|
||||
for (int i = 0; i < allBookings.size(); i++) {
|
||||
if (allBookings.get(i).getDate().toString().equals(bookingInfo.date.toString()) && allBookings.get(i).getPlace().getId() == bookingInfo.placeId)
|
||||
return new ResponseEntity<>("уже забронировано", HttpStatus.CONFLICT);
|
||||
}
|
||||
return new ResponseEntity<>("уже забронировано", HttpStatus.CONFLICT);
|
||||
bookingRepository.save(Booking.builder()
|
||||
.date(bookingInfo.date)
|
||||
.place(placeRepository.findById(bookingInfo.placeId))
|
||||
.employee(employeeRepository.findByCode(code).get())
|
||||
.build());
|
||||
return new ResponseEntity<>("бронирование успешно создано", HttpStatus.CREATED);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user