Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c43e4b18fb | ||
|
|
3c3ef45d78 | ||
|
|
3f1c5dbca8 | ||
|
|
46068ca46d | ||
|
|
65d3dd56cd | ||
|
|
d836b0bfe2 | ||
|
|
5d2d30992e | ||
|
|
18b3e950c1 | ||
|
|
0cf5cfdf59 | ||
|
|
ae1cfa3a32 | ||
|
|
2196f7e418 | ||
|
|
4814b6b1c1 | ||
|
|
f83af98397 | ||
|
|
662b109709 | ||
|
|
c4bb98b321 | ||
|
|
3b64ad9626 | ||
| f6acec1b98 | |||
|
|
bbd0182ae8 | ||
|
|
884adb5d6e | ||
|
|
9f437b83e2 | ||
|
|
af09df8047 | ||
| a6954c2013 |
@@ -1,4 +1,8 @@
|
||||
package com.example.nto;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
@@ -6,7 +10,9 @@ package com.example.nto;
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class , args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,77 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.excepation.EmployeeNotFoundException;
|
||||
import com.example.nto.repository.BookingRepository;
|
||||
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.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class BookingController {
|
||||
@Autowired
|
||||
private BookingService bookingService;
|
||||
@Autowired
|
||||
private PlaceRepository placeRepository;
|
||||
@Autowired
|
||||
private BookingRepository bookingRepository;
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
@GetMapping("/{code}/booking")
|
||||
public ResponseEntity<?> getAvailableBookings(@PathVariable String code) {
|
||||
try {
|
||||
if (code == null || code.trim().isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Employee code cannot be null or empty");
|
||||
}
|
||||
Map<String, Object> response = bookingService.findAvailableBookings(code);
|
||||
return ResponseEntity.ok(response);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
||||
} catch (EmployeeNotFoundException e) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Unexpected error");
|
||||
}
|
||||
}
|
||||
@PostMapping("/{code}/book")
|
||||
public ResponseEntity<?> createBooking(
|
||||
@PathVariable String code,
|
||||
@RequestBody Map<String, Object> body
|
||||
) {
|
||||
try {
|
||||
Long placeId = body.get("placeId") != null ? Long.valueOf(body.get("placeId").toString()) : null;
|
||||
String date = body.get("date") != null ? body.get("date").toString() : null;
|
||||
if (placeId == null || date == null || date.isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Place ID and date must be provided");
|
||||
}
|
||||
String message = bookingService.createBooking(code, placeId, date);
|
||||
return ResponseEntity.ok(message);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
||||
} catch (EmployeeNotFoundException e) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Unexpected error");
|
||||
}
|
||||
}
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteBooking(@PathVariable Long id) {
|
||||
bookingService.deleteBooking(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
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.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.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
@@ -6,5 +20,51 @@ package com.example.nto.controller;
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class EmployeeController {
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
@Autowired
|
||||
private BookingRepository bookingRepository;
|
||||
|
||||
@GetMapping("/{code}/auth")
|
||||
public ResponseEntity<String> checkAuth(
|
||||
@PathVariable String code) {
|
||||
if (code == null) {
|
||||
throw new IllegalArgumentException("Employee code is required");
|
||||
}
|
||||
try {
|
||||
employeeService.getEmployeeByCode(code);
|
||||
return ResponseEntity.ok("Authorized Employee");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||
} catch (EmployeeNotFoundException e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
@GetMapping("/{code}/info")
|
||||
public ResponseEntity<?> getEmployeeInfo(@PathVariable String code) {
|
||||
try {
|
||||
if (code == null || code.trim().isEmpty()) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body("Employee code cannot be null or empty");
|
||||
}
|
||||
Employee employee = employeeService.getEmployeeByCode(code);
|
||||
List<Booking> bookings = bookingRepository.findByEmployeeId(employee.getId());
|
||||
Map<String, List<Map<String, Object>>> bookingMap = bookings.stream().collect(Collectors.groupingBy(b -> b.getDate().toString(),LinkedHashMap::new,Collectors.mapping(b -> Map.of("id", b.getId(),"place", b.getPlace().getPlace()), Collectors.toList())));
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("name", employee.getName());
|
||||
response.put("photoUrl", employee.getPhotoUrl());
|
||||
response.put("booking", bookingMap);
|
||||
return ResponseEntity.ok(response);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
||||
} catch (EmployeeNotFoundException e) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body("Unexpected error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -21,15 +19,44 @@ import java.time.LocalDate;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name="booking")
|
||||
public class Booking {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
private LocalDate date;
|
||||
|
||||
@ManyToOne(targetEntity = Place.class, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "place_id")
|
||||
private Place place;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "employee_id")
|
||||
private Employee employee;
|
||||
|
||||
|
||||
public Place getPlace() {
|
||||
return place;
|
||||
}
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public Object getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Employee getEmployee() {
|
||||
return employee;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public void setPlace(Place place) {
|
||||
this.place = place;
|
||||
}
|
||||
public void setEmployee(Employee employee) {
|
||||
this.employee = (Employee) employee;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -19,16 +22,23 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name="employee")
|
||||
public class Employee {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private String photoUrl;
|
||||
@OneToMany(mappedBy = "employee", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
private List<Booking> bookings = new ArrayList<>();
|
||||
|
||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private List<Booking> bookingList;
|
||||
public long getId() { return id; }
|
||||
public String getName() { return name; }
|
||||
public String getCode() { return code; }
|
||||
public String getPhotoUrl() { return photoUrl; }
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -19,11 +17,26 @@ import lombok.NoArgsConstructor;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@Table(name="place")
|
||||
public class Place {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@Column(name = "place_name")
|
||||
private String place;
|
||||
|
||||
public Place(int id, String place) {
|
||||
}
|
||||
|
||||
|
||||
public Object getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.nto.excepation;
|
||||
|
||||
public class EmployeeNotFoundException extends RuntimeException{
|
||||
public EmployeeNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.nto.excepation;
|
||||
|
||||
public class IllegalArgumentException extends RuntimeException {
|
||||
public IllegalArgumentException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,20 @@
|
||||
package com.example.nto.repository;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface BookingRepository {
|
||||
@Repository
|
||||
public interface BookingRepository extends JpaRepository<Booking, Long> {
|
||||
List<Booking> findByDateBetween(LocalDate start, LocalDate end);
|
||||
List<Booking> findByEmployeeId(long id);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
package com.example.nto.repository;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface EmployeeRepository {
|
||||
}
|
||||
@Repository
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
Optional<Employee> findByCode(String code);
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
package com.example.nto.repository;
|
||||
|
||||
import com.example.nto.entity.Place;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface PlaceRepository {
|
||||
@Repository
|
||||
public interface PlaceRepository extends JpaRepository<Place, Long> {
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public interface BookingService {
|
||||
Map<String, Object> findAvailableBookings(String employeeCode);
|
||||
String createBooking(String code, Long placeId, String date);
|
||||
void deleteBooking(long id);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package com.example.nto.service;
|
||||
import com.example.nto.entity.Employee;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
@@ -6,5 +8,7 @@ package com.example.nto.service;
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Service
|
||||
public interface EmployeeService {
|
||||
Employee getEmployeeByCode(String code);
|
||||
}
|
||||
|
||||
22
src/main/java/com/example/nto/service/PlaceServise.java
Normal file
22
src/main/java/com/example/nto/service/PlaceServise.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.example.nto.service;
|
||||
import com.example.nto.entity.Place;
|
||||
import com.example.nto.repository.PlaceRepository;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PlaceServise {
|
||||
@Autowired
|
||||
private PlaceRepository placeRepository;
|
||||
@PostConstruct
|
||||
public void Places() {
|
||||
if(placeRepository.count() == 0) {
|
||||
placeRepository.save(new Place(1,"K-19"));
|
||||
placeRepository.save(new Place(2,"M-16"));
|
||||
placeRepository.save(new Place(3,"T-1"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,102 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.Place;
|
||||
import com.example.nto.excepation.EmployeeNotFoundException;
|
||||
import com.example.nto.repository.BookingRepository;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
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.stereotype.Service;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class BookingServiceImpl implements BookingService {
|
||||
@Autowired
|
||||
private BookingRepository bookingRepository;
|
||||
@Autowired
|
||||
private PlaceRepository placeRepository;
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
@Override
|
||||
public Map<String, Object> findAvailableBookings(String employeeCode) {
|
||||
if (employeeCode == null || employeeCode.isEmpty()) {
|
||||
throw new IllegalArgumentException("Employee code cannot be null or empty");
|
||||
}
|
||||
Employee employee = employeeService.getEmployeeByCode(employeeCode);
|
||||
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);
|
||||
List<Place> places = placeRepository.findAll();
|
||||
Map<String, List<Map<String, Object>>> result = new LinkedHashMap<>();
|
||||
for (int i = 0; i <= 3; i++) {
|
||||
LocalDate date = today.plusDays(i);
|
||||
List<Map<String, Object>> freePlaces = new ArrayList<>();
|
||||
for (Place place : places) {
|
||||
boolean isBooked = bookings.stream().anyMatch(b -> b.getDate().isEqual(date) && b.getPlace().getId() == place.getId());
|
||||
if (!isBooked) {
|
||||
Map<String, Object> placeInfo = new LinkedHashMap<>();
|
||||
placeInfo.put("id", place.getId());
|
||||
placeInfo.put("place", place.getPlace());
|
||||
freePlaces.add(placeInfo);
|
||||
}
|
||||
}
|
||||
result.put(date.toString(), freePlaces);
|
||||
}
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
public String createBooking(String code, Long placeId, String date) {
|
||||
|
||||
if (code == null || code.isBlank()) {
|
||||
throw new IllegalArgumentException("Employee code is empty");
|
||||
}
|
||||
if (placeId == null || date == null || date.isBlank()) {
|
||||
throw new IllegalArgumentException("Place ID and date must be provided");
|
||||
}
|
||||
Employee employee = employeeRepository.findByCode(code).orElseThrow(() -> new EmployeeNotFoundException("Employee not found"));
|
||||
Place place = placeRepository.findById(placeId).orElseThrow(() -> new IllegalArgumentException("Place not found"));
|
||||
LocalDate bookingDate;
|
||||
try {
|
||||
bookingDate = LocalDate.parse(date);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Invalid date format. Use yyyy-MM-dd");
|
||||
}
|
||||
boolean exists = bookingRepository.findByDateBetween(bookingDate, bookingDate).stream().anyMatch(
|
||||
b -> b.getPlace()
|
||||
.getId() == placeId);
|
||||
if (exists) {
|
||||
throw new IllegalArgumentException("Place already booked for this date");
|
||||
}
|
||||
Booking booking = new Booking();
|
||||
booking.setEmployee((Employee) employee);
|
||||
booking.setPlace(place);
|
||||
booking.setDate(bookingDate);
|
||||
bookingRepository.save(booking);
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("id", booking.getId());
|
||||
result.put("date", booking.getDate());
|
||||
result.put("placeId", place.getId());
|
||||
result.put("employeeId", employee.getId());
|
||||
return "the booking was created successfully";
|
||||
}
|
||||
public void deleteBooking(long id) {
|
||||
if (!bookingRepository.existsById(id)) {
|
||||
throw new IllegalArgumentException("Booking not found with id: " + id);
|
||||
}
|
||||
bookingRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.excepation.EmployeeNotFoundException;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
@@ -8,5 +14,16 @@ import com.example.nto.service.EmployeeService;
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
}
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
@Override
|
||||
public Employee getEmployeeByCode(String code) {
|
||||
if (code == null || code.isEmpty()) {
|
||||
throw new IllegalArgumentException("Employee code is required");
|
||||
}
|
||||
return employeeRepository.findByCode(code).orElseThrow(() -> new EmployeeNotFoundException("Employee not found"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user