-
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
피드 상세화면에 필요한 Domain영역과 Data 영역을 정의해 보았습니다. #13
Changes from 3 commits
6eb97ea
bab43de
4b09f04
3f7f570
429a962
6178184
e117629
8f79c55
c91393f
9ba8620
ed07510
cda676a
dbf2111
02a63aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
} | ||
|
||
class RecipeDetailFetchServiceImpl: RecipeDetailFetchService { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기엔 final 필요 없을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필요 한거 같아요 final 추가 하겠습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
return networkService.getRequest(url: URL, responseType: NetworkResponseDTO<RecipeDetailDTO>.self) | ||
.map { $0.data.toDomain() } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// RecipeDetailRepository.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/26/24. | ||
// | ||
|
||
import Foundation | ||
import RxSwift | ||
|
||
protocol RecipeDetailRepository { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RecipeDetailFetchService 랑 분리한 이유가 있나요..? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RecipeDetailFetchService는 네트워크 통신만을 담당하고 RecipeDetailRepository는 데이터 접근 로직을 추상화 할수 있습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 사실상 서비스에서는 url을 만드는 것 외에 복잡한 통신로직은 없는 것 같은데 이에 비해 레이어가 많은 것 같아요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [cda676a] service를 삭제후 repository에 service가 하는역할을 추가했습니다 |
||
func fetchRecipeDetail(recipeID: Int) -> Single<Recipe> | ||
} | ||
|
||
class FeedListRepositoryImpl: RecipeDetailRepository { | ||
private let networkService: RecipeDetailFetchService | ||
|
||
init(networkService: RecipeDetailFetchService) { | ||
self.networkService = networkService | ||
} | ||
|
||
func fetchRecipeDetail(recipeID: Int) -> Single<Recipe> { | ||
return networkService.fetchRecipeDetail(recipeId: recipeID) | ||
} | ||
} |
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.
이 파일 전체적으로 고쳐주세요.
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.
[6178184] 수정했습니다