Skip to content

Commit

Permalink
Merge pull request #20 from Media-XI/feat/exhibition-artwork-삭제
Browse files Browse the repository at this point in the history
Feat/exhibition artwork 삭제
  • Loading branch information
Hoon9901 authored Oct 11, 2023
2 parents 1eca06d + aa5b1e8 commit fa6f890
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 322 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.example.codebase.domain.exhibition.dto.CreateExhibitionDTO;
import com.example.codebase.domain.exhibition.dto.ResponseExhibitionDTO;
import com.example.codebase.domain.exhibition.service.ExhibitionService;
import com.example.codebase.domain.exhibition_artwork.dto.ExhibitionArtworkResponseDTO;
import com.example.codebase.domain.exhibition_artwork.dto.ExhibitionArtworksResponseDTO;
import com.example.codebase.util.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.codebase.domain.artwork.dto.ArtworkCreateDTO;
import com.example.codebase.domain.artwork.dto.ArtworkMediaCreateDTO;
import com.example.codebase.domain.artwork.dto.ArtworkUpdateDTO;
import com.example.codebase.domain.exhibition_artwork.entity.ExhibitionArtwork;
import com.example.codebase.domain.member.entity.Member;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -64,10 +63,6 @@ public class Artwork {
@JoinColumn(name = "member_id")
private Member member;

@Builder.Default
@OneToMany(mappedBy = "artwork", cascade = CascadeType.ALL)
private List<ExhibitionArtwork> exhibitionArtworks = new ArrayList<>();

@Builder.Default
@OneToMany(mappedBy = "artwork", cascade = CascadeType.ALL)
private List<ArtworkMedia> artworkMedia = new ArrayList<>();
Expand Down Expand Up @@ -97,10 +92,6 @@ public void addArtworkMedia(ArtworkMedia artworkMedia) {
this.artworkMedia.add(artworkMedia);
}

public void addExhibitionArtwork(ExhibitionArtwork exhibitionArtwork) {
this.exhibitionArtworks.add(exhibitionArtwork);
}

public void update(ArtworkUpdateDTO dto) {
this.title = dto.getTitle();
if (Optional.ofNullable(dto.getTags()).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.codebase.domain.exhibition.entity;

import com.example.codebase.domain.exhibition.dto.CreateExhibitionDTO;
import com.example.codebase.domain.exhibition_artwork.entity.ExhibitionArtwork;
import com.example.codebase.domain.member.entity.Member;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@
import com.example.codebase.domain.exhibition.entity.Exhibition;
import com.example.codebase.domain.exhibition.entity.ExhibitionMedia;
import com.example.codebase.domain.exhibition.repository.ExhibitionRepository;
import com.example.codebase.domain.exhibition_artwork.dto.ExhibitionArtworkResponseDTO;
import com.example.codebase.domain.exhibition_artwork.dto.ExhibitionArtworksResponseDTO;
import com.example.codebase.domain.exhibition_artwork.entity.ExhibitionArtwork;
import com.example.codebase.domain.exhibition_artwork.entity.ExhibitionArtworkStatus;
import com.example.codebase.domain.exhibition_artwork.exception.NotFoundExhibitionException;
import com.example.codebase.domain.exhibition_artwork.repository.ExhibitionArtworkRepository;
import com.example.codebase.domain.member.entity.Member;
import com.example.codebase.domain.member.exception.NotFoundMemberException;
import com.example.codebase.domain.member.repository.MemberRepository;
import com.example.codebase.exception.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -30,16 +25,13 @@
@Service
public class ExhibitionService {
private final ExhibitionRepository exhibitionRepository;

private final ExhibitionArtworkRepository exhibitionArtworkRepository;

private final ArtworkRepository artworkRepository;

private final MemberRepository memberRepository;

public ExhibitionService(ExhibitionRepository exhibitionRepository, ExhibitionArtworkRepository exhibitionArtworkRepository, ArtworkRepository artworkRepository, MemberRepository memberRepository) {
@Autowired
public ExhibitionService(ExhibitionRepository exhibitionRepository, ArtworkRepository artworkRepository, MemberRepository memberRepository) {
this.exhibitionRepository = exhibitionRepository;
this.exhibitionArtworkRepository = exhibitionArtworkRepository;
this.artworkRepository = artworkRepository;
this.memberRepository = memberRepository;
}
Expand Down Expand Up @@ -72,7 +64,7 @@ public List<ResponseExhibitionDTO> getAllExhibition() {

public ResponseExhibitionDTO updateExhibition(Long exhibitionId, CreateExhibitionDTO createExhibitionDTO, String username) {
Exhibition exhibition = exhibitionRepository.findById(exhibitionId)
.orElseThrow(() -> new NotFoundExhibitionException());
.orElseThrow(() -> new NotFoundException("전시를 찾을 수 없습니다."));

if (!exhibition.getMember().getUsername().equals(username)) {
throw new RuntimeException("공모전의 작성자가 아닙니다.");
Expand All @@ -86,72 +78,13 @@ public ResponseExhibitionDTO updateExhibition(Long exhibitionId, CreateExhibitio
@Transactional
public void deleteExhibition(Long exhibitionId, String username) {
Exhibition exhibition = exhibitionRepository.findById(exhibitionId)
.orElseThrow(() -> new NotFoundExhibitionException());
.orElseThrow(() -> new NotFoundException("전시를 찾을 수 없습니다."));

if (!exhibition.getMember().getUsername().equals(username)) {
throw new RuntimeException("공모전의 작성자가 아닙니다.");
}

// 공모전에 제출된 작품들을 반려처리
List<ExhibitionArtwork> all = exhibitionArtworkRepository.findAllByExhibitionId(exhibitionId);
all.forEach(exhibitionArtwork -> {
exhibitionArtwork.setExhibitionArtworkStatus(ExhibitionArtworkStatus.rejected);
});

exhibition.delete(); // 소프트 삭제
}

@Transactional
public ExhibitionArtworkResponseDTO addArtworkToExhibition(Long exhibitionId, Long artworkId, String username) {
Artwork artwork = artworkRepository.findById(artworkId)
.orElseThrow(() -> new NotFoundException("존재하지 않는 작품입니다."));

if (!artwork.getMember().getUsername().equals(username)) {
throw new RuntimeException("아트워크의 작성자가 아닙니다.");
}

Exhibition exhibition = exhibitionRepository.findById(exhibitionId)
.orElseThrow(() -> new NotFoundExhibitionException());

ExhibitionArtwork exhibitionArtwork = ExhibitionArtwork.of(exhibition, artwork);
artwork.addExhibitionArtwork(exhibitionArtwork);

ExhibitionArtwork save = exhibitionArtworkRepository.save(exhibitionArtwork);

return ExhibitionArtworkResponseDTO.from(save);
}

public ExhibitionArtworksResponseDTO getArtworkFromExhibition(Long exhibitionId) {
Exhibition exhibition = exhibitionRepository.findById(exhibitionId)
.orElseThrow(() -> new NotFoundExhibitionException());

List<ExhibitionArtwork> all = exhibitionArtworkRepository.findAllByExhibitionId(exhibitionId);
List<ArtworkResponseDTO> artworkResponseDTOS = all.stream()
.map(ExhibitionArtwork::getArtwork)
.map(ArtworkResponseDTO::from)
.collect(Collectors.toList());

return ExhibitionArtworksResponseDTO.from(exhibition, artworkResponseDTOS);
}

public ExhibitionArtworkResponseDTO updateStatusExhibitionArtwork(Long exhibitionId, Long artworkId, String status) {
ExhibitionArtwork exhibitionArtwork = exhibitionArtworkRepository.findByExhibitionIdAndArtworkId(exhibitionId, artworkId)
.orElseThrow(() -> new NotFoundException("존재하지 않는 공모전 또는 작품입니다."));

exhibitionArtwork.updateStatus(status);

return ExhibitionArtworkResponseDTO.from(exhibitionArtwork);
}

@Transactional
public void deleteExhibitionArtwork(Long exhibitionId, Long artworkId, String username) {
ExhibitionArtwork exhibitionArtwork = exhibitionArtworkRepository.findByExhibitionIdAndArtworkId(exhibitionId, artworkId)
.orElseThrow(() -> new NotFoundException("존재하지 않는 공모전 또는 작품입니다."));

if (!exhibitionArtwork.getArtwork().getMember().getUsername().equals(username)) {
throw new RuntimeException("아트워크의 작성자가 아닙니다.");
}

exhibitionArtworkRepository.delete(exhibitionArtwork);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit fa6f890

Please sign in to comment.