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

댓글 추가하는 기능을 생성하였습니다. #34

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 19 additions & 7 deletions HomeCafeRecipes/HomeCafeRecipes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
1D7641492C831295002AC68F /* LoginService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D7641482C831295002AC68F /* LoginService.swift */; };
1D8474562C6C917900323001 /* SearchFeedListUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D8474552C6C917900323001 /* SearchFeedListUseCaseTests.swift */; };
1D8474592C6CCF6900323001 /* TestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D8474582C6CCF6900323001 /* TestUtils.swift */; };
1D87E08B2CD8C4BD0082A1CD /* AddCommentUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D87E08A2CD8C4BD0082A1CD /* AddCommentUseCase.swift */; };
1D87E08D2CD8D5A80082A1CD /* AddCommentRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D87E08C2CD8D5A80082A1CD /* AddCommentRepository.swift */; };
1D87E08F2CD8DB4A0082A1CD /* CommentPostService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D87E08E2CD8DB4A0082A1CD /* CommentPostService.swift */; };
1D93B9992CA26EB80094277F /* LoginUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D93B9982CA26EB80094277F /* LoginUseCaseTests.swift */; };
1D95A0A62C37C79500F09077 /* RecipeDetailError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D95A0A52C37C79500F09077 /* RecipeDetailError.swift */; };
1D96FDAA2C7F55E600EFC657 /* LoginInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D96FDA92C7F55E600EFC657 /* LoginInteractor.swift */; };
Expand Down Expand Up @@ -234,6 +237,9 @@
1D7641482C831295002AC68F /* LoginService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginService.swift; sourceTree = "<group>"; };
1D8474552C6C917900323001 /* SearchFeedListUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchFeedListUseCaseTests.swift; sourceTree = "<group>"; };
1D8474582C6CCF6900323001 /* TestUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestUtils.swift; sourceTree = "<group>"; };
1D87E08A2CD8C4BD0082A1CD /* AddCommentUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddCommentUseCase.swift; sourceTree = "<group>"; };
1D87E08C2CD8D5A80082A1CD /* AddCommentRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddCommentRepository.swift; sourceTree = "<group>"; };
1D87E08E2CD8DB4A0082A1CD /* CommentPostService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentPostService.swift; sourceTree = "<group>"; };
1D93B9982CA26EB80094277F /* LoginUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginUseCaseTests.swift; sourceTree = "<group>"; };
1D95A0A52C37C79500F09077 /* RecipeDetailError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeDetailError.swift; sourceTree = "<group>"; };
1D96FDA92C7F55E600EFC657 /* LoginInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginInteractor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -305,21 +311,21 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
1D0173AA2CB15E2A00FF04BA /* comment */ = {
1D0173AA2CB15E2A00FF04BA /* Comment */ = {
isa = PBXGroup;
children = (
1D0635E22CB28ADE00DCC9EA /* View */,
1D0173AB2CB162CA00FF04BA /* commentViewModel.swift */,
1D0173AF2CB1847C00FF04BA /* CommentView.swift */,
1D0173B12CB1856300FF04BA /* CommentViewController.swift */,
1D0173B32CB185C000FF04BA /* CommentCell.swift */,
1D0635E22CB28ADE00DCC9EA /* View */,
);
path = comment;
path = Comment;
sourceTree = "<group>";
};
1D0635E22CB28ADE00DCC9EA /* View */ = {
isa = PBXGroup;
children = (
1D0173AF2CB1847C00FF04BA /* CommentView.swift */,
1D0173B12CB1856300FF04BA /* CommentViewController.swift */,
1D0173B32CB185C000FF04BA /* CommentCell.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -351,6 +357,7 @@
1D2398B12C8DC07800626F0C /* SignUpUseCase.swift */,
1DFC961F2C908739006C3309 /* CheckEmailUsecase.swift */,
1D0635E52CB2A63200DCC9EA /* FetchCommentUsecase.swift */,
1D87E08A2CD8C4BD0082A1CD /* AddCommentUseCase.swift */,
);
path = UseCases;
sourceTree = "<group>";
Expand Down Expand Up @@ -383,6 +390,7 @@
1D7641482C831295002AC68F /* LoginService.swift */,
1DBD90B82C91BDAC00184F67 /* SignUpService.swift */,
1D0635E02CB28A8700DCC9EA /* CommentService.swift */,
1D87E08E2CD8DB4A0082A1CD /* CommentPostService.swift */,
);
path = Network;
sourceTree = "<group>";
Expand Down Expand Up @@ -562,14 +570,15 @@
1DFC961B2C90809D006C3309 /* SignUpRepository.swift */,
1DFC961D2C908723006C3309 /* CheckEmailRepository.swift */,
1D0635E72CB2AA0600DCC9EA /* CommentListRepository.swift */,
1D87E08C2CD8D5A80082A1CD /* AddCommentRepository.swift */,
);
path = Repositories;
sourceTree = "<group>";
};
1DE19EB22C1B422F0031804A /* Presentation */ = {
isa = PBXGroup;
children = (
1D0173AA2CB15E2A00FF04BA /* comment */,
1D0173AA2CB15E2A00FF04BA /* Comment */,
1DF0D1A72C7DF99F00E2C94C /* Login */,
1D2C6F662C24697F004BB54E /* UploadRecipe */,
1D2C6F612C2446AF004BB54E /* Tabbar */,
Expand Down Expand Up @@ -830,6 +839,7 @@
1DF0D1A92C7DF9AA00E2C94C /* LoginViewModel.swift in Sources */,
1DF0D1A12C7B92F800E2C94C /* User.swift in Sources */,
1D73687A2C32EB18000EF904 /* RecipeUploadDTO.swift in Sources */,
1D87E08B2CD8C4BD0082A1CD /* AddCommentUseCase.swift in Sources */,
1D2C6F6A2C26AF9F004BB54E /* AddRecipeView.swift in Sources */,
1DDF485D2C9405CF000A082E /* CheckEmailRespones.swift in Sources */,
1D2C6F682C246998004BB54E /* AddRecipeViewController.swift in Sources */,
Expand All @@ -856,6 +866,7 @@
1D0BE5822CB5652500F54A26 /* CommnetMapper.swift in Sources */,
1DE19EA82C1B420A0031804A /* SearchFeedListRepository.swift in Sources */,
1DE19EC32C1B422F0031804A /* SearchBar.swift in Sources */,
1D87E08D2CD8D5A80082A1CD /* AddCommentRepository.swift in Sources */,
1D439EA22C2C6997008530A5 /* RecipeDetailInteractor.swift in Sources */,
1D73686E2C305757000EF904 /* RecipeDetailDTO.swift in Sources */,
1D0635E12CB28A8700DCC9EA /* CommentService.swift in Sources */,
Expand Down Expand Up @@ -886,6 +897,7 @@
1D0173AE2CB171DF00FF04BA /* Comment.swift in Sources */,
1D1283CA2C16D9C600C5A870 /* RecipeFetchService.swift in Sources */,
1D6958D42C3D059E008604B3 /* RecipeListRouter.swift in Sources */,
1D87E08F2CD8DB4A0082A1CD /* CommentPostService.swift in Sources */,
1D4741D42C1B4F8D009381CE /* NetworkResponseDTO.swift in Sources */,
1D439E9C2C2C58DD008530A5 /* FetchRecipeDetailUseCase.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// CommentPostService.swift
// HomeCafeRecipes
//
// Created by 김건호 on 11/4/24.
//

import Foundation

import RxSwift

protocol CommentPostService {
func postComment(
recipeID: Int,
userID: Int,
comment: String
) -> Single<Comment>
}

final class CommentPostServiceImpl: CommentPostService {
private let networkService: NetworkService

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

private func makeURL(ednpoint: String) -> URL {
return APIConfig().baseURL.appendingPathComponent(ednpoint)
}

func postComment(recipeID: Int, userID: Int, comment: String) -> Single<Comment> {
let url = makeURL(ednpoint: "comments")

let parameters: [String: Any] = [
"userId": userID,
"recipeId": recipeID,
"content": comment
]

return networkService.postJsonRequest(
url: url,
parameters: parameters,
responseType: NetworkResponseDTO<CommentDTO>.self
)
.flatMap { response in
guard response.statusCode == 200 else {
let error = NSError(
domain: "CommentPostServiceError",
code: response.statusCode,
userInfo: [NSLocalizedDescriptionKey: response.message]
)
return .error(error)
}
return .just(response.data.toDomain())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// AddCommentRepository.swift
// HomeCafeRecipes
//
// Created by 김건호 on 11/4/24.
//

import Foundation

import RxSwift

protocol AddCommentRepository {
func addComment(
recipeID: Int,
userID: Int,
comment: String
) -> Single<Comment>
}

final class AddCommenRepositoryImpl: AddCommentRepository {
private let service: CommentPostService

init(service: CommentPostService) {
self.service = service
}

func addComment(recipeID: Int, userID: Int, comment: String) -> Single<Comment> {
return service.postComment(recipeID: recipeID, userID: userID, comment: comment)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,38 @@ protocol CommentInteractorDelegate: AnyObject {

protocol CommentInteractor {
func loadComment(recipeID: Int)
func didEndEditing(comment: String)
func addComment(recipeID: Int,comment: String) -> Single<Result<Comment, Error>>
}

final class CommentInteractorImpl: CommentInteractor {

private let disposeBag = DisposeBag()
private let usecase: FetchCommentUsecase
private let fetchusecase: FetchCommentUsecase
private let addusecase: AddCommentUseCase
private var allComments: [Comment] = []
private var comment: String = ""

weak var delegate: CommentInteractorDelegate?

init(usecase: FetchCommentUsecase) {
self.usecase = usecase
init(
fetchusecase: FetchCommentUsecase,
addusecase: AddCommentUseCase
) {
self.fetchusecase = fetchusecase
self.addusecase = addusecase
}

func loadComment(recipeID: Int) {
usecase.execute(recipeID: recipeID)
fetchusecase.execute(recipeID: recipeID)
.subscribe(onSuccess: { [weak self] comments in
self?.handleResult(.success(comments))
}, onError: { [weak self] error in
self?.handleResult(.failure(error))
})
.disposed(by: disposeBag)
}

private func handleResult(_ result: Result<[Comment], Error>) {
switch result {
case .success(let comments):
Expand All @@ -49,4 +59,23 @@ final class CommentInteractorImpl: CommentInteractor {
delegate?.fetchedComments(result: .failure(error))
}
}

func didEndEditing(comment: String) {
self.comment = comment
}

// MARK: userID 받아오는 작업 예정
func addComment(
recipeID: Int,
comment: String
) -> Single<Result<Comment, Error>> {
return addusecase.execute(
recipeID: recipeID,
userID: 1,
comment: comment
)
.catch { error in
return .just(.failure(error))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// AddCommentUseCase.swift
// HomeCafeRecipes
//
// Created by 김건호 on 11/4/24.
//

import Foundation

import RxSwift

protocol AddCommentUseCase {
func execute(
recipeID: Int,
userID: Int,
comment: String
) -> Single<Result<Comment,Error>>
}

final class AddCommentUseCaseImpl : AddCommentUseCase {
private let addcommentRepository: AddCommentRepository

init(addcommentRepository: AddCommentRepository) {
self.addcommentRepository = addcommentRepository
}

func execute(
recipeID: Int,
userID: Int,
comment: String) -> Single<Result<Comment,Error>> {
return addcommentRepository.addComment(
recipeID: recipeID,
userID: userID,
comment: comment
)
.map{ .success($0) }
}
}

This file was deleted.

Loading
Loading