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

피드 상세화면에 필요한 Domain영역과 Data 영역을 정의해 보았습니다. #13

Merged
merged 14 commits into from
Jul 11, 2024

Conversation

GeonH0
Copy link
Collaborator

@GeonH0 GeonH0 commented Jul 3, 2024

  1. RecipeDetailFetchService 정의
    피드 상세화면에 필요한 네트워크 서비스를 정의했습니다.
    recipeId를 인스턴스로 받아서 URL 컴포넌트로 사용합니다.

  2. RecipeDetailDTO 정의
    서버로부터 받은 JSON 데이터를 디코딩하고 도메인 모델로 변환할 DTO(Data Transfer Object)를 정의했습니다.

  3. RecipeDetailRepository 정의
    서버로부터 데이터를 받아오는 레포지토리를 정의했습니다.
    RecipeDetailFetchService를 사용하여 데이터를 가져옵니다.

  4. RecipeDetailInteractor 정의
    피드 상세화면에 알맞는 비즈니스 로직을 전달하는 인터랙터를 정의했습니다.
    FetchRecipeDetailUseCase를 통해 비즈니스 로직을 처리합니다.

  5. FetchRecipeDetailUseCase 정의
    피드 상세화면에 필요한 비즈니스 로직을 담은 유즈 케이스를 정의했습니다.
    레포지토리와 상호작용하여 데이터를 가져오고 가공합니다.

import RxSwift

protocol RecipeDetailFetchService {
func fetchRecipeDetail(recipeId: Int) -> Single<Recipe>

Choose a reason for hiding this comment

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

Suggested change
func fetchRecipeDetail(recipeId: Int) -> Single<Recipe>
func fetchRecipeDetail(recipeID: Int) -> Single<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.

[6178184] 수정했습니다

func fetchRecipeDetail(recipeId: Int) -> Single<Recipe>
}

class RecipeDetailFetchServiceImpl: RecipeDetailFetchService {

Choose a reason for hiding this comment

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

여기엔 final 필요 없을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

필요 한거 같아요 final 추가 하겠습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

[e117629] 수정했습니다


func fetchRecipeDetail(recipeId: Int) -> Single<Recipe> {
guard let URL = makeURL(recipeId: recipeId) else {
return Single.error(NSError(domain: "URLComponentsError", code: -1, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))

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.

[8f79c55],[c91393f] 정의후 적용시켰습니다

import Foundation
import RxSwift

protocol RecipeDetailRepository {

Choose a reason for hiding this comment

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

RecipeDetailFetchService 랑 분리한 이유가 있나요..?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RecipeDetailFetchService는 네트워크 통신만을 담당하고 RecipeDetailRepository는 데이터 접근 로직을 추상화 할수 있습니다.

Choose a reason for hiding this comment

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

사실상 서비스에서는 url을 만드는 것 외에 복잡한 통신로직은 없는 것 같은데 이에 비해 레이어가 많은 것 같아요.
어떻게 생각하시나요~?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

[cda676a] service를 삭제후 repository에 service가 하는역할을 추가했습니다

return recipeDetailSubject.asObservable()
}

init(fetchRecipeDetailUseCase: FetchRecipeDetailUseCase, recipeID: Int) {

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.

[9ba8620] 수정했습니다

Comment on lines +19 to +21
protocol OutputRecipeDetailInteractor {
var recipe: Observable<Result<Recipe, Error>> { get }
}

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.

recipeDetailSubject를 Observable로 반환함으로써 외부에서 데이터를 읽기 전용으로 사용할 수 있습니다

Comment on lines +46 to +50
recipe
.subscribe(onNext: { [weak self] result in
self?.delegate?.fetchedRecipe(result: result)
})
.disposed(by: disposeBag)

Choose a reason for hiding this comment

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

바로 델리게이트를 호출해도 될 것 같은데 recipe를 통하는 이유가 궁금해요.
output과 delegate가 같은 역할 같아서요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

recipe를 통해서 비동기 데이터를 전달하고, Delegate는 이벤트만을 처리하기 위해 만들어 둔것 입니다.


import Foundation

enum RecipeError: 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.

구분지어야 할거 같아요 RecipeDeatilError로 네이밍 수정하겠습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

[6f3afb4] 네이밍 수정했습니다!

@GeonH0 GeonH0 force-pushed the feature/FeedDetailDomainData branch from 2fb942f to cda676a Compare July 9, 2024 07:34
private let networkService: RecipeDetailFetchService
class RecipeDetailRepositoryImpl: RecipeDetailRepository {
private let networkService: NetworkService
private static let baseURL: URL = URL(string: "https://meog0.store/api")!

Choose a reason for hiding this comment

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

공통 객체로 분리해보기
-> baseURL이 변경되었을 때 수정범위가 넓음

@@ -26,15 +26,15 @@ final class RecipeDetailFetchServiceImpl: RecipeDetailFetchService {

func fetchRecipeDetail(recipeID: Int) -> Single<Recipe> {
guard let url = makeURL(recipeID: recipeID) else {
return Single.error(RecipeError.invalidURL)
return Single.error(RecipeDetailError.invalidURL)

Choose a reason for hiding this comment

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

usecase
func foo() {
fetchRecipeDetail(recipeID: 100)... { onFailure: { [weak self] error in ..
var errorMessage: String {
switch error {
case .inbalidUR: "페이지를 찾을 수 없어요."
}
}
} }
}

Comment on lines +15 to +17
protocol InputRecipeDetailInteractor {
func viewDidLoad()
}

Choose a reason for hiding this comment

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

InputRecipeDetailInteractor -> RecipeDetailInteractor

RecipeDetailInteractorImpl: RecipeDetailInteractor
// vc에서 행동에 따른 비즈니스 로직 호출 ex) viewDidLoad
// 비즈니스 로직 -> return 도메인 모델 -> delegate로 vc에 전달 -> mapper -> return 뷰 모델 -> 뷰 업데이트

output 빼고


init(networkService: NetworkService) {
init(networkService: NetworkService, apiConfig: APIConfig) {

Choose a reason for hiding this comment

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

baseURL은 주입받아서 들고있을 필요 없이 public으로 열어두고 쓰는건 어때요?
레포지토리에서 무조건 봐야하는 모델인데 주입받을 필요는 없을 것 같아서요!

@GeonH0 GeonH0 force-pushed the feature/FeedDetailDomainData branch from 90fa58c to a388cf6 Compare July 11, 2024 04:09
@GeonH0 GeonH0 force-pushed the feature/FeedDetailDomainData branch from a388cf6 to dbf2111 Compare July 11, 2024 04:14
Copy link

@GeonH0 GeonH0 merged commit 2916d59 into main Jul 11, 2024
2 checks passed
@GeonH0 GeonH0 deleted the feature/FeedDetailDomainData branch September 12, 2024 01:00
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