-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
609 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...com/ajou/hertz/domain/instrument/exception/InstrumentDeletePermissionDeniedException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.ajou.hertz.domain.instrument.exception; | ||
|
||
import com.ajou.hertz.common.exception.ForbiddenException; | ||
import com.ajou.hertz.common.exception.constant.CustomExceptionType; | ||
|
||
public class InstrumentDeletePermissionDeniedException extends ForbiddenException { | ||
|
||
public InstrumentDeletePermissionDeniedException() { | ||
super(CustomExceptionType.INSTRUMENT_DELETE_PERMISSION_DENIED); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/ajou/hertz/domain/instrument/repository/InstrumentImageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package com.ajou.hertz.domain.instrument.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.ajou.hertz.domain.instrument.entity.InstrumentImage; | ||
|
||
public interface InstrumentImageRepository extends JpaRepository<InstrumentImage, Long> { | ||
|
||
List<InstrumentImage> findAllByInstrument_Id(Long instrumentId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentImageCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.ajou.hertz.domain.instrument.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.ajou.hertz.common.file.service.FileService; | ||
import com.ajou.hertz.domain.instrument.entity.Instrument; | ||
import com.ajou.hertz.domain.instrument.entity.InstrumentImage; | ||
import com.ajou.hertz.domain.instrument.repository.InstrumentImageRepository; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class InstrumentImageCommandService { | ||
|
||
private static final String INSTRUMENT_IMAGE_UPLOAD_PATH = "instrument-image/"; | ||
|
||
private final InstrumentImageQueryService instrumentImageQueryService; | ||
private final FileService fileService; | ||
private final InstrumentImageRepository instrumentImageRepository; | ||
|
||
/** | ||
* 전달받은 multipart files로 instrument image entity를 생성 후 저장한다. | ||
* | ||
* @param instrument 이미지의 대상이 되는 instrument entity | ||
* @param images 저장하고자 하는 image | ||
* @return 저장된 instrument images | ||
*/ | ||
public List<InstrumentImage> saveImages(Instrument instrument, Iterable<MultipartFile> images) { | ||
List<InstrumentImage> instrumentImages = fileService | ||
.uploadFiles(images, INSTRUMENT_IMAGE_UPLOAD_PATH) | ||
.stream() | ||
.map(fileDto -> InstrumentImage.create( | ||
instrument, | ||
fileDto.getOriginalName(), | ||
fileDto.getStoredName(), | ||
fileDto.getUrl() | ||
)).toList(); | ||
return instrumentImageRepository.saveAll(instrumentImages); | ||
} | ||
|
||
/** | ||
* 특정 악기 매물의 모든 이미지를 삭제한다. | ||
* | ||
* @param instrumentId 이미지를 전체 삭제할 악기 매물의 id | ||
*/ | ||
public void deleteAllByInstrumentId(Long instrumentId) { | ||
List<InstrumentImage> instrumentImages = instrumentImageQueryService.findAllByInstrumentId(instrumentId); | ||
fileService.deleteAll( | ||
instrumentImages.stream() | ||
.map(InstrumentImage::getStoredName) | ||
.toList() | ||
); | ||
instrumentImageRepository.deleteAll(instrumentImages); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/ajou/hertz/domain/instrument/service/InstrumentImageQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.ajou.hertz.domain.instrument.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.ajou.hertz.domain.instrument.entity.InstrumentImage; | ||
import com.ajou.hertz.domain.instrument.repository.InstrumentImageRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Service | ||
public class InstrumentImageQueryService { | ||
|
||
private final InstrumentImageRepository instrumentImageRepository; | ||
|
||
/** | ||
* 악기 id를 전달받고, 해당하는 악기의 이미지를 전부 조회한다. | ||
* | ||
* @param instrumentId 이미지를 조회하고자 하는 악기의 id | ||
* @return 조회된 Instrument image entity list | ||
*/ | ||
public List<InstrumentImage> findAllByInstrumentId(Long instrumentId) { | ||
return instrumentImageRepository.findAllByInstrument_Id(instrumentId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.