forked from Olympic/NTO-2025-Backend-TeamTask
Compare commits
3 Commits
af09df8047
...
bbd0182ae8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbd0182ae8 | ||
|
|
884adb5d6e | ||
|
|
9f437b83e2 |
@@ -15,11 +15,4 @@ public class App {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class , args);
|
||||
}
|
||||
@RestController
|
||||
public static class HomeController {
|
||||
@GetMapping("/")
|
||||
public String home() {
|
||||
return "Сервер работает!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,13 +9,11 @@ import com.example.nto.repository.PlaceRepository;
|
||||
import com.example.nto.service.BookingService;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -58,7 +56,6 @@ public class BookingController {
|
||||
@RequestParam String date
|
||||
) {
|
||||
try {
|
||||
// Проверка обязательных параметров
|
||||
if (placeId == null || date == null || date.isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body("Place ID and date must be provided");
|
||||
@@ -68,15 +65,11 @@ public class BookingController {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
|
||||
.body("Employee not found");
|
||||
}
|
||||
|
||||
// Получаем место
|
||||
Place place = placeRepository.findById(placeId).orElse(null);
|
||||
if (place == null) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body("Place not found");
|
||||
}
|
||||
|
||||
// Парсим дату
|
||||
LocalDate bookingDate;
|
||||
try {
|
||||
bookingDate = LocalDate.parse(date);
|
||||
@@ -84,8 +77,6 @@ public class BookingController {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body("Invalid date format. Use yyyy-MM-dd");
|
||||
}
|
||||
|
||||
// Проверяем, свободно ли место на эту дату
|
||||
boolean exists = bookingRepository.findByDateBetween(bookingDate, bookingDate)
|
||||
.stream()
|
||||
.anyMatch(b -> b.getPlace().getId() == placeId);
|
||||
@@ -98,16 +89,12 @@ public class BookingController {
|
||||
booking.setPlace(place);
|
||||
booking.setDate(bookingDate);
|
||||
bookingRepository.save(booking);
|
||||
|
||||
// Формируем ответ
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("id", booking.getId());
|
||||
response.put("date", booking.getDate());
|
||||
response.put("placeId", place.getId());
|
||||
response.put("employeeId", employee.getId());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||
|
||||
} catch (java.lang.IllegalArgumentException e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.excepation.EmployeeNotFoundException;
|
||||
import com.example.nto.repository.BookingRepository;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
@@ -24,7 +16,6 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class EmployeeController {
|
||||
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
@GetMapping("/{code}/auth")
|
||||
@@ -43,7 +34,6 @@ public class EmployeeController {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{code}/info")
|
||||
public ResponseEntity<?> getEmployeeInfo(@PathVariable String code) {
|
||||
try {
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.example.nto.excepation;
|
||||
|
||||
public class ConflictException extends RuntimeException {
|
||||
public ConflictException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,11 @@ package com.example.nto.repository;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.Place;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.example.nto.service;
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class PlaceServise {
|
||||
private final PlaceRepository placeRepository;
|
||||
|
||||
public PlaceServise(PlaceRepository placeRepository) {
|
||||
this.placeRepository = placeRepository;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public class BookingServiceImpl implements BookingService {
|
||||
if (employee == null) {
|
||||
throw new EmployeeNotFoundException("Employee not found with code: " + employeeCode);
|
||||
}
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate endDate = today.plusDays(3);
|
||||
List<Booking> bookings = bookingRepository.findByDateBetween(today, endDate);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
package com.example.nto.service.impl;
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.excepation.EmployeeNotFoundException;
|
||||
import com.example.nto.repository.BookingRepository;
|
||||
@@ -8,8 +7,6 @@ import com.example.nto.service.EmployeeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
@@ -19,13 +16,8 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Autowired
|
||||
private BookingRepository bookingRepository;
|
||||
|
||||
@Override
|
||||
public Employee getEmployeeWithBookings(String code) {
|
||||
if (code == null || code.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user