main #9

Closed
student-20690 wants to merge 26 commits from (deleted):main into main
3 changed files with 18 additions and 2 deletions
Showing only changes of commit aee0974918 - Show all commits

View File

@@ -3,6 +3,7 @@ package com.example.nto.controller;
import com.example.nto.entity.Booking;
import com.example.nto.service.BookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@@ -31,7 +32,17 @@ public class BookingController {
public ResponseEntity<Map<String, List<Booking.AvailablePlaceDto>>> getAvailablePlaces(
@PathVariable String code
) {
Map<String, List<Booking.AvailablePlaceDto>> response = bookingService.getAvailablePlaces(code);
return ResponseEntity.ok(response);
try {
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();
}
}
}

View File

@@ -18,4 +18,6 @@ public interface BookingService {
Optional<Booking> getBookingById(Long id);
Map<String, List<Booking.AvailablePlaceDto>> getAvailablePlaces(String code);
boolean isEmployeeExists(String code);
}

View File

@@ -46,6 +46,9 @@ public class BookingServiceImpl implements BookingService {
this.placeRepository = placeRepository;
this.employeeRepository = employeeRepository;
}
public boolean isEmployeeExists(String code) {
return employeeRepository.findByCode(code).isPresent();
}
public Map<String, List<Booking.AvailablePlaceDto>> getAvailablePlaces(String employeeCode) {
// 1. Получаем сотрудника (для контекста)
Employee employee = employeeRepository.findByCode(employeeCode)