+условие для букинга
This commit is contained in:
@@ -3,6 +3,7 @@ package com.example.nto.controller;
|
|||||||
import com.example.nto.entity.Booking;
|
import com.example.nto.entity.Booking;
|
||||||
import com.example.nto.service.BookingService;
|
import com.example.nto.service.BookingService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -31,7 +32,17 @@ public class BookingController {
|
|||||||
public ResponseEntity<Map<String, List<Booking.AvailablePlaceDto>>> getAvailablePlaces(
|
public ResponseEntity<Map<String, List<Booking.AvailablePlaceDto>>> getAvailablePlaces(
|
||||||
@PathVariable String code
|
@PathVariable String code
|
||||||
) {
|
) {
|
||||||
Map<String, List<Booking.AvailablePlaceDto>> response = bookingService.getAvailablePlaces(code);
|
try {
|
||||||
return ResponseEntity.ok(response);
|
if (!bookingService.isEmployeeExists(code)) {
|
||||||
|
return ResponseEntity
|
||||||
|
.status(401).build();
|
||||||
|
}
|
||||||
|
Map<String, List<Booking.AvailablePlaceDto>> response = bookingService.getAvailablePlaces(code);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,4 +18,6 @@ public interface BookingService {
|
|||||||
Optional<Booking> getBookingById(Long id);
|
Optional<Booking> getBookingById(Long id);
|
||||||
|
|
||||||
Map<String, List<Booking.AvailablePlaceDto>> getAvailablePlaces(String code);
|
Map<String, List<Booking.AvailablePlaceDto>> getAvailablePlaces(String code);
|
||||||
|
|
||||||
|
boolean isEmployeeExists(String code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ public class BookingServiceImpl implements BookingService {
|
|||||||
this.placeRepository = placeRepository;
|
this.placeRepository = placeRepository;
|
||||||
this.employeeRepository = employeeRepository;
|
this.employeeRepository = employeeRepository;
|
||||||
}
|
}
|
||||||
|
public boolean isEmployeeExists(String code) {
|
||||||
|
return employeeRepository.findByCode(code).isPresent();
|
||||||
|
}
|
||||||
public Map<String, List<Booking.AvailablePlaceDto>> getAvailablePlaces(String employeeCode) {
|
public Map<String, List<Booking.AvailablePlaceDto>> getAvailablePlaces(String employeeCode) {
|
||||||
// 1. Получаем сотрудника (для контекста)
|
// 1. Получаем сотрудника (для контекста)
|
||||||
Employee employee = employeeRepository.findByCode(employeeCode)
|
Employee employee = employeeRepository.findByCode(employeeCode)
|
||||||
|
|||||||
Reference in New Issue
Block a user