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

[박유진] 3차 과제 제출 #8

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

u-genuine
Copy link
Member

No description provided.

@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NotNull 애노테이션은 validation이라 DB에 null 조건 안 붙지 않나요??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Column(name = "title", nullable = false) 으로 설정하면 DB 내부 시스템에서 null 설정을 바꿀 수 있을 것 같아요!

public class SavePostRequest {
String title;
String content;
String name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validation은 controller로 오는 이 Request에 넣어주시면 좋을 거 같아요!

.postList(postPreviewList)
.build();

}catch (Exception e){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 try catch는 어떤 예외를 잡으려고 넣어주신 걸까요?!

}
}

public PostListResponse.PostPreviewList getPostList(Integer page){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전역에 @Transactional을 붙여주시고 읽기만하는 메서드에는 @Transactional(readOnly = true)를 따로 안 붙여주시는군요! db 종류에 따라 조금씩 다르지만 readOnly가 true이고 false일 때 서로 성능 차이가 난다는 것을 아시나요?
이에 대한 레퍼런스 첨부합니다!
https://willseungh0.tistory.com/75

.views(post.getViews())
.build();

} catch (Exception e){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 ApiException을 catch해서 다시 ApiException을 던지는 지 모르겠습니다!

혹시 Excel 메서드에서 제가 그렇게 만들어서 따라하신거면 로직에 오해가 있으셨던 거 같습니다.
저는 ExcelRead에서 발생할 수 있는 IOExcpetion, InvalidFormatException, `NullPointerException'등을 한번에 처리하기 위해서 Exception을 캐치하고 제가 만든 ApiException을 던진 거 였어요!
(즉 GlobalExceptionHandler에서 저 세 Exception을 각각 처리하는 로직을 짜기 귀찮아서였죠...)
지금 로직에서 try catch 문은 잘 못 사용되고 있는 거 같습니다.
스프링에서의 전역 예외 처리에 대해 이해해보시면 좋을 거 같아요
https://mangkyu.tistory.com/204

Copy link
Member

@yooooonshine yooooonshine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정말 고생하셨습니다!
유진님의 꼼꼼함이 돋보였습니다

Copy link
Member

@gikhoon gikhoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Column(name = "title", nullable = false) 으로 설정하면 DB 내부 시스템에서 null 설정을 바꿀 수 있을 것 같아요!

.orElseThrow(() -> ApiException.from(ErrorCode.POST_NOT_FOUND));

post.setViews(post.getViews() + 1);
postRepository.save(post);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 post entity는 JPA로 관리돼 영속성 컨택스트이기 때문에 따로 save하지 않아도 업데이트가 자동으로 DB에 적용됩니다!

https://velog.io/@seongwon97/Spring-Boot-%EC%98%81%EC%86%8D%EC%84%B1-%EC%BB%A8%ED%85%8D%EC%8A%A4%ED%8A%B8Persistence-Context

Post post = postRepository.findById(postId)
.orElseThrow(() -> ApiException.from(ErrorCode.POST_NOT_FOUND));

post.setViews(post.getViews() + 1);
Copy link
Member

@gikhoon gikhoon Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엔티티에 setter를 통해 데이터를 변경하는 것 보다 post.increaseViews() 이런 식으로 처리하면 뷰를 증가시키는 역할이 Service에서 Post로 이동돼 객체 지향적 설계가 가능할 것 같아요!


@Getter
@Builder
public class PostDetailResponse {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java17부터 불변객체임을 증명해주고 효율적으로 코드를 짤 수 있는 record 클래스라는게 있어요!
한번 공부해보시면 좋을 것 같아요.

레퍼런스: https://s7won.tistory.com/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants