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

2주차 심화과제 #3

Open
wants to merge 1 commit into
base: #2
Choose a base branch
from
Open

2주차 심화과제 #3

wants to merge 1 commit into from

Conversation

onpyeong
Copy link
Collaborator

@onpyeong onpyeong commented Apr 27, 2023

✅ 과제 구현 명세

😊 이런 점이 새로웠어요 / 어려웠어요

  • Optional을 활용하는 방법을 더 잘 알게 되었습니다!

@onpyeong onpyeong self-assigned this Apr 27, 2023
Copy link

@RinRinPARK RinRinPARK left a comment

Choose a reason for hiding this comment

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

수현님 고생하셨어요!!!!👍👍

Comment on lines +51 to +57
if (postId < postList.size()) {
Post updatePost = new Post(
post.getWriter(),
post.getTitle(),
post.getContent(),
postList.get(postId).getLike()
);

Choose a reason for hiding this comment

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

if문 조건에서 아직 DB 구현이 되지 않아서 postId < postList.size()일 때만 수정이 가능하게 코드를 작성해주신걸까요?!
해당 로직에선 postId를 다른 postId로 잘못 입력해도 수정이 가능할 것 같아서요!

Choose a reason for hiding this comment

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

아마 if문으로 postId가 postList의 사이즈보다 작아야 해당 포스트가 존재해서 예외처리 해 주신 것 같아요!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

맞습니다! list 크기를 초과하는 postId가 들어오면 존재하지 않는 게시물이기 때문에 if문을 써줬어요!

Comment on lines +66 to +68
if (postId < postList.size()) {
postList.remove(postId);
return Optional.of(postId);

Choose a reason for hiding this comment

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

여기도 위와 마찬가지로 이렇게 if문을 작성해주신 이유가 궁금합니다!!

Comment on lines +51 to +57
if (postId < postList.size()) {
Post updatePost = new Post(
post.getWriter(),
post.getTitle(),
post.getContent(),
postList.get(postId).getLike()
);

Choose a reason for hiding this comment

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

아마 if문으로 postId가 postList의 사이즈보다 작아야 해당 포스트가 존재해서 예외처리 해 주신 것 같아요!!

postList.set(postId, updatePost);
return Optional.of(postList.get(postId).toString());
}
return Optional.empty();

Choose a reason for hiding this comment

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

Optional.of와 Optional.empty 제가 처음 보는 메서드인데 뭔가 예외처리를 해줄 수 있는 애들 같아서 기능 찾아보고 저도 나중에 예외처리 할 때 사용해보겠습니다ㅎㅎ 예외처리 하는 방법 하나 배워갑니다!!

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

Successfully merging this pull request may close these issues.

3 participants