forked from Olympic/NTO-2025-Backend-TeamTask
49 lines
1.8 KiB
Java
49 lines
1.8 KiB
Java
package com.example.nto.controller;
|
|
|
|
import com.example.nto.dto.CreateBookingRequest;
|
|
import com.example.nto.dto.PlaceInfo;
|
|
import com.example.nto.dto.UserInfoResponse;
|
|
import com.example.nto.service.BookingService;
|
|
import com.example.nto.service.EmployeeService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.time.LocalDate;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
|
* =================================
|
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/{code}")
|
|
@RequiredArgsConstructor
|
|
public class BookingController {
|
|
|
|
private final BookingService bookingService;
|
|
private final EmployeeService employeeService;
|
|
|
|
@GetMapping("/info")
|
|
public ResponseEntity<UserInfoResponse> getUserInfo(@PathVariable String code) {
|
|
return ResponseEntity.ok(bookingService.getUserInfo(code));
|
|
}
|
|
|
|
@GetMapping("/booking")
|
|
public ResponseEntity<Map<LocalDate, List<PlaceInfo>>> getAvailablePlaces(@PathVariable String code) {
|
|
employeeService.findByCode(code)
|
|
.orElseThrow(() -> new jakarta.persistence.EntityNotFoundException("Employee not found with code: " + code));
|
|
return ResponseEntity.ok(bookingService.getAvailablePlaces());
|
|
}
|
|
|
|
@PostMapping("/book")
|
|
public ResponseEntity<Void> createBooking(@PathVariable String code, @RequestBody CreateBookingRequest request) {
|
|
bookingService.createBooking(code, request);
|
|
return ResponseEntity.status(HttpStatus.CREATED).build();
|
|
}
|
|
}
|