Skip to content

Commit

Permalink
Merge pull request #108 from oduck-team/feature/102
Browse files Browse the repository at this point in the history
장르, 성우, 원작자, 제작사, 시리즈 삭제 수정 #102
  • Loading branch information
jaycobcoder authored Nov 15, 2023
2 parents 1d1dea3 + d67a7b3 commit d3f8630
Show file tree
Hide file tree
Showing 23 changed files with 275 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public ResponseEntity<Object> patchAnimeStudios(

return ResponseEntity.noContent().build();
}

// 애니의 성우 수정
@PatchMapping("/animes/{animeId}/voice-actors")
public ResponseEntity<Object> patchAnimeVoiceActors(
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/oduck/api/domain/anime/dto/AnimeReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class AnimeReq {
@Getter
public static class PostReq {
@NotBlank
@Length(min = 1, max = 50, message = "글자 수는 0~50을 허용합니다.")
@Length(min = 1, max = 50, message = "글자 수는 1~50을 허용합니다.")
private String title;

@NotBlank
@Length(min = 1, max = 255, message = "글자 수는 0~255를 허용합니다.")
@Length(min = 1, max = 600, message = "글자 수는 1~600자를 허용합니다.")
private String summary;

@NotNull
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/oduck/api/domain/anime/entity/Anime.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ public void decreaseStarRatingScore(int score){
}

public void delete() {
this.animeOriginalAuthors.clear();
this.animeVoiceActors.clear();
this.animeGenres.clear();
this.animeStudios.clear();
this.series = null;

this.deletedAt = LocalDateTime.now();
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/io/oduck/api/domain/genre/entity/Genre.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package io.oduck.api.domain.genre.entity;

import io.oduck.api.domain.anime.entity.AnimeGenre;
import io.oduck.api.global.audit.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -22,14 +27,19 @@ public class Genre extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 15, unique = true)
@Column(nullable = false, length = 15)
private String name;

@OneToMany(mappedBy = "genre", cascade = CascadeType.PERSIST, orphanRemoval = true)
@Builder.Default
private List<AnimeGenre> animeGenres = new ArrayList<>();

public void update(String name) {
this.name = name;
}

public void delete() {
this.animeGenres.clear();
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface GenreRepository extends JpaRepository<Genre, Long> {
public interface GenreRepository extends JpaRepository<Genre, Long>, GenreRepositoryCustom {

boolean existsByName(String name);

Optional<Genre> findByIdAndDeletedAtIsNull(Long genreId);
@Query("select distinct g from Genre g left join fetch g.animeGenres where g.id = :id and g.deletedAt = null")
Optional<Genre> findByIdAndDeletedAtIsNull(@Param("id") Long genreId);

List<Genre> findAllByDeletedAtIsNull();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.oduck.api.domain.genre.repository;

public interface GenreRepositoryCustom {
boolean existsByName(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.oduck.api.domain.genre.repository;

import static io.oduck.api.domain.genre.entity.QGenre.genre;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class GenreRepositoryCustomImpl implements GenreRepositoryCustom{

private final JPAQueryFactory queryFactory;

@Override
public boolean existsByName(String name) {
Integer fetchOne = queryFactory
.selectOne()
.from(genre)
.where(
genre.name.eq(name),
notDeleted()
).fetchFirst();
return fetchOne != null;
}

private BooleanExpression notDeleted() {
return genre.deletedAt.isNull();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package io.oduck.api.domain.originalAuthor.entity;

import io.oduck.api.domain.anime.entity.Anime;
import io.oduck.api.domain.anime.entity.AnimeOriginalAuthor;
import io.oduck.api.global.audit.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -22,14 +28,19 @@ public class OriginalAuthor extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 50, unique = true)
@Column(nullable = false, length = 50)
private String name;

@OneToMany(mappedBy = "originalAuthor", cascade = CascadeType.PERSIST, orphanRemoval = true)
@Builder.Default
private List<AnimeOriginalAuthor> animeOriginalAuthors = new ArrayList<>();

public void update(String name) {
this.name = name;
}

public void delete() {
this.animeOriginalAuthors.clear();
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.oduck.api.domain.originalAuthor.repository;

import com.querydsl.core.Fetchable;
import io.oduck.api.domain.originalAuthor.entity.OriginalAuthor;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface OriginalAuthorRepository extends JpaRepository<OriginalAuthor, Long> {
public interface OriginalAuthorRepository extends JpaRepository<OriginalAuthor, Long>, OriginalAuthorRepositoryCustom {

boolean existsByName(String name);

Optional<OriginalAuthor> findByIdAndDeletedAtIsNull(Long originalAuthorId);
@Query("select distinct oa from OriginalAuthor oa left join fetch oa.animeOriginalAuthors where oa.id = :id and oa.deletedAt = null")
Optional<OriginalAuthor> findByIdAndDeletedAtIsNull(@Param("id") Long originalAuthorId);

List<OriginalAuthor> findAllByDeletedAtIsNull();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.oduck.api.domain.originalAuthor.repository;

public interface OriginalAuthorRepositoryCustom {
boolean existsByName(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.oduck.api.domain.originalAuthor.repository;


import static io.oduck.api.domain.originalAuthor.entity.QOriginalAuthor.originalAuthor;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class OriginalAuthorRepositoryCustomImpl implements OriginalAuthorRepositoryCustom {

private final JPAQueryFactory queryFactory;

@Override
public boolean existsByName(String name) {
Integer fetchOne = queryFactory.selectOne()
.from(originalAuthor)
.where(
originalAuthor.name.eq(name),
notDeleted()
)
.fetchFirst();
return fetchOne != null;
}

private BooleanExpression notDeleted() {
return originalAuthor.deletedAt.isNull();
}
}
12 changes: 11 additions & 1 deletion src/main/java/io/oduck/api/domain/series/entity/Series.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package io.oduck.api.domain.series.entity;

import io.oduck.api.domain.anime.entity.Anime;
import io.oduck.api.global.audit.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -22,14 +27,19 @@ public class Series extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 50, unique = true)
@Column(nullable = false, length = 50)
private String title;

@OneToMany(mappedBy = "series", cascade = CascadeType.PERSIST, orphanRemoval = true)
@Builder.Default
private List<Anime> animes = new ArrayList<>();

public void update(String title) {
this.title = title;
}

public void delete() {
this.animes.clear();
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.parameters.P;

public interface SeriesRepository extends JpaRepository<Series, Long> {
public interface SeriesRepository extends JpaRepository<Series, Long>, SeriesRepositoryCustom {

boolean existsByTitle(String title);

Optional<Series> findByIdAndDeletedAtIsNull(Long seriesId);
@Query("select distinct s from Series s left join fetch s.animes where s.id = :id and s.deletedAt = null")
Optional<Series> findByIdAndDeletedAtIsNull(@Param("id") Long seriesId);

List<Series> findAllByDeletedAtIsNull();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.oduck.api.domain.series.repository;

public interface SeriesRepositoryCustom {

boolean existsByTitle(String title);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.oduck.api.domain.series.repository;

import static io.oduck.api.domain.series.entity.QSeries.series;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class SeriesRepositoryCustomImpl implements SeriesRepositoryCustom{

private final JPAQueryFactory queryFactory;

@Override
public boolean existsByTitle(String title) {
Integer fetchOne = queryFactory.selectOne()
.from(series)
.where(
series.title.eq(title),
notDeleted()
)
.fetchFirst();
return fetchOne != null;
}

private BooleanExpression notDeleted() {
return series.deletedAt.isNull();
}
}
12 changes: 11 additions & 1 deletion src/main/java/io/oduck/api/domain/studio/entity/Studio.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package io.oduck.api.domain.studio.entity;

import io.oduck.api.domain.anime.entity.AnimeStudio;
import io.oduck.api.global.audit.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -22,14 +27,19 @@ public class Studio extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false, length = 50, unique = true)
@Column(nullable = false, length = 50)
private String name;

@OneToMany(mappedBy = "studio", cascade = CascadeType.PERSIST, orphanRemoval = true)
@Builder.Default
private List<AnimeStudio> animeStudios = new ArrayList<>();

public void update(String name) {
this.name = name;
}

public void delete() {
this.animeStudios.clear();
this.deletedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package io.oduck.api.domain.studio.repository;

import com.querydsl.core.Fetchable;
import io.oduck.api.domain.studio.entity.Studio;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface StudioRepository extends JpaRepository<Studio, Long> {
public interface StudioRepository extends JpaRepository<Studio, Long>, StudioRepositoryCustom {

boolean existsByName(String name);

Optional<Studio> findByIdAndDeletedAtIsNull(Long studioId);
@Query("select distinct s from Studio s left join fetch s.animeStudios where s.id = :id and s.deletedAt = null")
Optional<Studio> findByIdAndDeletedAtIsNull(@Param("id") Long studioId);

List<Studio> findAllByDeletedAtIsNull();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.oduck.api.domain.studio.repository;

public interface StudioRepositoryCustom {

boolean existsByName(String name);
}
Loading

0 comments on commit d3f8630

Please sign in to comment.