Skip to content

Commit

Permalink
✅ Feat #71 : 유저 정보 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 committed Aug 20, 2023
1 parent 76e69b7 commit 9f367d5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingCommentLikeRepository;
import com.umc.DongnaeFriend.domain.dongnae.entity.DongnaeCommentLike;
import com.umc.DongnaeFriend.domain.user.entity.User;
import com.umc.DongnaeFriend.domain.user.repository.UserRepository;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class SharingCommentLikeService {
private final SharingCommentLikeRepository sharingCommentLikeRepository;
private final UserRepository userRepository;


public String newLike(Long commentId) {
// !임시! 유저 가져오기
User user = sharingCommentLikeRepository.findByUserId(1L);

User user = findUser();

// 댓글 가져오기
SharingComment sharingComment = sharingCommentLikeRepository.findByCommentId(commentId);
Expand All @@ -38,4 +44,10 @@ public String newLike(Long commentId) {

return "가계부 공유 댓글 좋아요 삭제 성공";
}

public User findUser() {
Object userId = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return userRepository.findById((Long) userId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingComment;
import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingCommentRepository;
import com.umc.DongnaeFriend.domain.user.entity.User;
import com.umc.DongnaeFriend.domain.user.repository.UserRepository;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -15,10 +19,11 @@
@Service
public class SharingCommentService {
private final SharingCommentRepository sharingCommentRepository;
private final UserRepository userRepository;

public String newComment(Long accountBookId, ReqSharingCommentDto reqSharingCommentDto) {
// !임시! 유저 가져오기
User user = sharingCommentRepository.findByUserId(1L);

User user = findUser();

// 게시판 가져오기
SharingBoard sharingBoard = sharingCommentRepository.findBySharingBoardId(accountBookId);
Expand Down Expand Up @@ -91,4 +96,10 @@ public ReqSharingCommentDto.CommentListResponse getList(Long accountBookId) {
return ReqSharingCommentDto.CommentListResponse.of(list);
}


public User findUser() {
Object userId = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return userRepository.findById((Long) userId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
import com.umc.DongnaeFriend.domain.account.sharing.entity.SharingSympathy;
import com.umc.DongnaeFriend.domain.account.sharing.repository.SharingSympathyRepository;
import com.umc.DongnaeFriend.domain.user.entity.User;
import com.umc.DongnaeFriend.domain.user.repository.UserRepository;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class SharingSympathyService {
private final SharingSympathyRepository sharingSympathyRepository;
private final UserRepository userRepository;


public String newSympathy(Long accountBookId){
// !임시! 유저 가져오기
User user = sharingSympathyRepository.findByUserId(1L);
User user = findUser();

// 게시판 가져오기
SharingBoard sharingBoard = sharingSympathyRepository.findBySharingBoardId(accountBookId);
Expand All @@ -40,4 +45,9 @@ public String newSympathy(Long accountBookId){
return "[가계부 공유] 공감 삭제 성공";
}

public User findUser() {
Object userId = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return userRepository.findById((Long) userId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import com.umc.DongnaeFriend.domain.dongnae.respository.DongnaeCommentLikeRepository;
import com.umc.DongnaeFriend.domain.dongnae.respository.DongnaeCommentRepository;
import com.umc.DongnaeFriend.domain.user.entity.User;
import com.umc.DongnaeFriend.domain.user.repository.UserRepository;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;
Expand All @@ -19,11 +23,11 @@
public class DongnaeCommentService {
private final DongnaeCommentRepository dongnaeCommentRepository;
private final DongnaeCommentLikeRepository dongnaeCommentLikeRepository;
private final UserRepository userRepository;


public String newComment(Long townInformationId, DongnaeCommentDto dongnaeCommentDto) {
// !임시! 유저 가져오기
User user = dongnaeCommentRepository.findByUserId(1L);
User user = findUser();

// 게시판 가져오기
DongnaeBoard dongnaeBoard = dongnaeCommentRepository.findByDongnaeBoardId(townInformationId);
Expand Down Expand Up @@ -86,8 +90,7 @@ public String deleteComment(Long commentId) {
}

public String newLike(Long commentId) {
// !임시! 유저 가져오기
User user = dongnaeCommentRepository.findByUserId(1L);
User user = findUser();

// 댓글 가져오기
Optional<DongnaeComment> dongnaeCommentOptional = dongnaeCommentRepository.findById(commentId);
Expand Down Expand Up @@ -121,4 +124,10 @@ public DongnaeCommentDto.CommentListResponse getList(Long id) {
return DongnaeCommentDto.CommentListResponse.of(list);

}

public User findUser() {
Object userId = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return userRepository.findById((Long) userId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@
import com.umc.DongnaeFriend.domain.scrap.entity.Scrap;
import com.umc.DongnaeFriend.domain.scrap.repository.ScrapRepository;
import com.umc.DongnaeFriend.domain.user.entity.User;
import com.umc.DongnaeFriend.domain.user.repository.UserRepository;
import com.umc.DongnaeFriend.global.exception.CustomException;
import com.umc.DongnaeFriend.global.exception.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class ScrapService {
private final ScrapRepository scrapRepository;
private final UserRepository userRepository;

public String newScrap(ReqScrapDto reqScrapDto) {
// !임시! 유저 가져오기
User user = scrapRepository.findByUserId(1L);

User user = findUser();

// 가계부 공유
if (!(reqScrapDto.getAccountBookId() == null)) {
Expand Down Expand Up @@ -66,4 +71,10 @@ else if (!(reqScrapDto.getTownInformationId() == null)) {

return "스크랩 성공";
}

public User findUser() {
Object userId = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return userRepository.findById((Long) userId)
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
}
}

0 comments on commit 9f367d5

Please sign in to comment.