Skip to content

Commit

Permalink
refactor: PostService 에러코드 수정 (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschoi-96 authored Feb 19, 2024
1 parent bac8179 commit a98a5f0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public LoginSuccessDto login(final LoginDto loginDto) {
@Transactional(readOnly = true)
public MemberResponseDto findById(Long id) {
Member member = memberRepository.findById(id)
.orElseThrow(() -> new BalanceTalkException(ErrorCode.NOT_FOUND_MEMBER_INFORMATION));
.orElseThrow(() -> new BalanceTalkException(ErrorCode.NOT_FOUND_MEMBER));
return MemberResponseDto.fromEntity(member);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/balancetalk/module/member/dto/JoinDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import balancetalk.module.member.domain.Member;
import balancetalk.module.member.domain.Role;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -11,6 +13,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class JoinDto {

private String nickname;
private String email;
private String password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import balancetalk.module.post.dto.PostRequestDto;
import balancetalk.module.post.dto.PostResponseDto;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
import balancetalk.module.post.dto.PostResponseDto;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -34,7 +31,7 @@ public class PostService {
public Post save(final PostRequestDto postRequestDto) {

Member member = memberRepository.findById(postRequestDto.getMemberId())
.orElseThrow();
.orElseThrow(() -> new BalanceTalkException(NOT_FOUND_MEMBER));

Post postEntity = postRequestDto.toEntity(member);

Expand Down Expand Up @@ -62,14 +59,13 @@ public List<PostResponseDto> findAll() {
@Transactional(readOnly = true)
public PostResponseDto findById(Long postId) {
Post post = postRepository.findById(postId)
.orElseThrow(() -> new NoSuchElementException("해당 post를 찾을 수 없습니다."));
.orElseThrow(() -> new BalanceTalkException(NOT_FOUND_POST));
return PostResponseDto.fromEntity(post);
}

public void deleteById(Long postId) {
Post post = postRepository.findById(postId)
.orElseThrow(() -> new NoSuchElementException("게시글 삭제 실패"));
// todo: 에러 추가
.orElseThrow(() -> new BalanceTalkException(NOT_FOUND_POST));
postRepository.deleteById(postId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void readCommentsByPostId_Fail_PostNotFound() {
assertThatThrownBy(() -> commentService.findAll(postId))
.isInstanceOf(BalanceTalkException.class)
.hasMessageContaining("존재하지 않는 게시글입니다.");
}
@DisplayName("사용자가 특정 댓글에 추천을 누르면 해당 댓글 id가 반환된다.")
void createCommentLike_Success() {
// given
Expand Down

0 comments on commit a98a5f0

Please sign in to comment.