-
Notifications
You must be signed in to change notification settings - Fork 0
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
Network [#93] 게시물 좋아요, 좋아요 취소 버튼 API 연결 #99
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
너무너무 고생많으셨습니다!1아요 화이팅!!
@@ -1150,6 +1185,7 @@ | |||
2A8D70CA2B4D9787009F4C6C /* IntroductionView.swift in Sources */, | |||
2A8D70CA2B4D9787009F4C6C /* IntroductionView.swift in Sources */, | |||
3C6193172B3A7A7B00220CEB /* UIStackView+.swift in Sources */, | |||
2A73415C2B58534400F65FD0 /* ContentLikeRequestDTO.swift in Sources */, | |||
2AF069B02B518B3F00CA3E48 /* UICollectionViewRegisterable.swift in Sources */, | |||
2A0A730A2B541555004478C1 /* HttpMethod.swift in Sources */, | |||
3CE9C12E2B4C08AE0086E4A3 /* WriteTextView.swift in Sources */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 코드 패치는 몇 가지 파일 및 그룹을 추가하고 수정하는 것 같습니다.
주로 다음 사항을 확인할 필요가 있습니다:
-
파일 추가:
ContentLikeRequestDTO.swift
파일이 추가되었습니다. 해당 파일이 올바르게 추가되었는지 확인해야 합니다. -
그룹 수정:
ContentLike
그룹이 추가되었으며,DTO
및ResponseDTO
서브 그룹도 추가되었습니다. 이 변경사항이 의도한 대로 이루어졌는지 확인해야 합니다. -
Build 파일 참조: 새로운 파일인
ContentLikeRequestDTO.swift
에 대한 Build 파일 참조(PBXBuildFile
)가 생성되었습니다. 이것도 올바른지 확인해야 합니다.
위의 모든 수정이 원래 의도된 바와 일치하는지 확인하십시오. 또한 모든 파일 및 그룹 경로에 문제가 있는지 점검하고, 변경사항이 애플리케이션의 일부 기능을 제대로 동작하지 않도록 하거나 충돌을 일으키지 않는지 확인하십시오.
self.destinationViewController.contentId = viewModel.postData[indexPath.row].contentId | ||
|
||
let destinationViewController = PostViewController(viewModel: PostViewModel(networkProvider: NetworkService())) | ||
destinationViewController.contentId = viewModel.postData[indexPath.row].contentId | ||
self.navigationController?.pushViewController(destinationViewController, animated: true) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드 리뷰 요청하신 내용에 대해 다음은 제안드립니다:
- 코드 수정 사항:
- 27번 줄:
destinationViewController
를 직접 생성하지 않고,collectionView(_:didSelectItemAt:)
메서드에서 필요할 때만 생성하도록 변경해주세요. - 85~89번 줄:
viewWillDisappear(_:)
메서드에 있는self.navigationController?.navigationBar.isHidden = false
코드부분을 주석 처리하거나 삭제해주세요. 이 코드는 바로 직전의 화면이 표시되기 전에 실행되므로, 다음 뷰 컨트롤러의 네비게이션 바가 숨겨지지 않게 됩니다.
- 개선 사항:
bindViewModel()
메서드:HomeViewModel.Input
객체를 생성할 때likeButtonTapped
에nil
을 전달합니다. 이 부분을 수정하여likeButtonTapped
을 올바른 값을 가지도록 해주세요.output.toggleLikeButton
에서 값을 받아와 처리하는 부분을 확인할 필요가 있습니다. 현재는 값을print
하는 것으로 보이는데, 이외의 추가적인 로직이 필요하다면 해당 부분을 수정해주어야 합니다.
postLikeButtonAPI(isClicked:contentId:)
메서드:- 현재 구현된 상태로는
likeButtonTapped
이 항상Just(())
로 생성됩니다. 이렇게 되면 버튼을 클릭할 때마다 네트워크 요청이 계속해서 발생합니다.Just(())
를 적절한 트리거나 액션으로 변경하여 정확한 동작을 할 수 있도록 해주세요.
- 현재 구현된 상태로는
위의 사항들을 검토하시고 코드에 반영해보시길 권장드립니다.
return data | ||
} | ||
} | ||
|
||
func postDownTransparency(accessToken: String, alarmTriggerType: String, targetMemberId: Int, alarmTriggerId: Int) async throws -> BaseResponse<EmptyResponse>? { | ||
do { | ||
let result: BaseResponse<EmptyResponse>? = try await |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 코드 패치에는 몇 가지 변경 사항과 개선 제안 사항이 있습니다:
viewUpdate
와likeButtonTapped
의 타입을 optional로 변경했습니다.isLikeButtonClicked
를 초기화하지 않고 선언하여 기본값을 false로 설정했습니다.toggleLikeButton
을Output
구조체에 추가하고, 해당 Publisher를 반환하도록transform(from:cancelBag:)
메서드를 업데이트했습니다.likeButtonTapped
에 대한 sink 블록을 추가하여postLikeButtonAPI
및postUnlikeButtonAPI
를 호출하도록 하였습니다.likeButtonTapped
데이터를 기준으로 API 호출을 처리하고, 결과에 따라toggleLikeButton
에 새 값을 보내는 로직을 추가했습니다.
잠재적인 버그는 코드가 부분적으로 전달되어서 파악하기 어렵지만, 내용이 일관성 있고 안전해 보입니다. 그러나 API 호출에 대한 오류 처리를 논리적으로 수행하는지 확인하는 것이 좋습니다. 예외 처리에 대한 주석이 제공되었으면 더 도움이 될 것입니다.
이러한 수정 사항은 코드의 가독성과 유지 관리를 개선할 수 있습니다. 그러나 추가적인 정보나 완전한 코드 스니펫이 제공된다면 더 정확하고 포괄적인 검토를 제공할 수 있습니다.
@@ -340,6 +359,7 @@ extension PostViewController { | |||
self.postView.timeLabel.text = data.time.formattedTime() | |||
self.postView.likeNumLabel.text = "\(data.likedNumber)" | |||
self.postView.commentNumLabel.text = "\(data.commentNumber)" | |||
postView.likeButton.setImage(data.isLiked ? ImageLiterals.Posting.btnFavoriteActive : ImageLiterals.Posting.btnFavoriteInActive, for: .normal) | |||
self.memberId = data.memberId | |||
|
|||
if self.memberId == loadUserData()?.memberId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 코드 패치의 간단한 코드 리뷰를 도와드리겠습니다. 버그 위험과 개선 제안을 언급하겠습니다:
버그 위험:
deletePostPopupVC
변수가 중복으로 선언되어 있습니다. 하나의 삭제 팝업 뷰 컨트롤러만 필요한 것으로 보입니다.likeButtonTapped
은throttle
연산자를 사용하여 2초에 한 번만 게시됩니다. 이 경우, 사용자가 2초마다 여러 번 버튼을 누를 수 있게끔 변경하려면.latest
대신.debounce
연산자를 사용하는 것이 좋습니다.
개선 제안:
private lazy var ghostButton = postView.ghostButton
은 지역 변수ghostButton
을 생성해서 사용해도 될 것 같습니다.let input = PostViewModel.Input(viewUpdate: Just((contentId)).eraseToAnyPublisher(), collectionViewUpdata: Just((contentId)).eraseToAnyPublisher(), likeButtonTapped: likeButtonTapped)
은Just(contentId)
대신Just(contentId).eraseToAnyPublisher()
으로 작성할 수 있습니다.output.toggleLikeButton
에서 이미지 업데이트 및 좋아요 수 업데이트 부분은 상당히 중복되므로, 이들을 의미 있는 메소드 또는 함수로 추출하여 코드 재사용성을 높이는 것이 좋습니다.
위의 코드 리뷰를 참고하여 코드를 개선해보시기 바랍니다.
} catch { | ||
return nil | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위의 코드 패치에 대한 간단한 코드 검토를 도와드리겠습니다. 버그 위험과/또는 개선 제안사항이 있다면 환영합니다.
-
toggleLikeButton
과isLikeButtonClicked
가 추가되었습니다. 이러한 토글 관련 변수들을 사용하여 좋아요 버튼 클릭 여부를 추적하는 것은 좋은 접근 방식입니다. -
likeButtonTapped
프로퍼티를 포함한Input
구조체가 추가되었습니다. 사용자가 좋아요 버튼을 탭할 때 이벤트를 처리하는 데 사용됩니다. -
toggleLikeButton
프로퍼티를 포함한Output
구조체가 추가되었습니다. 이것은 좋아요 버튼 상태에 대한 업데이트를 다른 부분에서 처리하는 데 사용됩니다. -
likeButtonTapped
Publisher를 구독하여 좋아요 버튼 클릭 이벤트를 처리하고 API 요청을 보내는 로직이 추가되었습니다. 이 부분은 리액티브한 방식으로 작성되어 좋아요 버튼 상태를 업데이트하고,isLikeButtonClicked
및toggleLikeButton
을 변경하여 UI에 변화를 전달합니다. -
postLikeButtonAPI
및postUnlikeButtonAPI
메서드가 추가되었습니다. 이들은 좋아요 버튼 클릭 및 취소에 대한 API 요청을 처리합니다. -
전반적으로 코드의 구조와 로직은 깔끔하게 작성되어 있습니다.
👻 PULL REQUEST
💻 작업한 내용
💡 참고사항
📸 스크린샷
📟 관련 이슈