-
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
Changes from 6 commits
a99e1b0
52c981f
5fcb880
e9d4af2
56c5ae6
8afc27b
d86703c
628e0b7
a7e58be
bf60bc6
84df58b
506be99
8acf4c6
66312f1
e9763e8
b7981cc
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,47 @@ | ||
// | ||
// RecipeDTO.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/10/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecipeDTO: 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] | ||
|
||
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" | ||
} | ||
} | ||
|
||
extension RecipeDTO { | ||
func toDomain() -> Recipe { | ||
return Recipe( | ||
id: ID, | ||
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. ID만 있을 때는 id로 써도 돼요, 하지만 camel Case로 작성할 때는 fooID 식으로 d까지 대문자로 써달라는 이야기였어요. 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. fa80af1 |
||
type: RecipeType(rawValue: type) ?? .coffee, | ||
name: name, | ||
description: description, | ||
writer: writer.toDomain(), | ||
imageUrls: imageUrls.map { $0.recipeImgUrl }, | ||
isLiked: false, | ||
likeCount: likesCount, | ||
createdAt: DateFormatter.iso8601.date(from: createdAt) ?? Date() | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// RecipeImageDTO.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/11/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecipeImageDTO: Decodable { | ||
let recipeImgId: Int | ||
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. 이런 경우에 recipeImgID로 D까지 대문자로 쓰는게 일반적이에요~ 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. fa80af1 |
||
let recipeImgUrl: String | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// RecipesResponseDTO.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/11/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecipesResponseDTO: Decodable { | ||
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. d86703c |
||
let statusCode: Int | ||
let message: String | ||
let data: [RecipeDTO] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// FeedListRepository.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/10/24. | ||
// | ||
|
||
import RxSwift | ||
|
||
protocol FeedListRepository { | ||
func fetchRecipes() -> Observable<[Recipe]> | ||
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. 서버에서 api 통신을 해서 Observable 자체로 return 시켜 비동기적으로 데이터를 처리해 보고 싶어서 사용했습니다 |
||
} | ||
|
||
class DefaultFeedListRepository: FeedListRepository { | ||
private let networkService: RecipeFetchService | ||
|
||
init(networkService: RecipeFetchService) { | ||
self.networkService = networkService | ||
} | ||
|
||
func fetchRecipes() -> Observable<[Recipe]> { | ||
return networkService.fetchRecipes() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// SearchFeedListRepository.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/10/24. | ||
// | ||
|
||
import RxSwift | ||
|
||
protocol SearchFeedListRepository { | ||
func searchRecipes(title: String) -> Observable<[Recipe]> | ||
} | ||
|
||
class DefaultSearchFeedRepository: SearchFeedListRepository { | ||
|
||
private let networkService: RecipeFetchService | ||
|
||
init(networkService: RecipeFetchService) { | ||
self.networkService = networkService | ||
} | ||
|
||
func searchRecipes(title: String) -> Observable<[Recipe]> { | ||
return networkService.searchRecipes(title: title) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Recipe.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/9/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Recipe { | ||
let id: Int | ||
let type: RecipeType | ||
let name: String | ||
let description: String | ||
let writer: User | ||
let imageUrls: [String] | ||
let isLiked: Bool | ||
let likeCount: Int | ||
let createdAt: Date | ||
Comment on lines
+18
to
+19
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. likeCount가 없을 땐 0으로 가져가는건가요? nullable한 값을 가지지 않는건지 궁금해요. (likeCount 외에 다른 값들도 전부 required네요) 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. 넵 likeCount가 없을때는 0으로 가져갑니다! |
||
} |
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는 따로 분리 시켜 두었습니다!