#2 Создала сущность заведения.

Создала класс Place, дто PlaceDTO, репозиторий, сервис, контроллер.
Написала миграцию для создания таблицы places.
parent e861fd80
package com.example.final_exam_l.controller;
import com.example.final_exam_l.service.PlaceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequiredArgsConstructor
@RequestMapping("/places")
public class PlaceController {
private final PlaceService service;
}
package com.example.final_exam_l.dto;
import com.example.final_exam_l.entity.Place;
import lombok.*;
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PlaceDTO {
private Integer id;
private String name;
private String description;
private double rating;
@ToString.Exclude
private UserDTO user;
public static PlaceDTO from(Place place){
return PlaceDTO.builder()
.id(place.getId())
.name(place.getName())
.description(place.getDescription())
.rating(place.getRating())
.user(UserDTO.from(place.getUser()))
.build();
}
}
package com.example.final_exam_l.entity;
import com.sun.istack.NotNull;
import lombok.*;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@Table(name = "places")
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Place {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column
@NotNull
private String name;
@Column
@NotNull
private String description;
@Column
@NotNull
@Builder.Default
private double rating = 0.0;
@Column
@NotNull
@Builder.Default
private boolean isDel = false;
@NotNull
@ManyToOne
private User user;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "place")
@Builder.Default
@ToString.Exclude
List<PlacePhoto> photos = new ArrayList<>();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "place")
@Builder.Default
@ToString.Exclude
List<Review> reviews = new ArrayList<>();
}
package com.example.final_exam_l.repository;
import com.example.final_exam_l.entity.Place;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface PlaceRepository extends JpaRepository<Place, Integer> {
}
package com.example.final_exam_l.service;
import com.example.final_exam_l.repository.PlaceRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class PlaceService {
private final PlaceRepository repository;
}
USE `final_exam`;
CREATE Table `places` (
`id` int auto_increment not null,
`name` varchar(128) not null,
`description` varchar(128) not null,
`rating` double not null,
`is_del` boolean not null,
`user_id` int not null references `users`(`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