This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
package com.example.nto;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
}
|
||||
package com.example.nto;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* ok
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,61 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public class BookingController {
|
||||
}
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.entity.Place;
|
||||
import com.example.nto.service.BookingService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.crossstore.ChangeSetPersister;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Dictionary;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class BookingController {
|
||||
@Autowired
|
||||
private BookingService bookingService;
|
||||
|
||||
@GetMapping("/{code}/booking")
|
||||
public ResponseEntity<Dictionary<LocalDate, List<Place>>> getBookingsFree(@PathVariable String code){
|
||||
try {
|
||||
Dictionary<LocalDate, List<Place>> freeBookings = bookingService.getAllBooking(code);
|
||||
return new ResponseEntity<>(freeBookings, HttpStatus.OK);
|
||||
} catch (ChangeSetPersister.NotFoundException e) {
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
@PostMapping("/{code}/book")
|
||||
public ResponseEntity<Void> setBook(@PathVariable String code, @RequestBody String request){
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode;
|
||||
try {
|
||||
jsonNode = mapper.readTree(request);
|
||||
} catch (JsonProcessingException e) {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
boolean flag = bookingService.setBooking(code, LocalDate.parse(jsonNode.get("date").asText()), jsonNode.get("placeId").asLong());
|
||||
if (flag){
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||
}
|
||||
} catch (ChangeSetPersister.NotFoundException e) {
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,54 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public class EmployeeController {
|
||||
}
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.crossstore.ChangeSetPersister;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class EmployeeController {
|
||||
@Autowired
|
||||
private EmployeeService employeeService;
|
||||
|
||||
@GetMapping("/{code}/auth")
|
||||
public ResponseEntity<Void> validCode(@PathVariable String code){
|
||||
try {
|
||||
Employee employee = employeeService.getEmployeeByCode(code);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
} catch (ChangeSetPersister.NotFoundException e) {
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
@GetMapping("/{code}/info")
|
||||
public ResponseEntity<JsonNode> getEmployee(@PathVariable String code){
|
||||
try {
|
||||
Employee employee = employeeService.getEmployeeByCode(code);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode;
|
||||
jsonNode = mapper.readTree(employee.toString());
|
||||
return new ResponseEntity<>(jsonNode, HttpStatus.OK);
|
||||
} catch (ChangeSetPersister.NotFoundException e) {
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
} catch (JsonProcessingException e) {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,75 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Booking {
|
||||
|
||||
private long id;
|
||||
|
||||
private LocalDate date;
|
||||
|
||||
@ManyToOne(targetEntity = Place.class, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "place_id")
|
||||
private Place place;
|
||||
|
||||
private Employee employee;
|
||||
}
|
||||
package com.example.nto.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
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")
|
||||
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
|
||||
private Place place;
|
||||
|
||||
@ManyToOne(targetEntity = Employee.class, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "employee_id")
|
||||
private Employee employee;
|
||||
|
||||
@JsonIgnore
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDate getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Place getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public void setPlace(Place place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Employee getEmployee() {
|
||||
return employee;
|
||||
}
|
||||
|
||||
public void setEmployee(Employee employee) {
|
||||
this.employee = employee;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,109 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Employee {
|
||||
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private String photoUrl;
|
||||
|
||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private List<Booking> bookingList;
|
||||
}
|
||||
package com.example.nto.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Employee {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private String photoUrl;
|
||||
|
||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JsonProperty("booking")
|
||||
private List<Booking> bookingList;
|
||||
|
||||
@JsonIgnore
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getPhotoUrl() {
|
||||
return photoUrl;
|
||||
}
|
||||
|
||||
public void setPhotoUrl(String photoUrl) {
|
||||
this.photoUrl = photoUrl;
|
||||
}
|
||||
|
||||
public List<Booking> getBookingList() {
|
||||
return bookingList;
|
||||
}
|
||||
|
||||
public void setBookingList(List<Booking> bookingList) {
|
||||
this.bookingList = bookingList;
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectNode bookingDict = mapper.createObjectNode();
|
||||
for (Booking booking : bookingList) {
|
||||
bookingDict.set(booking.getDate().toString(), mapper.createObjectNode().put("id", booking.getPlace().getId()).put("place", booking.getPlace().getPlace()));
|
||||
}
|
||||
String bookingStr;
|
||||
try {
|
||||
bookingStr = mapper.writeValueAsString(bookingDict);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return """
|
||||
{
|
||||
"name":"%s",
|
||||
"photoUrl":"%s",
|
||||
"booking":%s
|
||||
}
|
||||
""".formatted(this.name, this.photoUrl, bookingStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,61 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Place {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
private String place;
|
||||
}
|
||||
package com.example.nto.entity;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Place {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@Column(name = "place_name")
|
||||
private String place;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getPlace() {
|
||||
return place;
|
||||
}
|
||||
|
||||
public void setPlace(String place) {
|
||||
this.place = place;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectNode place = mapper.createObjectNode();
|
||||
place.put("id", this.id);
|
||||
place.put("place", this.place);
|
||||
try {
|
||||
return mapper.writeValueAsString(place);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
package com.example.nto.repository;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface BookingRepository {
|
||||
}
|
||||
package com.example.nto.repository;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Place;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
|
||||
@Repository
|
||||
public interface BookingRepository extends JpaRepository<Booking, Long> {
|
||||
@Query(nativeQuery = true, value = "SELECT * FROM PLACE p WHERE p.id NOT IN (SELECT b.place_id FROM BOOKING b WHERE b.date = :datek)")
|
||||
List<Place> findAllFreeBooking(@Param("datek") LocalDate datek);
|
||||
@Query("SELECT b FROM Booking b WHERE date = :datek AND place.id = :placek")
|
||||
Optional<Booking> findBookingDatePlace(@Param("datek") LocalDate localDate, @Param("placek") long placeId);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
package com.example.nto.repository;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface EmployeeRepository {
|
||||
}
|
||||
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: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
|
||||
@Repository
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
Optional<Employee> findByCode(String code);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package com.example.nto.repository;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface PlaceRepository {
|
||||
}
|
||||
package com.example.nto.repository;
|
||||
|
||||
import com.example.nto.entity.Place;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
|
||||
@Repository
|
||||
public interface PlaceRepository extends JpaRepository<Place, Long> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface BookingService {
|
||||
}
|
||||
package com.example.nto.service;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.entity.Place;
|
||||
import org.springframework.boot.logging.structured.ContextPairs;
|
||||
import org.springframework.data.crossstore.ChangeSetPersister;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Dictionary;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface BookingService {
|
||||
Dictionary<LocalDate, List<Place>> getAllBooking(String code) throws ChangeSetPersister.NotFoundException;
|
||||
boolean setBooking(String code, LocalDate date, Long place) throws ChangeSetPersister.NotFoundException;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface EmployeeService {
|
||||
}
|
||||
package com.example.nto.service;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import org.springframework.data.crossstore.ChangeSetPersister;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface EmployeeService {
|
||||
Employee getEmployeeByCode(String code) throws ChangeSetPersister.NotFoundException;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,78 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.service.BookingService;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public class BookingServiceImpl implements BookingService {
|
||||
}
|
||||
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.repository.BookingRepository;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.repository.PlaceRepository;
|
||||
import com.example.nto.service.BookingService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.data.crossstore.ChangeSetPersister;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
|
||||
@Service
|
||||
@EnableJpaRepositories("com.example.nto")
|
||||
@EntityScan("com.example.nto")
|
||||
@ComponentScan(basePackages = "com.example.nto")
|
||||
public class BookingServiceImpl implements BookingService {
|
||||
@Autowired
|
||||
private BookingRepository bookingRepository;
|
||||
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Autowired
|
||||
private PlaceRepository placeRepository;
|
||||
|
||||
@Override
|
||||
public Dictionary<LocalDate, List<Place>> getAllBooking(String code) throws ChangeSetPersister.NotFoundException {
|
||||
try {
|
||||
Employee employee = employeeRepository.findByCode(code).get();
|
||||
Dictionary<LocalDate, List<Place>> dict = new Hashtable<>();
|
||||
dict.put(LocalDate.now(), bookingRepository.findAllFreeBooking(LocalDate.now()));
|
||||
dict.put(LocalDate.now().plusDays(1), bookingRepository.findAllFreeBooking(LocalDate.now().plusDays(1)));
|
||||
dict.put(LocalDate.now().plusDays(2), bookingRepository.findAllFreeBooking(LocalDate.now().plusDays(2)));
|
||||
dict.put(LocalDate.now().plusDays(3), bookingRepository.findAllFreeBooking(LocalDate.now().plusDays(3)));
|
||||
return dict;
|
||||
}
|
||||
catch (NoSuchElementException e){
|
||||
throw new ChangeSetPersister.NotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBooking(String code, LocalDate date, Long place) throws ChangeSetPersister.NotFoundException {
|
||||
try {
|
||||
Employee employee = employeeRepository.findByCode(code).get();
|
||||
Optional<Booking> booking = bookingRepository.findBookingDatePlace(date, place);
|
||||
if (booking.isPresent()){
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
Booking booking1 = new Booking();
|
||||
booking1.setDate(date);
|
||||
booking1.setPlace(placeRepository.findById(place).get());
|
||||
booking1.setEmployee(employee);
|
||||
bookingRepository.save(booking1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (NoSuchElementException e){
|
||||
throw new ChangeSetPersister.NotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.service.EmployeeService;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
}
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.crossstore.ChangeSetPersister;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
@Autowired
|
||||
private EmployeeRepository employeeRepository;
|
||||
|
||||
@Override
|
||||
public Employee getEmployeeByCode(String code) throws ChangeSetPersister.NotFoundException {
|
||||
try {
|
||||
return employeeRepository.findByCode(code).get();
|
||||
}
|
||||
catch (NoSuchElementException e){
|
||||
throw new ChangeSetPersister.NotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user