#4 Создала сущность отзыва.

Создала класс Review, ReviewDTO, репозиторий, сервис.
Написала миграцию для создания таблицы reviews.
parent 8371fea7
package com.example.final_exam_l.dto;
import com.example.final_exam_l.entity.Place;
import com.example.final_exam_l.entity.Review;
import com.example.final_exam_l.entity.User;
import com.sun.istack.NotNull;
import lombok.*;
import javax.persistence.*;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ReviewDTO {
private Integer id;
private String description;
private Integer grade;
private boolean isDel;
@ToString.Exclude
private PlaceDTO place;
@ToString.Exclude
private UserDTO user;
public static ReviewDTO from(Review review){
return ReviewDTO.builder()
.id(review.getId())
.description(review.getDescription())
.grade(review.getGrade())
.isDel(review.isDel())
.place(PlaceDTO.from(review.getPlace()))
.user(UserDTO.from(review.getUser()))
.build();
}
}
package com.example.final_exam_l.entity;
import com.sun.istack.NotNull;
import lombok.*;
import javax.persistence.*;
@Getter
@Setter
@Table(name = "reviews")
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Review {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column
@NotNull
private String description;
@Column
@NotNull
private Integer grade;
@Column
@NotNull
@Builder.Default
private boolean isDel = false;
@NotNull
@ManyToOne
private Place place;
@NotNull
@ManyToOne
private User user;
}
package com.example.final_exam_l.repository;
import com.example.final_exam_l.entity.Review;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ReviewRepository extends JpaRepository<Review, Integer> {
}
package com.example.final_exam_l.service;
import com.example.final_exam_l.repository.ReviewRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class ReviewService {
private final ReviewRepository repository;
}
USE `final_exam`;
CREATE Table `reviews` (
`id` int auto_increment not null,
`description` varchar(128) not null,
`grade` int not null,
`is_del` boolean not null,
`user_id` int not null references `users`(`id`),
`place_id` int not null references `places`(`id`),
primary key (`id`)
);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment