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
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// RecipeDetailDTO.swift
// HomeCafeRecipes
//
// Created by 김건호 on 6/29/24.
//

import Foundation

struct RecipeDetailDTO: Decodable {

let id: Int
let type: String
let name: String
let description: String
let likesCount: Int
let createdAt: String
let writer: UserDTO
let imageUrls: [RecipeImageDTO]
let isLikedByCurrentUser: Bool

enum CodingKeys: String, CodingKey {
case id = "recipeId"
case type = "recipeType"
case name = "recipeName"
case description = "recipeDescription"
case likesCount = "recipeLikesCnt"
case createdAt = "createdAt"
case writer = "writer"
case imageUrls = "recipeImgUrls"
case isLikedByCurrentUser = "isLiked"
}
}

extension RecipeDetailDTO {
func toDomain() -> Recipe {
return Recipe(
id: id,
type: RecipeType(rawValue: type) ?? .coffee,
name: name,
description: description,
writer: writer.toDomain(),
imageUrls: imageUrls.map { $0.recipeImageUrl },
isLikedByCurrentUser: isLikedByCurrentUser,
likeCount: likesCount,
createdAt: DateFormatter.iso8601.date(from: createdAt) ?? Date()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// RecipeDetailFetchService.swift
// HomeCafeRecipes
//
// Created by 김건호 on 6/26/24.
//

import Foundation
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] 수정했습니다

}

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] 수정했습니다

private let networkService: NetworkService
private static let baseURL: URL = URL(string: "https://meog0.store/api")!

init(networkService: NetworkService) {
self.networkService = networkService
}

private func makeURL(recipeId: Int) -> URL? {
return RecipeDetailFetchServiceImpl.baseURL.appendingPathComponent("recipes/\(recipeId)")
}

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] 정의후 적용시켰습니다

}
return networkService.getRequest(url: URL, responseType: NetworkResponseDTO<RecipeDetailDTO>.self)
.map { $0.data.toDomain() }
}
}