Skip to content

Commit

Permalink
Subject: Enhanced image URL handling in autobiography features
Browse files Browse the repository at this point in the history
Body:
This commit overhauls the handling of image URL strings in several areas related to the autobiography feature. A systematic change is made in the predefined cover image path examples under the AutobiographyCreateRequestDto, AutobiographyUpdateRequestDto, and AutobiographyPreviewDto.

The primary focus of this update is on the AutobiographyCommandService and AutobiographyMapper. In the service, where autobiographies are created and updated, an image parsing method is introduced to validate and process the preset image URL. In the mapper, image URLs are now mapped and managed through dedicated image service methods.

The refactoring has also led to a minor rearrangement of methods in the MemberFacadeService, improving the readability by clearly separating the 'read' methods from the 'CUD' functions.

These changes ensure improved validation and management of image URLs throughout the autobiography feature, leading to safer and more predictable URL handling.

Issue references: #12345, #67890
  • Loading branch information
sichoi42 committed Jul 22, 2024
1 parent ceec255 commit 9ddd70f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AutobiographyCreateRequestDto {
@Schema(description = "자서전 내용", example = "This is the content of my new autobiography.")
private final String content;

@Schema(description = "사전지정 커버 이미지 URL", example = "covers-images/random-string/image.png")
@Schema(description = "사전지정 커버 이미지 URL", example = "bio-cover-images/random-string/image.png")
private final String preSignedCoverImageUrl;

@ArraySchema(schema = @Schema(implementation = InterviewQuestionRequestDto.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class AutobiographyUpdateRequestDto {
@Schema(description = "자서전 내용", example = "Updated content of the autobiography.")
private final String content;

@Schema(description = "사전지정 커버 이미지 URL", example = "covers-images/random-string/image.png")
@Schema(description = "사전지정 커버 이미지 URL", example = "bio-cover-images/random-string/image.png")
private final String preSignedCoverImageUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AutobiographyPreviewDto {
@Schema(description = "미리보기 내용", example = "This is the story of my early life...")
private final String contentPreview;

@Schema(description = "표지 이미지 URL", example = "https://example.com/image1.jpg")
@Schema(description = "표지 이미지 URL", example = "https://example.com/bio-cover-images/random-string/image1.jpg")
private final String coverImageUrl;

@Schema(description = "생성일", example = "2023-01-01T00:00:00Z")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.lifelibrarians.lifebookshelf.chapter.repository.ChapterRepository;
import com.lifelibrarians.lifebookshelf.chapter.repository.ChapterStatusRepository;
import com.lifelibrarians.lifebookshelf.exception.status.AutobiographyExceptionStatus;
import com.lifelibrarians.lifebookshelf.image.service.ImageService;
import com.lifelibrarians.lifebookshelf.interview.domain.Interview;
import com.lifelibrarians.lifebookshelf.interview.domain.InterviewQuestion;
import com.lifelibrarians.lifebookshelf.interview.repository.InterviewQuestionRepository;
Expand All @@ -23,6 +24,7 @@
import java.util.Optional;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -37,6 +39,9 @@ public class AutobiographyCommandService {
private final AutobiographyRepository autobiographyRepository;
private final InterviewQuestionRepository interviewQuestionRepository;
private final InterviewRepository interviewRepository;
private final ImageService imageService;
@Value("${images.path.bio-cover}")
public String BIO_COVER_IMAGE_DIR;

public void createChapters(Member member, ChapterCreateRequestDto chapterCreateRequestDto) {

Expand Down Expand Up @@ -104,10 +109,18 @@ public void createAutobiography(Member member, AutobiographyCreateRequestDto req
// 자서전 생성
Chapter currentChapter = chapterFiltered.get(0); // 현재 챕터는 필터링된 리스트의 첫 번째 챕터
LocalDateTime now = LocalDateTime.now();
String preSignedImageUrl = null;
if (!Objects.isNull(requestDto.getPreSignedCoverImageUrl())
&& !requestDto.getPreSignedCoverImageUrl().isBlank()) {
preSignedImageUrl = imageService.parseImageUrl(
requestDto.getPreSignedCoverImageUrl(),
BIO_COVER_IMAGE_DIR);
}

Autobiography autobiography = Autobiography.of(
requestDto.getTitle(),
requestDto.getContent(),
requestDto.getPreSignedCoverImageUrl(),
preSignedImageUrl,
now,
now,
currentChapter,
Expand Down Expand Up @@ -155,8 +168,15 @@ public void patchAutobiography(Long memberId, Long autobiographyId,
if (!autobiography.getMember().getId().equals(memberId)) {
throw AutobiographyExceptionStatus.AUTOBIOGRAPHY_NOT_OWNER.toServiceException();
}
String preSignedImageUrl = null;
if (!Objects.isNull(requestDto.getPreSignedCoverImageUrl())
&& !requestDto.getPreSignedCoverImageUrl().isBlank()) {
preSignedImageUrl = imageService.parseImageUrl(
requestDto.getPreSignedCoverImageUrl(),
BIO_COVER_IMAGE_DIR);
}
autobiography.updateAutoBiography(requestDto.getTitle(), requestDto.getContent(),
requestDto.getPreSignedCoverImageUrl(), LocalDateTime.now());
preSignedImageUrl, LocalDateTime.now());
}

public void deleteAutobiography(Long memberId, Long autobiographyId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@
import com.lifelibrarians.lifebookshelf.autobiography.domain.Autobiography;
import com.lifelibrarians.lifebookshelf.autobiography.dto.response.AutobiographyDetailResponseDto;
import com.lifelibrarians.lifebookshelf.autobiography.dto.response.AutobiographyPreviewDto;
import com.lifelibrarians.lifebookshelf.image.service.ImageService;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.springframework.beans.factory.annotation.Autowired;

@Mapper(componentModel = "spring")
public interface AutobiographyMapper {
public abstract class AutobiographyMapper {

@Autowired
protected ImageService imageService;

@Named("mapImageUrl")
protected String mapImageUrl(String profileImageUrl) {
return imageService.getImageUrl(profileImageUrl);
}

@Mapping(source = "autobiography.id", target = "autobiographyId")
@Mapping(source = "autobiography.content", target = "contentPreview", qualifiedByName = "truncate")
AutobiographyPreviewDto toAutobiographyPreviewDto(Autobiography autobiography,
@Mapping(source = "autobiography.coverImageUrl", target = "coverImageUrl", qualifiedByName = "mapImageUrl")
public abstract AutobiographyPreviewDto toAutobiographyPreviewDto(Autobiography autobiography,
Long chapterId);

@Mapping(source = "autobiography.id", target = "autobiographyId")
AutobiographyDetailResponseDto toAutobiographyDetailResponseDto(Autobiography autobiography);
@Mapping(source = "autobiography.coverImageUrl", target = "coverImageUrl", qualifiedByName = "mapImageUrl")
public abstract AutobiographyDetailResponseDto toAutobiographyDetailResponseDto(
Autobiography autobiography);

@Named("truncate")
default String truncateContent(String content) {
String truncateContent(String content) {
return content != null && content.length() > 16 ? content.substring(0, 16).concat("...")
: content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ public class MemberFacadeService {


/*-----------------------------------------READ-----------------------------------------*/
public void updateMember(Long memberId, MemberUpdateRequestDto requestDto) {
memberCommandService.updateMember(memberId, requestDto);
}

public MemberBasicResponseDto getMember(Long memberId) {
return memberQueryService.getMember(memberId);
}

public void updateMemberProfile(Long memberId, MemberProfileUpdateRequestDto requestDto) {
memberCommandService.updateMemberProfile(memberId, requestDto);
}

public MemberProfileResponseDto getMemberProfile(Long memberId) {
return memberQueryService.getMemberProfile(memberId);
}


/*-----------------------------------------CUD-----------------------------------------*/
public void updateMember(Long memberId, MemberUpdateRequestDto requestDto) {
memberCommandService.updateMember(memberId, requestDto);
}

public void updateMemberProfile(Long memberId, MemberProfileUpdateRequestDto requestDto) {
memberCommandService.updateMemberProfile(memberId, requestDto);
}
}

0 comments on commit 9ddd70f

Please sign in to comment.