Skip to content

Commit

Permalink
Merge pull request #244 from Zatch-Team/dev-api-search
Browse files Browse the repository at this point in the history
Network/#242-#243: μΈκΈ°μžˆλŠ” 검색 ν‚€μ›Œλ“œ API μ—°κ²° 및 λ‚΄κ°€ μ›ν•˜λŠ” 재치 ViewModel 섀계 λ³€κ²½
  • Loading branch information
dev-muuu authored May 22, 2023
2 parents 353fa24 + b12795a commit f0e9bdb
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 69 deletions.
28 changes: 28 additions & 0 deletions Zatch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@
EE41019329854DED0083B7E0 /* LeftNavigationTitleHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE41019229854DED0083B7E0 /* LeftNavigationTitleHeaderView.swift */; };
EE41019529854EE60083B7E0 /* LeftNavigationEtcButtonHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE41019429854EE60083B7E0 /* LeftNavigationEtcButtonHeaderView.swift */; };
EE410197298557440083B7E0 /* ImageDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE410196298557440083B7E0 /* ImageDetailView.swift */; };
EE42D5BF2A1B33FC001BEF64 /* PopularKeywordResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE42D5BE2A1B33FC001BEF64 /* PopularKeywordResponseModel.swift */; };
EE42D5C22A1B3575001BEF64 /* SearchRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE42D5C12A1B3575001BEF64 /* SearchRouter.swift */; };
EE42D5C42A1B357C001BEF64 /* SearchService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE42D5C32A1B357C001BEF64 /* SearchService.swift */; };
EE4CE7B929F910AF00943FE5 /* FAQ.json in Resources */ = {isa = PBXBuildFile; fileRef = EE4CE7B829F910AF00943FE5 /* FAQ.json */; };
EE4CE7C729FCF60E00943FE5 /* LoginUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4CE7C629FCF60E00943FE5 /* LoginUseCase.swift */; };
EE4CE7CA29FCF6FD00943FE5 /* LoginResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4CE7C929FCF6FD00943FE5 /* LoginResponseModel.swift */; };
Expand Down Expand Up @@ -711,6 +714,9 @@
EE41019229854DED0083B7E0 /* LeftNavigationTitleHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftNavigationTitleHeaderView.swift; sourceTree = "<group>"; };
EE41019429854EE60083B7E0 /* LeftNavigationEtcButtonHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeftNavigationEtcButtonHeaderView.swift; sourceTree = "<group>"; };
EE410196298557440083B7E0 /* ImageDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageDetailView.swift; sourceTree = "<group>"; };
EE42D5BE2A1B33FC001BEF64 /* PopularKeywordResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopularKeywordResponseModel.swift; sourceTree = "<group>"; };
EE42D5C12A1B3575001BEF64 /* SearchRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchRouter.swift; sourceTree = "<group>"; };
EE42D5C32A1B357C001BEF64 /* SearchService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchService.swift; sourceTree = "<group>"; };
EE4CE7B829F910AF00943FE5 /* FAQ.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = FAQ.json; sourceTree = "<group>"; };
EE4CE7C629FCF60E00943FE5 /* LoginUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginUseCase.swift; sourceTree = "<group>"; };
EE4CE7C929FCF6FD00943FE5 /* LoginResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginResponseModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1045,6 +1051,7 @@
57B32C2F291F55F20018C0CB /* Zatch */,
57A28D5428D1A07000263079 /* Map */,
57D6D7A128CDC30C00F805B7 /* ChattingModels */,
EE42D5BD2A1B33DF001BEF64 /* Search */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -2010,6 +2017,23 @@
path = MyZatch;
sourceTree = "<group>";
};
EE42D5BD2A1B33DF001BEF64 /* Search */ = {
isa = PBXGroup;
children = (
EE42D5BE2A1B33FC001BEF64 /* PopularKeywordResponseModel.swift */,
);
path = Search;
sourceTree = "<group>";
};
EE42D5C02A1B356D001BEF64 /* Search */ = {
isa = PBXGroup;
children = (
EE42D5C12A1B3575001BEF64 /* SearchRouter.swift */,
EE42D5C32A1B357C001BEF64 /* SearchService.swift */,
);
path = Search;
sourceTree = "<group>";
};
EE4CE7B729F9105000943FE5 /* FAQ */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2096,6 +2120,7 @@
EE4D887D29CFFA69003B6383 /* MoyaService */ = {
isa = PBXGroup;
children = (
EE42D5C02A1B356D001BEF64 /* Search */,
EE4CE7D829FD028E00943FE5 /* User */,
EE4D887729CFF399003B6383 /* Zatch */,
EE4D887829CFF3AA003B6383 /* Map */,
Expand Down Expand Up @@ -2791,6 +2816,7 @@
EEC3753429F8E22300190B22 /* ModifyProfileViewModel.swift in Sources */,
5722462928C77D64009B7C78 /* SearchAddressResultBottomSheet.swift in Sources */,
235613FD28D09DCD00D44E97 /* ZatchTableViewCell.swift in Sources */,
EE42D5C22A1B3575001BEF64 /* SearchRouter.swift in Sources */,
23B051CA28E21BAD005D08EA /* MyQuestionTableViewCell.swift in Sources */,
57A28D5628D1A0BB00263079 /* GetTownResponseModel.swift in Sources */,
57713944281F596C0066DEEB /* TopTitleView.swift in Sources */,
Expand Down Expand Up @@ -2891,6 +2917,7 @@
576341A728D29CC70067D2C5 /* BlockUserViewController.swift in Sources */,
EE1840CE2A0C9FAB00DF5D06 /* ZatchLikeResponseModel.swift in Sources */,
EE7AFF5729D16652007872B9 /* MeetingLocationRegisterMapViewController.swift in Sources */,
EE42D5C42A1B357C001BEF64 /* SearchService.swift in Sources */,
574EC1ED282E62A000E3CE4B /* RegisterCategorySelectTableViewCell.swift in Sources */,
57FFEDC528DD2F0D0041719B /* CheckShareRegisterViewController.swift in Sources */,
EE0AD54729E5033400C1CDA1 /* RegisterFirstInfoViewController.swift in Sources */,
Expand Down Expand Up @@ -2978,6 +3005,7 @@
571C0C7728AB5070002293B6 /* HiddenDeleteView.swift in Sources */,
23B7FBB028CECEAF0018642E /* MyZatchStatisticTableViewCell.swift in Sources */,
232DD0AD28ECE00900BC6E91 /* OtherReviewTableViewCell.swift in Sources */,
EE42D5BF2A1B33FC001BEF64 /* PopularKeywordResponseModel.swift in Sources */,
57D6D78D28CDB59100F805B7 /* MessageAlertViewController.swift in Sources */,
5722461028C074AE009B7C78 /* TimePickerAlertViewController.swift in Sources */,
57468A74289D071100056691 /* UIButton.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Zatch/AppDelegate/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// var startViewController: UIViewController
// startViewController = UserManager.token == nil ? UINavigationController(rootViewController: OnboardingViewController()) : TabBarController()

window?.rootViewController = UINavigationController(rootViewController: ZatchDetailViewController.getInstance(data: TemporaryData.zatch))
window?.rootViewController = UINavigationController(rootViewController: FindWantZatchSearchViewController())
// window?.rootViewController = TabBarController()
window?.makeKeyAndVisible()
}
Expand Down
4 changes: 4 additions & 0 deletions Zatch/Data/Foundation/HTTPMethodURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
enum HTTPMethodURL {

static let zatchUrl = "/zatch"
static let searchUrl = "/search"
static let userUrl = "/users"
static let kakaoLocal = "/v2/local"

Expand All @@ -21,6 +22,9 @@ enum HTTPMethodURL {

//USER
static let logout = userUrl + "/logout"

//SEARCH
static let popularKeywords = zatchUrl + searchUrl + "/popularItem"
}

struct POST {
Expand Down
23 changes: 23 additions & 0 deletions Zatch/Data/Models/Search/PopularKeywordResponseModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// PopularKeywordResponseModel.swift
// Zatch
//
// Created by λ°•μ†Œμœ€ on 2023/05/22.
//

import Foundation

struct PopularKeywordsResponseModel: Decodable{
let popularItem: [PopularKeywords]
}

struct PopularKeywords: Decodable{

let keyword: String
let likeCount: Int

enum CodingKeys: String, CodingKey{
case keyword = "md_name"
case likeCount = "like_count"
}
}
36 changes: 36 additions & 0 deletions Zatch/Data/MoyaService/Search/SearchRouter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// SearchRouter.swift
// Zatch
//
// Created by λ°•μ†Œμœ€ on 2023/05/22.
//

import Foundation
import Moya

enum SearchRouter: BaseRouter{
case getPopularKeywords
}

extension SearchRouter{

var path: String {
switch self {
case .getPopularKeywords: return HTTPMethodURL.GET.popularKeywords
}
}

var method: Moya.Method {
switch self {
case .getPopularKeywords: return .get
}
}

var task: Task {
switch self{
case .getPopularKeywords: return .requestPlain
}
}
}


22 changes: 22 additions & 0 deletions Zatch/Data/MoyaService/Search/SearchService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// SearchService.swift
// Zatch
//
// Created by λ°•μ†Œμœ€ on 2023/05/22.
//

import Foundation

public class SearchService {

static let shared = SearchService()
let provider = BaseService(plugins: [MoyaLoggerPlugin()])

private init() { }

func getPopularKeywords(completion: @escaping (Result<PopularKeywordsResponseModel, Error>) -> Void){
provider.requestDecoded(SearchRouter.getPopularKeywords){ response in
completion(response)
}
}
}
18 changes: 16 additions & 2 deletions Zatch/Data/Repository/SearchRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@
//

import Foundation
import RxSwift

class SearchRepository: SearchRepositotyInterface{

func getSearchResult() {

}

func getPopularKeyword() {

func getPopularKeywords() -> Observable<[PopularKeywords]?> {
let observable = Observable<[PopularKeywords]?>.create { observer -> Disposable in
let requestReference: () = SearchService.shared.getPopularKeywords{ response in
switch response {
case .success(let data):
observer.onNext(data.popularItem)
case .failure:
observer.onNext(nil)
}
}
return Disposables.create(with: { requestReference })
}
return observable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
//

import Foundation
import RxSwift

protocol SearchRepositotyInterface{
func getPopularKeyword()
func getPopularKeywords() -> Observable<[PopularKeywords]?>
func getSearchResult()
}
10 changes: 4 additions & 6 deletions Zatch/Domain/UseCase/Search/PopularKeywordUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
//

import Foundation

struct PopularKeywordRequestValue {
}
import RxSwift

protocol PopularKeywordUseCaseInterface {
func execute(requestValue: PopularKeywordRequestValue) async throws
func execute() -> Observable<[PopularKeywords]?>
}

final class PopularKeywordUseCase: PopularKeywordUseCaseInterface {
Expand All @@ -22,7 +20,7 @@ final class PopularKeywordUseCase: PopularKeywordUseCaseInterface {
self.searchRepository = searchRepository
}

func execute(requestValue: PopularKeywordRequestValue) async throws {
return try await searchRepository.getPopularKeyword()
func execute() -> Observable<[PopularKeywords]?>{
return searchRepository.getPopularKeywords()
}
}
Loading

0 comments on commit f0e9bdb

Please sign in to comment.