Skip to content

Commit

Permalink
Merge pull request #87 from Leets-Official/feat#86
Browse files Browse the repository at this point in the history
Feat#86  ๋‹ค์ˆ˜ ๊ฒŒ์‹œ๋ฌผ ์กฐํšŒ ์‹œ ํŒŒ์ผ ์ฒจ๋ถ€ ์—ฌ๋ถ€ ํ‘œ์‹œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
  • Loading branch information
jj0526 authored Dec 19, 2024
2 parents aeb6557 + 0549b0b commit 46cbfca
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jakarta.validation.constraints.NotNull;
import leets.weeth.domain.comment.application.dto.CommentDTO;
import leets.weeth.domain.file.application.dto.request.FileSaveRequest;
import leets.weeth.domain.file.application.dto.request.FileUpdateRequest;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import lombok.Builder;

Expand Down Expand Up @@ -49,7 +48,8 @@ public record ResponseAll(
String title,
String content,
LocalDateTime time,//modifiedAt
Integer commentCount
Integer commentCount,
boolean hasFile
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public record ResponseAll(
String title,
String content,
LocalDateTime time,//modifiedAt
Integer commentCount
Integer commentCount,
boolean hasFile
){}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import leets.weeth.domain.comment.application.mapper.CommentMapper;
import leets.weeth.domain.comment.domain.entity.Comment;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import leets.weeth.domain.file.domain.entity.File;
import leets.weeth.domain.file.domain.service.FileGetService;
import leets.weeth.domain.user.domain.entity.User;
import org.mapstruct.*;

Expand All @@ -24,10 +24,11 @@ public interface NoticeMapper {
Notice fromNoticeDto(NoticeDTO.Save dto, User user);

@Mappings({
@Mapping(target = "name", source = "user.name"),
@Mapping(target = "time", source = "modifiedAt")
@Mapping(target = "name", source = "notice.user.name"),
@Mapping(target = "time", source = "notice.modifiedAt"),
@Mapping(target = "hasFile", expression = "java(fileExists)")
})
NoticeDTO.ResponseAll toAll(Notice notice);
NoticeDTO.ResponseAll toAll(Notice notice, boolean fileExists);

@Mappings({
@Mapping(target = "name", source = "notice.user.name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import leets.weeth.domain.comment.application.mapper.CommentMapper;
import leets.weeth.domain.comment.domain.entity.Comment;
import leets.weeth.domain.file.application.dto.response.FileResponse;
import leets.weeth.domain.file.domain.service.FileGetService;
import leets.weeth.domain.user.domain.entity.User;
import org.mapstruct.*;

Expand All @@ -23,10 +24,12 @@ public interface PostMapper {
Post fromPostDto(PostDTO.Save dto, User user);

@Mappings({
@Mapping(target = "name", source = "user.name"),
@Mapping(target = "time", source = "modifiedAt")
@Mapping(target = "name", source = "post.user.name"),
@Mapping(target = "time", source = "post.modifiedAt"),
@Mapping(target = "hasFile", expression = "java(fileExists)")
})
PostDTO.ResponseAll toAll(Post post);
PostDTO.ResponseAll toAll(Post post, boolean fileExists);


@Mappings({
@Mapping(target = "name", source = "post.user.name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public Slice<NoticeDTO.ResponseAll> findNotices(int pageNumber, int pageSize) {
}
Pageable pageable = PageRequest.of(pageNumber, pageSize, Sort.by(Sort.Direction.DESC, "id")); // id๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ
Slice<Notice> notices = noticeFindService.findRecentNotices(pageable);

return notices.map(mapper::toAll);
return notices.map(notice->mapper.toAll(notice, checkFileExistsByNotice(notice.id)));
}

@Override
Expand Down Expand Up @@ -118,4 +117,8 @@ private Notice validateOwner(Long noticeId, Long userId) {
return notice;
}

public boolean checkFileExistsByNotice(Long noticeId){
return !fileGetService.findAllByNotice(noticeId).isEmpty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public Slice<PostDTO.ResponseAll> findPosts(int pageNumber, int pageSize) {
throw new PageNotFoundException();
}
Pageable pageable = PageRequest.of(pageNumber, pageSize, Sort.by(Sort.Direction.DESC, "id"));
Slice<Post> recentPosts = postFindService.findRecentPosts(pageable);
Slice<Post> posts = postFindService.findRecentPosts(pageable);

return recentPosts.map(mapper::toAll);
return posts.map(post->mapper.toAll(post, checkFileExistsByPost(post.id)));
}

@Override
Expand Down Expand Up @@ -116,4 +116,8 @@ private Post validateOwner(Long postId, Long userId) {
return post;
}

public boolean checkFileExistsByPost(Long postId){
return !fileGetService.findAllByPost(postId).isEmpty();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package leets.weeth.domain.file.domain.service;

import leets.weeth.domain.board.domain.entity.Notice;
import leets.weeth.domain.file.domain.entity.File;
import leets.weeth.domain.file.domain.repository.FileRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,4 +25,5 @@ public List<File> findAllByNotice(Long noticeId) {
public List<File> findAllByReceipt(Long receiptId) {
return fileRepository.findAllByReceiptId(receiptId);
}

}

0 comments on commit 46cbfca

Please sign in to comment.