-
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
피드리스트를 받기 위한 UseCase, Entities,Repository를 정의했습니다. #4
Conversation
let likeCount: Int | ||
let createdAt: Date |
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.
likeCount가 없을 땐 0으로 가져가는건가요? nullable한 값을 가지지 않는건지 궁금해요. (likeCount 외에 다른 값들도 전부 required네요)
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.
넵 likeCount가 없을때는 0으로 가져갑니다!
case coffee | ||
case dessert |
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.
외에는 더 없나요?
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.
넵 일단은 커피와 디저트만 생각하고 있습니다!
import RxSwift | ||
|
||
protocol FetchFeedListUseCase { | ||
func execute() -> Observable<Result<[Recipe], Error>> |
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.
옵저버블로 반환하는 이유가 있을까요?
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.
RxSwift를 사용해 비동기로 서버에서 받아온 데이터를 처리하려고 반환시켜보았습니다.
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.
Observable, Single 차이
import RxSwift | ||
|
||
protocol FeedListRepository { | ||
func fetchRecipes() -> Observable<[Recipe]> |
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.
옵저버블 자체로 반환하는 이유가 있을가요?
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.
서버에서 api 통신을 해서 Observable 자체로 return 시켜 비동기적으로 데이터를 처리해 보고 싶어서 사용했습니다
let statusCode: Int | ||
let message: String | ||
let data: [RecipeDTO] |
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.
이건 공통적으로 네트워킹에 사용하는 DTO 인 것 같은데, 네트워크 레이어에서 따로 관리하는건 어때요?
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.
8afc27b
따로 분리 시켜두었습니다
let recipeId: Int | ||
let recipeType: String | ||
let recipeName: String | ||
let recipeDescription: String | ||
let recipeLikesCnt: Int |
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.
단순 의견) 전부 prefix로 recipe가 붙어있네요. Recipe DTO라서 불필요하지 않을까 싶은데 검토 부탁드릴게요.
필수) Id는 ID 로 작성 부탁드려요.
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.
56c5ae6
prefix를 제거 하였습니다!
let recipeDescription: String | ||
let recipeLikesCnt: Int | ||
let createdAt: String | ||
let writer: UserDTO |
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.
userDTO는 따로 파일을 분리하는게 어떠신가요?
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.
userDTO는 따로 분리 시켜 두었습니다!
let recipeImgUrls: [RecipeImageDTO] | ||
} | ||
|
||
struct RecipeImageDTO: Decodable { |
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.
이미지DTO도 따로 분리되면 다른 곳에서 image를 내려 받을 때 재사용할 수 있을 것 같아요.
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.
56c5ae6
이미지 DTO 따로 분리 시켰습니다
func toDomain() -> Recipe { | ||
return Recipe( | ||
id: recipeId, | ||
type: RecipeType(rawValue: recipeType) ?? .dessert, |
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.
type의 기본값이 dessert인가요?
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.
56c5ae6
coffee로 변경시켰습니다!
|
||
import Foundation | ||
|
||
struct RecipesResponseDTO: Decodable { |
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.
레시피가 아니라 아예 네트워크 레이어의 공통 구조체로 분리하는게 어떠냐는 이야기였어요.
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.
d86703c
네이밍 변경했습니다
type: RecipeType(rawValue: recipeType) ?? .dessert, | ||
name: recipeName, | ||
description: recipeDescription, | ||
id: ID, |
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.
ID만 있을 때는 id로 써도 돼요, 하지만 camel Case로 작성할 때는 fooID 식으로 d까지 대문자로 써달라는 이야기였어요.
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.
fa80af1
id로 다시 변경했습니다
import Foundation | ||
|
||
struct RecipeImageDTO: Decodable { | ||
let recipeImgId: Int |
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.
이런 경우에 recipeImgID로 D까지 대문자로 쓰는게 일반적이에요~
또한 swift Naming convention에 맞춰서 왠만하면 줄임말은 지양해주세요.
img -> image
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.
fa80af1
변경했습니다
|
isLiked: false, | ||
hasBeenLiked: false, |
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.
"내가(작성자가)" 좋아요했다가 느껴지지 않아서 여전히 모호해보여요
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.
b7981cc
isLikedByCurrentUser 로 네이밍 변경했습니다!
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.
hasBeenLiked 만 다시 고민해주세요. 일단 선 승인 해둘게요.
네이밍이 크리티컬한 부분은 아니라서, 변경 후 머지하고 다음 작업 해주시면 될 것 같아요
Quality Gate passedIssues Measures |
피드리스트를 받기 위한 Entity와 UseCase,Repository를 정의해보았습니다.
UseCase에서는 RxSwift를 사용하여 비동기적으로 데이터를 처리했습니다. 성공할 경우 map 연산자를 사용하여 .success를 반환하고, 실패할 경우 catch 연산자를 사용해 오류를 잡아내고 .just(.failure(error))를 반환합니다. 여기서 just를 사용한 이유는 단일 값인 error를 방출하고 Observable을 완료시키기 위해서입니다.
서버로부터 받은 JSON 데이터를 어떻게 디코딩하고 도메인 모델로 변환할지 고민한 끝에, DTO(Data Transfer Object)를 도입하고, 확장 메서드 toDomain()을 통해 변환 로직을 작성했습니다.