именены классы фильмов
This commit is contained in:
parent
e865488ab5
commit
1713a0be9a
@ -1,19 +0,0 @@
|
||||
package com.example.backend.core.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommonRepository<E, T> {
|
||||
|
||||
List<E> getAll();
|
||||
|
||||
E get(T id);
|
||||
|
||||
E create(E entity);
|
||||
|
||||
E update(E entity);
|
||||
|
||||
E delete(E entity);
|
||||
|
||||
void deleteAll();
|
||||
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
package com.example.backend.core.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.example.backend.core.model.BaseEntity;
|
||||
|
||||
public abstract class MapRepository<E extends BaseEntity> implements CommonRepository<E, Integer> {
|
||||
|
||||
private final Map<Integer, E> entities = new TreeMap<>();
|
||||
private Integer lastId = 0;
|
||||
|
||||
private boolean checkNull(E entity) {
|
||||
if (get(entity.getId()) == null)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
protected MapRepository() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<E> getAll() {
|
||||
return entities.values().stream().toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(Integer id) {
|
||||
return entities.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E create(E entity) {
|
||||
lastId++;
|
||||
entity.setId(lastId);
|
||||
entities.put(lastId, entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E update(E entity) {
|
||||
if (checkNull(entity)) {
|
||||
entities.put(entity.getId(), entity);
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E delete(E entity) {
|
||||
if (checkNull(entity)) {
|
||||
entities.remove(entity.getId());
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAll() {
|
||||
entities.clear();
|
||||
lastId = 0;
|
||||
}
|
||||
}
|
@ -5,9 +5,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public class MovieDTO {
|
||||
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
private Integer id;
|
||||
|
||||
@NotNull
|
||||
@ -15,12 +17,15 @@ public class MovieDTO {
|
||||
private Integer categorieId;
|
||||
|
||||
@NotBlank
|
||||
@Size(min = 2, max = 50)
|
||||
private String name;
|
||||
|
||||
@NotBlank
|
||||
@Size(min = 2, max = 50)
|
||||
private String description;
|
||||
|
||||
@NotBlank
|
||||
@Size(min = 2, max = 50)
|
||||
private String duration;
|
||||
|
||||
private String image;
|
||||
|
@ -5,13 +5,30 @@ import java.util.Objects;
|
||||
import com.example.backend.categories.model.CategorieEntity;
|
||||
import com.example.backend.core.model.BaseEntity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "movies")
|
||||
public class MovieEntity extends BaseEntity {
|
||||
|
||||
@OneToMany
|
||||
@JoinColumn(name = "categorieId", nullable = false)
|
||||
private CategorieEntity categorie;
|
||||
|
||||
@Column(nullable = false, unique = true, length = 50)
|
||||
private String name;
|
||||
|
||||
@Column(nullable = false, unique = true, length = 300)
|
||||
private String description;
|
||||
|
||||
@Column(nullable = false, unique = true, length = 50)
|
||||
private String duration;
|
||||
|
||||
@Column(nullable = true)
|
||||
private String image;
|
||||
|
||||
public MovieEntity() {
|
||||
@ -21,7 +38,6 @@ public class MovieEntity extends BaseEntity {
|
||||
public MovieEntity(Integer id, CategorieEntity categorie, String name, String description, String duration,
|
||||
String image) {
|
||||
|
||||
super(id);
|
||||
this.categorie = categorie;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
|
@ -1,11 +1,8 @@
|
||||
package com.example.backend.movies.repository;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import com.example.backend.core.repository.MapRepository;
|
||||
import com.example.backend.movies.model.MovieEntity;
|
||||
|
||||
@Repository
|
||||
public class MovieRepository extends MapRepository<MovieEntity> {
|
||||
|
||||
}
|
||||
public interface MovieRepository extends CrudRepository<MovieRepository, Integer> {
|
||||
Optional<MovieRepository> findByNameIgnoreCase(String name);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user