main #10
@@ -1,9 +1,13 @@
|
||||
package com.example.nto.controller;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
@@ -11,9 +15,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("code")
|
||||
public class BookingController {
|
||||
@GetMapping("/booking")
|
||||
public String booking(@RequestParam(defaultValue = "")String id){
|
||||
return "booking session started " + id;
|
||||
}
|
||||
// @GetMapping("/booking")
|
||||
// public Booking booking(@RequestParam(defaultValue = "")String id){
|
||||
// return new Booking(id, );
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("code")
|
||||
public class EmployeeController {
|
||||
@GetMapping("/auth/{id}")
|
||||
public int isAuth(@PathVariable int id){
|
||||
return id;
|
||||
}
|
||||
// @GetMapping("/auth/{id}")
|
||||
// public int isAuth(@PathVariable int id){
|
||||
// return id;
|
||||
// }
|
||||
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
@@ -29,9 +29,8 @@ public class EmployeeController {
|
||||
this.employeeService = employeeService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@ResponseStatus(code = HttpStatus.OK)
|
||||
public List<Employee> getAll() {
|
||||
return employeeService.getAll();
|
||||
@GetMapping("/{id}/auth")
|
||||
public HttpStatus Isauth(@PathVariable long id){
|
||||
return HttpStatus.OK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
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;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@@ -21,8 +20,9 @@ import java.time.LocalDate;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
public class Booking {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private LocalDate date;
|
||||
@@ -31,5 +31,7 @@ public class Booking {
|
||||
@JoinColumn(name = "place_id")
|
||||
private Place place;
|
||||
|
||||
@ManyToOne(targetEntity = Employee.class, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "employee_id")
|
||||
private Employee employee;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,11 @@ import java.util.List;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
public class Employee {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
@@ -37,19 +40,4 @@ public class Employee {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.nto.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
@@ -19,6 +20,7 @@ import lombok.NoArgsConstructor;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
public class Place {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
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.util.Optional;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface BookingRepository {
|
||||
@Repository
|
||||
public interface BookingRepository extends JpaRepository<Booking, Long> {
|
||||
Optional<Booking> findByName(String name);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.example.nto.repository;
|
||||
import com.example.nto.entity.Employee;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -13,8 +14,9 @@ import java.util.Optional;
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Repository
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
Optional<Employee> findById(long id);
|
||||
Optional<Employee> findById(Long id);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
@@ -7,4 +9,5 @@ package com.example.nto.service;
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public interface BookingService {
|
||||
Booking getBooking(String name);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.example.nto.service;
|
||||
import com.example.nto.entity.Employee;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
@@ -13,5 +14,5 @@ import java.util.List;
|
||||
public interface EmployeeService {
|
||||
List<Employee> getAll();
|
||||
|
||||
Employee getById(long id);
|
||||
Optional<Employee> getById(long id);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,34 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.entity.Booking;
|
||||
import com.example.nto.repository.BookingRepository;
|
||||
import com.example.nto.service.BookingService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
* =================================
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
public class BookingServiceImpl implements BookingService {
|
||||
}
|
||||
//public class BookingServiceImpl implements BookingService {
|
||||
//
|
||||
//
|
||||
// private final BookingRepository bookingRepository;
|
||||
//
|
||||
// public BookingServiceImpl(BookingRepository bookingRepository) {
|
||||
// this.bookingRepository = bookingRepository;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Booking> getAll() {
|
||||
// return bookingRepository.findAll();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Booking getByName(String name) {
|
||||
// return bookingRepository.findByName(name);
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
@@ -3,9 +3,11 @@ 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.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||
@@ -13,6 +15,7 @@ import java.util.List;
|
||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||
*/
|
||||
@Component
|
||||
@Service
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
private final EmployeeRepository employeeRepository;
|
||||
@@ -23,13 +26,11 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
@Override
|
||||
public List<Employee> getAll() {
|
||||
|
||||
|
||||
return employeeRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Employee getById(long id) {
|
||||
public Optional<Employee> getById(long id) {
|
||||
return employeeRepository.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user