Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

게시글 CRUD 에러 코드 추가 #83

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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