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

피드리스트를 받기 위한 UseCase, Entities,Repository를 정의했습니다. #4

Merged
merged 16 commits into from
Jun 12, 2024

Conversation

GeonH0
Copy link
Collaborator

@GeonH0 GeonH0 commented Jun 10, 2024

피드리스트를 받기 위한 Entity와 UseCase,Repository를 정의해보았습니다.

  • UseCase에서는 RxSwift를 사용하여 비동기적으로 데이터를 처리했습니다. 성공할 경우 map 연산자를 사용하여 .success를 반환하고, 실패할 경우 catch 연산자를 사용해 오류를 잡아내고 .just(.failure(error))를 반환합니다. 여기서 just를 사용한 이유는 단일 값인 error를 방출하고 Observable을 완료시키기 위해서입니다.

  • 서버로부터 받은 JSON 데이터를 어떻게 디코딩하고 도메인 모델로 변환할지 고민한 끝에, DTO(Data Transfer Object)를 도입하고, 확장 메서드 toDomain()을 통해 변환 로직을 작성했습니다.

@GeonH0 GeonH0 force-pushed the feature/feedList branch from f8e0f4a to e9d4af2 Compare June 11, 2024 01:48
Comment on lines +18 to +19
let likeCount: Int
let createdAt: Date

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네요)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 likeCount가 없을때는 0으로 가져갑니다!

Comment on lines +11 to +12
case coffee
case dessert

Choose a reason for hiding this comment

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

외에는 더 없나요?

Copy link
Collaborator Author

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>>

Choose a reason for hiding this comment

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

옵저버블로 반환하는 이유가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RxSwift를 사용해 비동기로 서버에서 받아온 데이터를 처리하려고 반환시켜보았습니다.

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]>

Choose a reason for hiding this comment

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

옵저버블 자체로 반환하는 이유가 있을가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

서버에서 api 통신을 해서 Observable 자체로 return 시켜 비동기적으로 데이터를 처리해 보고 싶어서 사용했습니다

Comment on lines 11 to 13
let statusCode: Int
let message: String
let data: [RecipeDTO]

Choose a reason for hiding this comment

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

이건 공통적으로 네트워킹에 사용하는 DTO 인 것 같은데, 네트워크 레이어에서 따로 관리하는건 어때요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

8afc27b
따로 분리 시켜두었습니다

Comment on lines 17 to 21
let recipeId: Int
let recipeType: String
let recipeName: String
let recipeDescription: String
let recipeLikesCnt: Int

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 로 작성 부탁드려요.

Copy link
Collaborator Author

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

Choose a reason for hiding this comment

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

userDTO는 따로 파일을 분리하는게 어떠신가요?

Copy link
Collaborator Author

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 {

Choose a reason for hiding this comment

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

이미지DTO도 따로 분리되면 다른 곳에서 image를 내려 받을 때 재사용할 수 있을 것 같아요.

Copy link
Collaborator Author

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,

Choose a reason for hiding this comment

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

type의 기본값이 dessert인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

56c5ae6
coffee로 변경시켰습니다!

@GeonH0 GeonH0 changed the title UseCase, Entities,Repository를 정의했습니다. 피드리스트를 받기 위한 UseCase, Entities,Repository를 정의했습니다. Jun 11, 2024

import Foundation

struct RecipesResponseDTO: Decodable {

Choose a reason for hiding this comment

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

레시피가 아니라 아예 네트워크 레이어의 공통 구조체로 분리하는게 어떠냐는 이야기였어요.

Copy link
Collaborator Author

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,

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까지 대문자로 써달라는 이야기였어요.

Copy link
Collaborator Author

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

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fa80af1
변경했습니다

@GeonH0 GeonH0 force-pushed the feature/feedList branch from 7796413 to 628e0b7 Compare June 11, 2024 10:32
@f-lab-barry
Copy link

  1. Observable, Single
  2. isLiked 네이밍
  3. networkDTO

@GeonH0 GeonH0 force-pushed the feature/feedList branch from d4e9a9f to a7e58be Compare June 11, 2024 13:56
@GeonH0
Copy link
Collaborator Author

GeonH0 commented Jun 11, 2024

  1. Observable, Single a7e58be
  2. isLiked 네이밍 bf60bc6
  3. networkDTO 84df58b

변경 완료 했습니다!

506be99
RecipeImageDTO에 CodingKey를 추가했습니다

페이지 네이션을 위해 DTO구조 및 Repository, Usecase를 변경했습니다
8acf4c6

66312f1

e9763e8

isLiked: false,
hasBeenLiked: false,

Choose a reason for hiding this comment

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

"내가(작성자가)" 좋아요했다가 느껴지지 않아서 여전히 모호해보여요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

b7981cc
isLikedByCurrentUser 로 네이밍 변경했습니다!

Copy link

@f-lab-barry f-lab-barry left a comment

Choose a reason for hiding this comment

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

hasBeenLiked 만 다시 고민해주세요. 일단 선 승인 해둘게요.
네이밍이 크리티컬한 부분은 아니라서, 변경 후 머지하고 다음 작업 해주시면 될 것 같아요

Copy link

@GeonH0 GeonH0 merged commit 8c2e972 into main Jun 12, 2024
2 checks passed
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.

2 participants