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

피드리스트를 받기 위한 UseCase, Entities,Repository를 정의했습니다. #4

Merged
merged 16 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions HomeCafeRecipes/HomeCafeRecipes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@
objects = {

/* Begin PBXBuildFile section */
1D1283A22C15E94300C5A870 /* Recipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A12C15E94300C5A870 /* Recipe.swift */; };
1D1283A42C15EA8100C5A870 /* RecipeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A32C15EA8100C5A870 /* RecipeType.swift */; };
1D1283A62C15EAA600C5A870 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A52C15EAA600C5A870 /* User.swift */; };
1D1283A82C15EABB00C5A870 /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A72C15EABB00C5A870 /* Comment.swift */; };
1D1283AA2C15EBCF00C5A870 /* SearchFeedUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A92C15EBCF00C5A870 /* SearchFeedUseCase.swift */; };
1D1283AC2C15EBE600C5A870 /* FetchFeedListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283AB2C15EBE600C5A870 /* FetchFeedListUseCase.swift */; };
1D1283AF2C1697DB00C5A870 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 1D1283AE2C1697DB00C5A870 /* RxCocoa */; };
1D1283B12C1697DB00C5A870 /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 1D1283B02C1697DB00C5A870 /* RxSwift */; };
1D1283B42C16983900C5A870 /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 1D1283B32C16983900C5A870 /* RxSwift */; };
1D1283B62C16984E00C5A870 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 1D1283B52C16984E00C5A870 /* RxCocoa */; };
1D1283B82C169C0200C5A870 /* FeedListRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283B72C169C0200C5A870 /* FeedListRepository.swift */; };
1D1283BA2C16A62800C5A870 /* SearchFeedListRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283B92C16A62800C5A870 /* SearchFeedListRepository.swift */; };
1D1283C12C16B05800C5A870 /* RecipeDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C02C16B05800C5A870 /* RecipeDTO.swift */; };
1D1283C32C16B06F00C5A870 /* UserDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C22C16B06F00C5A870 /* UserDTO.swift */; };
1D1283C52C16B07D00C5A870 /* CommentDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C42C16B07D00C5A870 /* CommentDTO.swift */; };
1D1283C82C16CE7C00C5A870 /* DateFormatter+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C72C16CE7C00C5A870 /* DateFormatter+Extensions.swift */; };
1D1283CA2C16D9C600C5A870 /* RecipeFetchService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C92C16D9C600C5A870 /* RecipeFetchService.swift */; };
1D2C16E62BE532B700C04508 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2C16E52BE532B700C04508 /* AppDelegate.swift */; };
1D2C16E82BE532B700C04508 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2C16E72BE532B700C04508 /* SceneDelegate.swift */; };
1D2C16EA2BE532B700C04508 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2C16E92BE532B700C04508 /* ViewController.swift */; };
Expand Down Expand Up @@ -35,6 +52,19 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1D1283A12C15E94300C5A870 /* Recipe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Recipe.swift; sourceTree = "<group>"; };
1D1283A32C15EA8100C5A870 /* RecipeType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeType.swift; sourceTree = "<group>"; };
1D1283A52C15EAA600C5A870 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
1D1283A72C15EABB00C5A870 /* Comment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = "<group>"; };
1D1283A92C15EBCF00C5A870 /* SearchFeedUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchFeedUseCase.swift; sourceTree = "<group>"; };
1D1283AB2C15EBE600C5A870 /* FetchFeedListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchFeedListUseCase.swift; sourceTree = "<group>"; };
1D1283B72C169C0200C5A870 /* FeedListRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListRepository.swift; sourceTree = "<group>"; };
1D1283B92C16A62800C5A870 /* SearchFeedListRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchFeedListRepository.swift; sourceTree = "<group>"; };
1D1283C02C16B05800C5A870 /* RecipeDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeDTO.swift; sourceTree = "<group>"; };
1D1283C22C16B06F00C5A870 /* UserDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDTO.swift; sourceTree = "<group>"; };
1D1283C42C16B07D00C5A870 /* CommentDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentDTO.swift; sourceTree = "<group>"; };
1D1283C72C16CE7C00C5A870 /* DateFormatter+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extensions.swift"; sourceTree = "<group>"; };
1D1283C92C16D9C600C5A870 /* RecipeFetchService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeFetchService.swift; sourceTree = "<group>"; };
1D2C16E22BE532B700C04508 /* HomeCafeRecipes.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HomeCafeRecipes.app; sourceTree = BUILT_PRODUCTS_DIR; };
1D2C16E52BE532B700C04508 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
1D2C16E72BE532B700C04508 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -54,6 +84,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1D1283B12C1697DB00C5A870 /* RxSwift in Frameworks */,
1D1283AF2C1697DB00C5A870 /* RxCocoa in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -68,19 +100,95 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1D1283B62C16984E00C5A870 /* RxCocoa in Frameworks */,
1D1283B42C16983900C5A870 /* RxSwift in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
1D12839F2C15E7A700C5A870 /* Entities */ = {
isa = PBXGroup;
children = (
1D1283A12C15E94300C5A870 /* Recipe.swift */,
1D1283A32C15EA8100C5A870 /* RecipeType.swift */,
1D1283A52C15EAA600C5A870 /* User.swift */,
1D1283A72C15EABB00C5A870 /* Comment.swift */,
);
path = Entities;
sourceTree = "<group>";
};
1D1283A02C15E92C00C5A870 /* UseCases */ = {
isa = PBXGroup;
children = (
1D1283A92C15EBCF00C5A870 /* SearchFeedUseCase.swift */,
1D1283AB2C15EBE600C5A870 /* FetchFeedListUseCase.swift */,
);
path = UseCases;
sourceTree = "<group>";
};
1D1283AD2C16974B00C5A870 /* Data */ = {
isa = PBXGroup;
children = (
1D1283BC2C16AA8100C5A870 /* Network */,
1D1283BB2C16AA6400C5A870 /* Repositories */,
);
path = Data;
sourceTree = "<group>";
};
1D1283B22C16983900C5A870 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
1D1283BB2C16AA6400C5A870 /* Repositories */ = {
isa = PBXGroup;
children = (
1D1283B72C169C0200C5A870 /* FeedListRepository.swift */,
1D1283B92C16A62800C5A870 /* SearchFeedListRepository.swift */,
);
name = Repositories;
path = "ㄲ데ㅐ냐새갿ㄴ";
sourceTree = "<group>";
};
1D1283BC2C16AA8100C5A870 /* Network */ = {
isa = PBXGroup;
children = (
1D1283BF2C16B02600C5A870 /* DTO */,
1D1283C92C16D9C600C5A870 /* RecipeFetchService.swift */,
);
path = Network;
sourceTree = "<group>";
};
1D1283BF2C16B02600C5A870 /* DTO */ = {
isa = PBXGroup;
children = (
1D1283C02C16B05800C5A870 /* RecipeDTO.swift */,
1D1283C22C16B06F00C5A870 /* UserDTO.swift */,
1D1283C42C16B07D00C5A870 /* CommentDTO.swift */,
);
path = DTO;
sourceTree = "<group>";
};
1D1283C62C16CD9200C5A870 /* Utilities */ = {
isa = PBXGroup;
children = (
1D1283C72C16CE7C00C5A870 /* DateFormatter+Extensions.swift */,
);
path = Utilities;
sourceTree = "<group>";
};
1D2C16D92BE532B700C04508 = {
isa = PBXGroup;
children = (
1D2C16E42BE532B700C04508 /* HomeCafeRecipes */,
1D2C16FB2BE532B800C04508 /* HomeCafeRecipesTests */,
1D2C17052BE532B800C04508 /* HomeCafeRecipesUITests */,
1D2C16E32BE532B700C04508 /* Products */,
1D1283B22C16983900C5A870 /* Frameworks */,
);
sourceTree = "<group>";
};
Expand All @@ -97,6 +205,9 @@
1D2C16E42BE532B700C04508 /* HomeCafeRecipes */ = {
isa = PBXGroup;
children = (
1D1283C62C16CD9200C5A870 /* Utilities */,
1D1283AD2C16974B00C5A870 /* Data */,
1D740B402C15E6680001B704 /* Domain */,
1D2C16E52BE532B700C04508 /* AppDelegate.swift */,
1D2C16E72BE532B700C04508 /* SceneDelegate.swift */,
1D2C16E92BE532B700C04508 /* ViewController.swift */,
Expand Down Expand Up @@ -124,6 +235,15 @@
path = HomeCafeRecipesUITests;
sourceTree = "<group>";
};
1D740B402C15E6680001B704 /* Domain */ = {
isa = PBXGroup;
children = (
1D1283A02C15E92C00C5A870 /* UseCases */,
1D12839F2C15E7A700C5A870 /* Entities */,
);
path = Domain;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -141,6 +261,8 @@
);
name = HomeCafeRecipes;
packageProductDependencies = (
1D1283AE2C1697DB00C5A870 /* RxCocoa */,
1D1283B02C1697DB00C5A870 /* RxSwift */,
);
productName = HomeCafeRecipes;
productReference = 1D2C16E22BE532B700C04508 /* HomeCafeRecipes.app */;
Expand Down Expand Up @@ -178,6 +300,10 @@
1D2C17042BE532B800C04508 /* PBXTargetDependency */,
);
name = HomeCafeRecipesUITests;
packageProductDependencies = (
1D1283B32C16983900C5A870 /* RxSwift */,
1D1283B52C16984E00C5A870 /* RxCocoa */,
);
productName = HomeCafeRecipesUITests;
productReference = 1D2C17022BE532B800C04508 /* HomeCafeRecipesUITests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
Expand Down Expand Up @@ -261,7 +387,20 @@
files = (
1D2C16EA2BE532B700C04508 /* ViewController.swift in Sources */,
1D2C16E62BE532B700C04508 /* AppDelegate.swift in Sources */,
1D1283A62C15EAA600C5A870 /* User.swift in Sources */,
1D1283C52C16B07D00C5A870 /* CommentDTO.swift in Sources */,
1D1283AC2C15EBE600C5A870 /* FetchFeedListUseCase.swift in Sources */,
1D1283A82C15EABB00C5A870 /* Comment.swift in Sources */,
1D1283C82C16CE7C00C5A870 /* DateFormatter+Extensions.swift in Sources */,
1D1283B82C169C0200C5A870 /* FeedListRepository.swift in Sources */,
1D1283A42C15EA8100C5A870 /* RecipeType.swift in Sources */,
1D1283AA2C15EBCF00C5A870 /* SearchFeedUseCase.swift in Sources */,
1D2C16E82BE532B700C04508 /* SceneDelegate.swift in Sources */,
1D1283BA2C16A62800C5A870 /* SearchFeedListRepository.swift in Sources */,
1D1283A22C15E94300C5A870 /* Recipe.swift in Sources */,
1D1283CA2C16D9C600C5A870 /* RecipeFetchService.swift in Sources */,
1D1283C32C16B06F00C5A870 /* UserDTO.swift in Sources */,
1D1283C12C16B05800C5A870 /* RecipeDTO.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -609,6 +748,29 @@
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
1D1283AE2C1697DB00C5A870 /* RxCocoa */ = {
isa = XCSwiftPackageProductDependency;
package = 1D740B3F2C15E1EC0001B704 /* XCRemoteSwiftPackageReference "RxSwift" */;
productName = RxCocoa;
};
1D1283B02C1697DB00C5A870 /* RxSwift */ = {
isa = XCSwiftPackageProductDependency;
package = 1D740B3F2C15E1EC0001B704 /* XCRemoteSwiftPackageReference "RxSwift" */;
productName = RxSwift;
};
1D1283B32C16983900C5A870 /* RxSwift */ = {
isa = XCSwiftPackageProductDependency;
package = 1D740B3F2C15E1EC0001B704 /* XCRemoteSwiftPackageReference "RxSwift" */;
productName = RxSwift;
};
1D1283B52C16984E00C5A870 /* RxCocoa */ = {
isa = XCSwiftPackageProductDependency;
package = 1D740B3F2C15E1EC0001B704 /* XCRemoteSwiftPackageReference "RxSwift" */;
productName = RxCocoa;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 1D2C16DA2BE532B700C04508 /* Project object */;
}
47 changes: 47 additions & 0 deletions HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift
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

Choose a reason for hiding this comment

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

userDTO는 따로 파일을 분리하는게 어떠신가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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,

Choose a reason for hiding this comment

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

ID만 있을 때는 id로 써도 돼요, 하지만 camel Case로 작성할 때는 fooID 식으로 d까지 대문자로 써달라는 이야기였어요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fa80af1
id로 다시 변경했습니다

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

Choose a reason for hiding this comment

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

이런 경우에 recipeImgID로 D까지 대문자로 쓰는게 일반적이에요~
또한 swift Naming convention에 맞춰서 왠만하면 줄임말은 지양해주세요.
img -> image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 {

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.

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]>

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.

서버에서 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)
}
}
20 changes: 20 additions & 0 deletions HomeCafeRecipes/HomeCafeRecipes/Domain/Entities/Recipe.swift
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

Choose a reason for hiding this comment

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

likeCount가 없을 땐 0으로 가져가는건가요? nullable한 값을 가지지 않는건지 궁금해요. (likeCount 외에 다른 값들도 전부 required네요)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 likeCount가 없을때는 0으로 가져갑니다!

}
Loading
Loading