-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from f-lab-edu/feature/feedList
피드리스트를 받기 위한 UseCase, Entities,Repository를 정의했습니다.
- Loading branch information
Showing
11 changed files
with
405 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/NetworkResponseDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 NetworkResponseDTO<T: Decodable>: Decodable { | ||
let statusCode: Int | ||
let message: String | ||
let data: T | ||
} |
49 changes: 49 additions & 0 deletions
49
HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// 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] | ||
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 RecipeDTO { | ||
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() | ||
) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeImageDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// RecipeImageDTO.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/11/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecipeImageDTO: Decodable { | ||
let recipeImageID: Int | ||
let recipeImageUrl: String | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case recipeImageID = "recipeImgId" | ||
case recipeImageUrl = "recipeImgUrl" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipePageDTO.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// RecipePageDTO.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct RecipePageDTO: Decodable { | ||
let totalPageNumber: Int | ||
let pageNumber: Int | ||
let recipes: [RecipeDTO] | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case totalPageNumber = "totalPageNumber" | ||
case pageNumber = "pageNumber" | ||
case recipes = "recipes" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/FeedListRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(pageNumber: Int) -> Single<[Recipe]> | ||
} | ||
|
||
class DefaultFeedListRepository: FeedListRepository { | ||
private let networkService: RecipeFetchService | ||
|
||
init(networkService: RecipeFetchService) { | ||
self.networkService = networkService | ||
} | ||
|
||
func fetchRecipes(pageNumber: Int) -> Single<[Recipe]> { | ||
return networkService.fetchRecipes(pageNumber: pageNumber) | ||
} | ||
} |
Oops, something went wrong.