This commit is contained in:
indx0
2025-11-21 21:39:00 +03:00
parent a612c92833
commit 02a8c05142
11 changed files with 92 additions and 28 deletions

View File

@@ -1,10 +1,40 @@
package com.example.nto.controller;
import com.example.nto.dto.CreateBookingDTO;
import com.example.nto.entity.Place;
import com.example.nto.service.BookingService;
import com.example.nto.service.EmployeeService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
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")
@RequiredArgsConstructor
public class BookingController {
@Autowired
private BookingService bookingService;
@GetMapping("/{code}/booking")
public ResponseEntity<Map<LocalDate, List<Place>>> getAvailablePlaces(@PathVariable String code) {
return ResponseEntity.noContent().build();
}
@PostMapping("/{code}/book")
public ResponseEntity<Void> createBooking(@RequestBody CreateBookingDTO createBookingDTO, @PathVariable String code) {
bookingService.createBooking(createBookingDTO);
return ResponseEntity.ok().build();
}
}

View File

@@ -1,11 +1,8 @@
package com.example.nto.controller;
import com.example.nto.dto.EmployeeDTO;
import com.example.nto.entity.Employee;
import com.example.nto.dto.EmployeeDTO;;
import com.example.nto.exception.CodeNotFoundException;
import com.example.nto.repository.EmployeeRepository;
import com.example.nto.service.EmployeeService;
import com.example.nto.util.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
@@ -14,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* TODO: ДОРАБОТАТЬ в рамках задания
* FINISHED_TODO: ДОРАБОТАТЬ в рамках задания
* =================================
* МОЖНО: Добавлять методы, аннотации, зависимости
* НЕЛЬЗЯ: Изменять название класса и пакета
@@ -28,24 +25,13 @@ public class EmployeeController {
@GetMapping("/{code}/auth")
public ResponseEntity<Void> auth(@PathVariable String code) {
boolean codeExists = employeeService.codeExists(code);
if(codeExists) {
employeeService.codeExists(code);
return ResponseEntity.ok().build();
}
else {
throw new CodeNotFoundException("Code Does Not Exist");
}
}
@GetMapping("/{code}/info")
public ResponseEntity<EmployeeDTO> info(@PathVariable String code) {
boolean codeExists = employeeService.codeExists(code);
if(codeExists) {
return ResponseEntity.ok(employeeService.getInfo(code));
}
else {
throw new CodeNotFoundException("Code Does Not Exist");
}
}
}

View File

@@ -0,0 +1,11 @@
package com.example.nto.dto;
import lombok.Data;
import java.time.LocalDate;
@Data
public class CreateBookingDTO {
LocalDate date;
Long placeID;
}

View File

@@ -1,11 +1,9 @@
package com.example.nto.dto;
import com.example.nto.entity.Booking;
import com.example.nto.entity.Place;
import lombok.Data;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
@Data

View File

@@ -10,6 +10,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
public class GlobalExceptionHandler {
@ExceptionHandler(CodeNotFoundException.class)
public ResponseEntity<Void> handleCodeNotFoundException(CodeNotFoundException e) {
return new ResponseEntity<Void>(HttpStatus.UNAUTHORIZED);
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
}

View File

@@ -3,6 +3,9 @@ package com.example.nto.repository;
import com.example.nto.entity.Booking;
import org.springframework.data.jpa.repository.JpaRepository;
import java.time.LocalDate;
import java.util.List;
/**
* FINISHED_TODO: ДОРАБОТАТЬ в рамках задания
* =================================
@@ -10,4 +13,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
public interface BookingRepository extends JpaRepository<Booking, Long> {
List<Booking> findByDateBetween(LocalDate startDate, LocalDate endDate);
}

View File

@@ -10,6 +10,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
public boolean existsByCode(String code);
public Employee findByCode(String code);
boolean existsByCode(String code);
Employee findByCode(String code);
}

View File

@@ -1,5 +1,11 @@
package com.example.nto.service;
import com.example.nto.dto.CreateBookingDTO;
import com.example.nto.entity.Place;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
/**
* TODO: ДОРАБОТАТЬ в рамках задания
* =================================
@@ -7,4 +13,6 @@ package com.example.nto.service;
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
public interface BookingService {
Map<LocalDate, List<Place>> getAvailablePlaces();
void createBooking(CreateBookingDTO createBookingDTO);
}

View File

@@ -9,6 +9,6 @@ import com.example.nto.dto.EmployeeDTO;
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
public interface EmployeeService {
public boolean codeExists(String code);
public EmployeeDTO getInfo(String code);
boolean codeExists(String code);
EmployeeDTO getInfo(String code);
}

View File

@@ -1,6 +1,15 @@
package com.example.nto.service.impl;
import com.example.nto.dto.CreateBookingDTO;
import com.example.nto.entity.Place;
import com.example.nto.repository.BookingRepository;
import com.example.nto.service.BookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
/**
* TODO: ДОРАБОТАТЬ в рамках задания
@@ -8,5 +17,18 @@ import com.example.nto.service.BookingService;
* МОЖНО: Добавлять методы, аннотации, зависимости
* НЕЛЬЗЯ: Изменять название класса и пакета
*/
@Service
public class BookingServiceImpl implements BookingService {
@Autowired
BookingRepository bookingRepository;
@Override
public Map<LocalDate, List<Place>> getAvailablePlaces() {
return Map.of();
}
@Override
public void createBooking(CreateBookingDTO createBookingDTO) {
}
}

View File

@@ -2,6 +2,7 @@ package com.example.nto.service.impl;
import com.example.nto.dto.EmployeeDTO;
import com.example.nto.entity.Employee;
import com.example.nto.exception.CodeNotFoundException;
import com.example.nto.repository.EmployeeRepository;
import com.example.nto.service.EmployeeService;
import com.example.nto.util.EmployeeMapper;
@@ -22,11 +23,15 @@ public class EmployeeServiceImpl implements EmployeeService {
@Override
public boolean codeExists(String code) {
boolean codeExists = employeeRepository.existsByCode(code);
return codeExists;
if(!codeExists) {
throw new CodeNotFoundException("Code Not Found");
}
return employeeRepository.existsByCode(code);
}
@Override
public EmployeeDTO getInfo(String code) {
this.codeExists(code);
Employee employee = employeeRepository.findByCode(code);
return EmployeeMapper.convertToDTO(employee);
}