Skip to content

Commit

Permalink
refactor: FixZone - 이미지 순서 지정 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
5uhwann committed Jan 5, 2025
1 parent 477d211 commit 2c53bc2
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ddingdong.ddingdongBE.domain.fixzone.controller.dto.request;

import ddingdong.ddingdongBE.domain.fixzone.service.dto.command.CreateFixZoneCommand;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.command.CreateFixZoneCommand.ImageInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.List;
Expand All @@ -12,17 +13,28 @@ public record CreateFixZoneRequest(
@NotNull
@Schema(description = "내용")
String content,
@Schema(description = "픽스존 이미지 식별자 목록", example = "[\"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\", \"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\"]")
List<String> fixZoneImageIds
@Schema(description = "픽스존 이미지 정보 목록")
List<ImageInfoRequest> images
) {

public CreateFixZoneCommand toCommand(Long userId) {
return new CreateFixZoneCommand(
userId,
title,
content,
fixZoneImageIds
images.stream()
.map(image -> new ImageInfo(image.id, image.order()))
.toList()
);
}

public record ImageInfoRequest(
@Schema(description = "이미지 식별자", example = "0192c828-ffce-7ee8-94a8-d9d4c8cdec00")
String id,
@Schema(description = "이미지 순서", example = "1")
int order
) {

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ddingdong.ddingdongBE.domain.fixzone.controller.dto.request;

import ddingdong.ddingdongBE.domain.fixzone.service.dto.command.UpdateFixZoneCommand;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.command.UpdateFixZoneCommand.ImageInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.List;
Expand All @@ -12,17 +13,28 @@ public record UpdateFixZoneRequest(
@NotNull
@Schema(description = "내용")
String content,
@Schema(description = "픽스존 이미지 식별자 목록", example = "[\"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\", \"0192c828-ffce-7ee8-94a8-d9d4c8cdec00\"]")
List<String> fixZoneImageIds
@Schema(description = "픽스존 이미지 정보 목록")
List<ImageInfoRequest> images
) {

public UpdateFixZoneCommand toCommand(Long fixZoneId) {
return new UpdateFixZoneCommand(
fixZoneId,
title,
content,
fixZoneImageIds
images.stream()
.map(image -> new ImageInfo(image.id(), image.order()))
.toList()
);
}

public record ImageInfoRequest(
@Schema(description = "이미지 식별자", example = "0192c828-ffce-7ee8-94a8-d9d4c8cdec00")
String id,
@Schema(description = "이미지 순서", example = "1")
int order
) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.AdminFixZoneQuery;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.AdminFixZoneQuery.FixZoneCommentQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlWithOrderQuery;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -54,17 +55,19 @@ public static AdminFixZoneResponse from(AdminFixZoneQuery query) {
description = "어드민 - 픽스존 이미지 URL 조회 응답"
)
record FixZoneImageUrlResponse(
@Schema(description = "이미지 순서", example = "1")
int order,
@Schema(description = "원본 url", example = "url")
String originUrl,
@Schema(description = "cdn url", example = "url")
String cdnUrl
) {

public static FixZoneImageUrlResponse from(UploadedFileUrlQuery query) {
public static FixZoneImageUrlResponse from(UploadedFileUrlWithOrderQuery query) {
if (query == null) {
return null;
}
return new FixZoneImageUrlResponse(query.originUrl(), query.cdnUrl());
return new FixZoneImageUrlResponse(query.order(), query.originUrl(), query.cdnUrl());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.CentralFixZoneQuery;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.CentralFixZoneQuery.FixZoneCommentQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlWithOrderQuery;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -57,17 +58,19 @@ public static CentralFixZoneResponse from(CentralFixZoneQuery query) {
record FixZoneImageUrlResponse(
@Schema(description = "파일 식별자", example = "0192c828-ffce-7ee8-94a8-d9d4c8cdec00l")
String id,
@Schema(description = "이미지 순서", example = "1")
int order,
@Schema(description = "원본 url", example = "url")
String originUrl,
@Schema(description = "cdn url", example = "url")
String cdnUrl
) {

public static FixZoneImageUrlResponse from(UploadedFileUrlQuery query) {
public static FixZoneImageUrlResponse from(UploadedFileUrlWithOrderQuery query) {
if (query == null) {
return null;
}
return new FixZoneImageUrlResponse(query.id(), query.originUrl(), query.cdnUrl());
return new FixZoneImageUrlResponse(query.id(), query.order(), query.originUrl(), query.cdnUrl());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.AdminFixZoneQuery;
import ddingdong.ddingdongBE.file.service.S3FileService;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlWithOrderQuery;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -32,10 +33,11 @@ public List<AdminFixZoneListQuery> getAll() {
@Override
public AdminFixZoneQuery getFixZone(Long fixZoneId) {
FixZone fixZone = fixZoneService.getById(fixZoneId);
List<UploadedFileUrlQuery> imageUrlQueries = fileMetaDataService
List<UploadedFileUrlWithOrderQuery> imageUrlQueries = fileMetaDataService
.getCoupledAllByDomainTypeAndEntityId(DomainType.FIX_ZONE_IMAGE, fixZoneId)
.stream()
.map(fileMetaData -> s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()))
.map(fileMetaData -> UploadedFileUrlWithOrderQuery.of(
s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()), fileMetaData.getOrder()))
.toList();
Club club = fixZone.getClub();
UploadedFileUrlQuery clubProfileImageQuery = fileMetaDataService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import ddingdong.ddingdongBE.domain.club.service.ClubService;
import ddingdong.ddingdongBE.domain.filemetadata.entity.DomainType;
import ddingdong.ddingdongBE.domain.filemetadata.service.FileMetaDataService;
import ddingdong.ddingdongBE.domain.filemetadata.service.dto.FileMetaDataIdOrderDto;
import ddingdong.ddingdongBE.domain.fixzone.entity.FixZone;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.command.CreateFixZoneCommand;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.command.UpdateFixZoneCommand;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.CentralFixZoneQuery;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.CentralMyFixZoneListQuery;
import ddingdong.ddingdongBE.file.service.S3FileService;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlWithOrderQuery;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -32,7 +34,16 @@ public Long create(CreateFixZoneCommand command) {
Club club = clubService.getByUserId(command.userId());
FixZone createdFixZone = command.toEntity(club);
Long createdFixZoneId = fixZoneService.save(createdFixZone);
fileMetaDataService.updateStatusToCoupled(command.fixZoneImageIds(), DomainType.FIX_ZONE_IMAGE, createdFixZoneId);

List<FileMetaDataIdOrderDto> imageFileMetaDataIdOrderDtos = command.imageInfos().stream()
.map(imageInfo -> FileMetaDataIdOrderDto.of(imageInfo.imagId(), imageInfo.order()))
.toList();

fileMetaDataService.updateStatusToCoupledWithOrder(
imageFileMetaDataIdOrderDtos,
DomainType.FIX_ZONE_IMAGE,
createdFixZoneId
);
return createdFixZoneId;
}

Expand All @@ -49,10 +60,11 @@ public List<CentralMyFixZoneListQuery> getMyFixZones(Long userId) {
public CentralFixZoneQuery getFixZone(Long fixZoneId) {
FixZone fixZone = fixZoneService.getById(fixZoneId);
Club club = fixZone.getClub();
List<UploadedFileUrlQuery> imageUrlQueries = fileMetaDataService
List<UploadedFileUrlWithOrderQuery> imageUrlQueries = fileMetaDataService
.getCoupledAllByDomainTypeAndEntityId(DomainType.FIX_ZONE_IMAGE, fixZoneId)
.stream()
.map(fileMetaData -> s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()))
.map(fileMetaData -> UploadedFileUrlWithOrderQuery.of(
s3FileService.getUploadedFileUrl(fileMetaData.getFileKey()), fileMetaData.getOrder()))
.toList();

UploadedFileUrlQuery clubProfileImageKey = fileMetaDataService
Expand All @@ -69,7 +81,10 @@ public CentralFixZoneQuery getFixZone(Long fixZoneId) {
public Long update(UpdateFixZoneCommand command) {
FixZone fixZone = fixZoneService.getById(command.fixZoneId());
fixZone.update(command.toEntity());
fileMetaDataService.update(command.fixZoneImageIds(), DomainType.FIX_ZONE_IMAGE, fixZone.getId());
List<FileMetaDataIdOrderDto> imageFileMetaDataIdOrderDtos = command.imageInfos().stream()
.map(imageInfo -> FileMetaDataIdOrderDto.of(imageInfo.imagId(), imageInfo.order()))
.toList();
fileMetaDataService.updateWithOrder(imageFileMetaDataIdOrderDtos, DomainType.FIX_ZONE_IMAGE, fixZone.getId());
return fixZone.getId();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public record CreateFixZoneCommand(
Long userId,
String title,
String content,
List<String> fixZoneImageIds
List<ImageInfo> imageInfos
) {

public FixZone toEntity(Club club) {
Expand All @@ -20,4 +20,11 @@ public FixZone toEntity(Club club) {
.build();
}

public record ImageInfo(
String imagId,
int order
) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public record UpdateFixZoneCommand(
Long fixZoneId,
String title,
String content,
List<String> fixZoneImageIds
List<ImageInfo> imageInfos
) {

public FixZone toEntity() {
Expand All @@ -17,4 +17,11 @@ public FixZone toEntity() {
.build();
}

public record ImageInfo(
String imagId,
int order
) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ddingdong.ddingdongBE.domain.fixzone.entity.FixZone;
import ddingdong.ddingdongBE.domain.fixzone.entity.FixZoneComment;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlWithOrderQuery;
import java.time.LocalDateTime;
import java.util.List;

Expand All @@ -14,13 +15,13 @@ public record AdminFixZoneQuery(
String content,
boolean isCompleted,
LocalDateTime requestedAt,
List<UploadedFileUrlQuery> imageUrlQueries,
List<UploadedFileUrlWithOrderQuery> imageUrlQueries,
List<FixZoneCommentQuery> fixZoneCommentQueries
) {

public static AdminFixZoneQuery of(
FixZone fixZone,
List<UploadedFileUrlQuery> fixZoneImageUrlQueries,
List<UploadedFileUrlWithOrderQuery> fixZoneImageUrlQueries,
UploadedFileUrlQuery commenterProfileImageUrlQuery) {
return new AdminFixZoneQuery(
fixZone.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ddingdong.ddingdongBE.domain.fixzone.entity.FixZone;
import ddingdong.ddingdongBE.domain.fixzone.entity.FixZoneComment;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery;
import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlWithOrderQuery;
import java.time.LocalDateTime;
import java.util.List;

Expand All @@ -14,13 +15,13 @@ public record CentralFixZoneQuery(
String content,
boolean isCompleted,
LocalDateTime requestedAt,
List<UploadedFileUrlQuery> imageUrlQueries,
List<UploadedFileUrlWithOrderQuery> imageUrlQueries,
List<FixZoneCommentQuery> fixZoneCommentQueries
) {

public static CentralFixZoneQuery of(
FixZone fixZone,
List<UploadedFileUrlQuery> fixZoneImageUrlQueries,
List<UploadedFileUrlWithOrderQuery> fixZoneImageUrlQueries,
UploadedFileUrlQuery commenterProfileImageUrlQuery) {
return new CentralFixZoneQuery(
fixZone.getId(),
Expand Down

0 comments on commit 2c53bc2

Please sign in to comment.