Skip to content

Commit

Permalink
Merge pull request #102 from hook-killer/fix/100-mypage-mylistPaging
Browse files Browse the repository at this point in the history
[FIX] 마이페이지 페이징 처리
  • Loading branch information
lljh1992 authored Oct 25, 2023
2 parents 50e36a6 + 0f594f3 commit 6ab2896
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/main/java/HookKiller/server/common/AbstractTimeStamp.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class AbstractTimeStamp {
@CreatedDate
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd hh:mm:ss",
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul"
)
private Timestamp createAt;
Expand All @@ -36,7 +36,7 @@ public abstract class AbstractTimeStamp {
@LastModifiedDate
@JsonFormat(
shape = JsonFormat.Shape.STRING,
pattern = "yyyy-MM-dd hh:mm:ss",
pattern = "yyyy-MM-dd HH:mm:ss",
timezone = "Asia/Seoul"
)
private Timestamp updateAt;
Expand Down
60 changes: 39 additions & 21 deletions src/main/java/HookKiller/server/user/service/MyPageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import HookKiller.server.board.dto.ArticleRequestDto;
import HookKiller.server.board.dto.ReplyResponseDto;
import HookKiller.server.board.entity.Article;
import HookKiller.server.board.entity.ArticleLike;
import HookKiller.server.board.entity.Reply;
import HookKiller.server.board.exception.ArticleContentNotFoundException;
import HookKiller.server.board.exception.ReplyContentNotFoundException;
import HookKiller.server.board.repository.ArticleContentRepository;
Expand All @@ -20,12 +23,16 @@
import HookKiller.server.user.entity.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

import static HookKiller.server.common.util.SecurityUtils.passwordEncoder;

@Slf4j
Expand All @@ -52,64 +59,75 @@ public void updateUserInfo(MyPageUserUpdateRequest request) {
// 변경이 존재하는 경우에만 변경한다.
if (request.getPassword() != null && !passwordEncoder.matches(request.getPassword(), user.getPassword()))
user.setPassword(request.getPassword());
if(request.getNickName() != null && !user.getNickName().equals(request.getNickName()))
if (request.getNickName() != null && !user.getNickName().equals(request.getNickName()))
user.setNickName(request.getNickName());
}

@Transactional(propagation = Propagation.REQUIRED)
public CommonBooleanResultResponse updateUserThumbnailPath(MyPageUserUpdateRequest request) {
User user = userUtils.getUser();
log.error("request Thumnail >>> {} , userThumnail >>> {}", request.getThumbnail(), user.getThumbnail());
if(request.getThumbnail() == null)
if (request.getThumbnail() == null)
return CommonBooleanResultResponse.builder().result(false).message("요청 Path가 없습니다.").build();
if(request.getThumbnail().trim().equals(""))
if (request.getThumbnail().trim().equals(""))
return CommonBooleanResultResponse.builder().result(false).message("요청 Path가 없습니다.").build();
if(user.getThumbnail() == null || !request.getThumbnail().equalsIgnoreCase(user.getThumbnail())) {
if (user.getThumbnail() == null || !request.getThumbnail().equalsIgnoreCase(user.getThumbnail())) {
user.setThumbnail(request.getThumbnail());
return CommonBooleanResultResponse.builder().result(true).message("수정이 완료되었습니다.").build();
}
return CommonBooleanResultResponse.builder().result(false).message("동일한 Path라 수정이 불가능합니다.").build();
}



@Transactional(readOnly = true)
public Object getMyCreatedList(int page, int limit, String searchType, LanguageType language) {
public Map<String, Object> getMyCreatedList(int page, int limit, String searchType, LanguageType language) {
User user = userUtils.getUser();
Pageable pageable = PageRequest.of(page, limit);
if(searchType.equalsIgnoreCase("ARTICLE")) {
return articleRepository.findAllByCreatedUserAndArticleStatusOrderByCreateAtDesc(user, ArticleStatus.PUBLIC, pageable)
.stream().map(
article -> ArticleRequestDto.of(article, articleContentRepository
.findByArticleAndLanguage(article, language)
.orElseThrow(() -> ArticleContentNotFoundException.EXCEPTION))
).toList();
Map<String, Object> result = new HashMap<>();

if (searchType.equalsIgnoreCase("ARTICLE")) {
Page<Article> articleResult = articleRepository.findAllByCreatedUserAndArticleStatusOrderByCreateAtDesc(user, ArticleStatus.PUBLIC, pageable);
result.put("totalPage", articleResult.getTotalPages());
result.put("totalElements", articleResult.getTotalElements());
result.put("data", articleResult.stream().map(
article -> ArticleRequestDto.of(article, articleContentRepository
.findByArticleAndLanguage(article, language)
.orElseThrow(() -> ArticleContentNotFoundException.EXCEPTION))
).toList());
return result;
}

if(searchType.equalsIgnoreCase("REPLY")){
return replyRepository.findAllByCreatedUserAndReplyStatusOrderByCreateAtDesc(user, ReplyStatus.USABLE, pageable)
if (searchType.equalsIgnoreCase("REPLY")) {
Page<Reply> replyResult = replyRepository.findAllByCreatedUserAndReplyStatusOrderByCreateAtDesc(user, ReplyStatus.USABLE, pageable);
result.put("totalPage", replyResult.getTotalPages());
result.put("totalElements", replyResult.getTotalElements());
result.put("data", replyResult
.stream()
.map(reply ->
ReplyResponseDto.of(
reply,
replyContentRepository.findByReplyAndLanguage(reply, language)
.orElseThrow(() -> ReplyContentNotFoundException.EXCEPTION)
)
).toList();
).toList());

return result;
}

if(searchType.equalsIgnoreCase("LIKE")) {
return articleLikeRepository
.findAllByUserOrderByCreateAtDesc(user, pageable)
if (searchType.equalsIgnoreCase("LIKE")) {
Page<ArticleLike> likeResult = articleLikeRepository.findAllByUserOrderByCreateAtDesc(user, pageable);
result.put("totalPage", likeResult.getTotalPages());
result.put("totalElements", likeResult.getTotalElements());
result.put("data", likeResult
.map(articleLike -> ArticleRequestDto.of(articleLike.getArticle(), articleContentRepository
.findByArticleAndLanguage(articleLike.getArticle(), language)
.orElseThrow(() -> ArticleContentNotFoundException.EXCEPTION))
).toList();
).toList());
return result;
}

throw BadTypeRequestException.EXCEPTION;
}



}

0 comments on commit 6ab2896

Please sign in to comment.