/
ir_witch_13
/
ReadingDiaryWithRecommendationSystem
Обзор
Документация
Войти
/
ir_witch_13
/
ReadingDiaryWithRecommendationSystem
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/com/example/readingdiary/model/Book.java
166 строк
4 KB
Ira
Add entities. Set relations between them.
26 ноя 2025, 02:04
26 ноя 2025, 02:04
ff37154
Код
Авторство
О чём код?
package com.example.readingdiary.model; import jakarta.persistence.*; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.UUID; @Entity public class Book { @Id private String id; private String title; @ManyToOne @JoinColumn(name="author_id") private Author author; private String description; @ManyToMany @JoinTable(name = "book_genres", joinColumns = @JoinColumn(name="book_id"), inverseJoinColumns = @JoinColumn(name = "genre_name") ) private List<Genre> genres; private Status status; private LocalDate startDate; private LocalDate endDate; private String favoriteCharacter; private String leastCharacter; @OneToMany(mappedBy = "book") private List<Quote> quotes; @OneToMany(mappedBy = "book") private List<Note> notes; private Boolean isLiked; @ManyToOne @JoinColumn(name = "user_library_id") private UserLibrary userLibrary; public Book(String title, Author author, String description, ArrayList<Genre> genres, Status status, LocalDate startDate, LocalDate endDate, String favoriteCharacter, String leastCharacter){ this.id = UUID.randomUUID().toString(); this.title = title; this.author = author; this.description = description; this.genres = genres; this.status = status; this.startDate = startDate; this.endDate = endDate; this.favoriteCharacter = favoriteCharacter; this.leastCharacter = leastCharacter; quotes = new ArrayList<>(); notes = new ArrayList<>(); } public Book(String title, Author author, String description, ArrayList<Genre> genres, Status status){ this.id = UUID.randomUUID().toString(); this.title = title; this.author = author; this.description = description; this.genres = genres; this.status = status; } public String getId(){ return id; } public String getTitle(){ return title; } public void setTitle(String title){ if(!title.isEmpty()) this.title = title; } public Author getAuthor(){ return author; } public void setAuthor(String authorName){ this.author = new Author(authorName); } public String getDescription(){ return description; } public void setDescription(String description){ this.description = description; } public List<Genre> getGenre(){ return genres; } public void setGenre(ArrayList<Genre> genres){ this.genres = genres; } public LocalDate getStartDate(){ return startDate; } public void setStartDate(LocalDate startDate){ if(status != Status.WILL_READ && !startDate.isAfter(LocalDate.now())) this.startDate = startDate; } public LocalDate getEndDate() { return endDate; } public void setEndDate(LocalDate endDate) { if(status != Status.WILL_READ && !endDate.isAfter(LocalDate.now()) && endDate.isAfter(startDate)) this.endDate = endDate; } public String getFavoriteCharacter() { return favoriteCharacter; } public void setFavoriteCharacter(String favoriteCharacter) { if (status != Status.WILL_READ && !favoriteCharacter.isEmpty()) this.favoriteCharacter = favoriteCharacter; } public String getLeastCharacter() { return leastCharacter; } public void setLeastCharacter(String leastCharacter) { if (status != Status.WILL_READ && !leastCharacter.isEmpty()) this.leastCharacter = leastCharacter; } public List<Quote> getQuotes() { return quotes; } public List<Note> getNotes() { return notes; } public Boolean getLiked() { return isLiked; } public void setLiked(Boolean liked) { if(status == Status.FINISHED) isLiked = liked; } public void addQuote(Quote quote){ quotes.add(quote); } public void addNote(Note note){ notes.add(note); } public String getInfo(){ return ""; } }