forked from Olympic/NTO-2025-Backend-TeamTask
app, entity and repo
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
package com.example.nto;
|
package com.example.nto;
|
||||||
|
|
||||||
/**
|
import org.springframework.boot.SpringApplication;
|
||||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
* =================================
|
|
||||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
@SpringBootApplication
|
||||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
|
||||||
*/
|
|
||||||
public class App {
|
public class App {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(App.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.example.nto.entity;
|
package com.example.nto.entity;
|
||||||
|
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.*;
|
||||||
import jakarta.persistence.JoinColumn;
|
|
||||||
import jakarta.persistence.ManyToOne;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -21,8 +19,12 @@ import java.time.LocalDate;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "booking")
|
||||||
public class Booking {
|
public class Booking {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private LocalDate date;
|
private LocalDate date;
|
||||||
@@ -31,5 +33,7 @@ public class Booking {
|
|||||||
@JoinColumn(name = "place_id")
|
@JoinColumn(name = "place_id")
|
||||||
private Place place;
|
private Place place;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "employee_id")
|
||||||
private Employee employee;
|
private Employee employee;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,19 @@ import java.util.List;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "employee")
|
||||||
public class Employee {
|
public class Employee {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
|
@Column(name = "photo_url")
|
||||||
private String photoUrl;
|
private String photoUrl;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(mappedBy = "employee", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.example.nto.entity;
|
package com.example.nto.entity;
|
||||||
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.*;
|
||||||
import jakarta.persistence.GenerationType;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -19,11 +17,14 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "place")
|
||||||
public class Place {
|
public class Place {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
|
@Column(name = "place_name")
|
||||||
private String place;
|
private String place;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
package com.example.nto.repository;
|
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;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||||
* =================================
|
* =================================
|
||||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||||
*/
|
*/
|
||||||
public interface BookingRepository {
|
@Repository
|
||||||
|
public interface BookingRepository extends JpaRepository<Booking, Long> {
|
||||||
|
List<Booking> findByDateBetween(LocalDate startDate, LocalDate endDate);
|
||||||
|
List<Booking> findByEmployeeIdAndDateBetween(Long employeeId, LocalDate startDate, LocalDate endDate);
|
||||||
|
Optional<Booking> findByDateAndPlaceId(LocalDate date, Long placeId);
|
||||||
|
boolean existsByEmployeeIdAndDate(Long employeeId, LocalDate date);
|
||||||
|
List<Booking> findByDate(LocalDate date);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
package com.example.nto.repository;
|
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: ДОРАБОТАТЬ в рамках задания
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||||
* =================================
|
* =================================
|
||||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||||
*/
|
*/
|
||||||
public interface EmployeeRepository {
|
@Repository
|
||||||
|
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||||
|
Optional<Employee> findByCode(String code);
|
||||||
|
boolean existsByCode(String code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
package com.example.nto.repository;
|
package com.example.nto.repository;
|
||||||
|
|
||||||
|
import com.example.nto.entity.Place;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: ДОРАБОТАТЬ в рамках задания
|
* TODO: ДОРАБОТАТЬ в рамках задания
|
||||||
* =================================
|
* =================================
|
||||||
* МОЖНО: Добавлять методы, аннотации, зависимости
|
* МОЖНО: Добавлять методы, аннотации, зависимости
|
||||||
* НЕЛЬЗЯ: Изменять название класса и пакета
|
* НЕЛЬЗЯ: Изменять название класса и пакета
|
||||||
*/
|
*/
|
||||||
public interface PlaceRepository {
|
@Repository
|
||||||
|
public interface PlaceRepository extends JpaRepository<Place, Long> {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user