Skip to content

Commit

Permalink
feat: 외부아이디 리캡생성시 받기
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Dec 13, 2024
1 parent e6a53eb commit b1d2932
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import kr.mafoo.photo.domain.enums.AlbumType;
import kr.mafoo.photo.domain.enums.BrandType;
import kr.mafoo.photo.exception.*;
import kr.mafoo.photo.repository.AlbumRepository;
import kr.mafoo.photo.repository.SumoneEventMappingRepository;
import kr.mafoo.photo.service.AlbumCommand;
import kr.mafoo.photo.service.AlbumQuery;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class SumoneController {
private final RecapService recapService;
private final RecapLambdaService recapLambdaService;
private final SumoneEventMappingRepository sumoneEventMappingRepository;
private final AlbumRepository albumRepository;

@Operation(summary = "통계 api")
@GetMapping("/summary")
Expand All @@ -58,21 +60,10 @@ public Mono<SumoneSummaryResponse> getSummary() {
@Transactional
@Operation(summary = "앨범 생성 api")
@PostMapping("/albums")
public Mono<SumoneAlbumResponse> createAlbum(
@RequestBody SumoneAlbumCreateRequest request
) {
if(request.userId() == null || request.userId().isEmpty()) {
return Mono.error(new DomainException(ErrorCode.REQUEST_INPUT_NOT_VALID));
}

return sumoneEventMappingRepository
.findById(request.userId())
.switchIfEmpty(sumoneEventMappingRepository.save(SumoneEventMappingEntity.newEventMember(
request.userId(),
RandomCodeGenerator.generateAlphanumericString(8)
)))
.then(albumCommand.addAlbum(sumoneAlbumCommonName, "SUMONE", sumoneAlbumCommonMemberId, "SUMONE_" + request.userId())
.map(SumoneAlbumResponse::fromEntity));
public Mono<SumoneAlbumResponse> createAlbum() {
return albumCommand
.addAlbum(sumoneAlbumCommonName, "SUMONE", sumoneAlbumCommonMemberId, null)
.map(SumoneAlbumResponse::fromEntity);
}

@Operation(summary = "앨범에 이미지 url 추가")
Expand Down Expand Up @@ -139,15 +130,26 @@ Mono<RecapUrlDto> createRecapVideo(
@RequestBody
SumoneRecapCreateRequest request
) {
if(request.fileUrls().size() < 1 || request.fileUrls().size() > 10) {
if(request.fileUrls().isEmpty() || request.fileUrls().size() > 10) {
return Mono.error(new RecapPhotoCountNotValidException());
}
if(request.userId() == null || request.userId().isEmpty()) {
return Mono.error(new DomainException(ErrorCode.REQUEST_INPUT_NOT_VALID));
}
return albumQuery.findById(albumId).flatMap(album -> {
if(album.getType() != AlbumType.SUMONE) {
return Mono.error(new AlbumNotFoundException());
}
//TODO: add timeout
return recapLambdaService.generateVideo(request.fileUrls());

return sumoneEventMappingRepository
.findById(request.userId())
.switchIfEmpty(sumoneEventMappingRepository.save(SumoneEventMappingEntity.newEventMember(
request.userId(),
RandomCodeGenerator.generateAlphanumericString(8)
)))
.then(albumRepository.save(album.setExternalId("SUMONE_" + request.userId())))
.then(recapLambdaService.generateVideo(request.fileUrls()));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public record SumoneRecapCreateRequest(
schema = @Schema(description = "파일 URL 목록"),
arraySchema = @Schema(example = "[\"file_url_1\", \"file_url_2\", \"file_url_3\"]")
)
List<String> fileUrls
List<String> fileUrls,

@Schema(description = "썸원 유저ID")
String userId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public AlbumEntity decreasePhotoCount(int count) {
return this;
}

public AlbumEntity setExternalId(String externalId) {
this.externalId = externalId;
return this;
}

public static AlbumEntity newAlbum(String albumId, String albumName, AlbumType albumType, String ownerMemberId, String externalId) {
AlbumEntity album = new AlbumEntity();
album.albumId = albumId;
Expand Down

0 comments on commit b1d2932

Please sign in to comment.