Skip to content

Commit

Permalink
Merge pull request #23 from NAGAZA-Team/Feature/map_serach_api
Browse files Browse the repository at this point in the history
Map Search 화면 구현
  • Loading branch information
Minny27 authored Mar 20, 2024
2 parents 0114177 + 11d324c commit 74a7997
Show file tree
Hide file tree
Showing 24 changed files with 652 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,26 @@ final class MapSceneDIContainer: MapFlowCoordinaterDependencies {
MapViewController.create(with: makeMapViewModel(actions: actions))
}

private func makeMapViewModel(actions: MapViewModelActions) -> MapViewModel
{
private func makeMapViewModel(actions: MapViewModelActions) -> MapViewModel {
MapViewModel(actions: actions)
}

func makeMapSearchViewController(actions: MapSearchViewModelActions) -> MapSearchViewController {
MapSearchViewController.create(with: makeMapSearchViewModel(actions: actions))
}

private func makeMapUseCase() -> MapRepositoryInterface {
return MapRepository(
isStub: true,
sampleStatusCode: 200,
customEndpointClosure: nil
)
}

private func makeMapSearchViewModel(actions: MapSearchViewModelActions) -> MapSearchViewModel {
MapSearchViewModel(mapUseCase: makeMapUseCase(), actions: actions)
}

func makeMapFlowCoordinator(navigationController: UINavigationController) -> MapFlowCoordinator {
MapFlowCoordinator(
navigationController: navigationController,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// KeywordResponseDTO.swift
// Nagaza
//
// Created by SeungMin on 3/14/24.
//

struct RecentKeywordResponse: Decodable {
let keywordList: [RecentKeywordResponseDTO]
let page: Int
let totalPages: Int

enum CodingKeys: String, CodingKey {
case keywordList
case page
case totalPages = "total_pages"
}
}

struct RecentKeywordResponseDTO: Decodable {
let keyword: String
}

extension RecentKeywordResponse {
func toDomain() -> RecentKeywordPage {
return RecentKeywordPage(
keywordList: self.keywordList.map { $0.toDomain() },
page: self.page,
totalPages: self.totalPages
)
}
}

extension RecentKeywordResponseDTO {
func toDomain() -> RecentKeyword {
return RecentKeyword(
keyword: self.keyword
)
}
}
28 changes: 28 additions & 0 deletions Nagaza/Sources/Data/Repositories/Map/MapRepository.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// MapRepository.swift
// Nagaza
//
// Created by SeungMin on 3/14/24.
//

import RxSwift
import Moya

final class MapRepository: ProviderProtocol {
typealias Target = MapTarget
var provider: MoyaProvider<Target>

init(isStub: Bool, sampleStatusCode: Int, customEndpointClosure: ((Target) -> Moya.Endpoint)?) {
self.provider = Self.consProvider(isStub, sampleStatusCode, customEndpointClosure)
}
}

extension MapRepository: MapRepositoryInterface {
func fetchRecentKeywordList() -> Single<RecentKeywordPage> {
request(
type: RecentKeywordResponse.self,
target: .fetchRecentKeywordList
)
.map { $0.toDomain() }
}
}
39 changes: 39 additions & 0 deletions Nagaza/Sources/Data/Repositories/Map/MapTarget+SampleData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// MapTarget+SampleData.swift
// Nagaza
//
// Created by SeungMin on 3/14/24.
//

import Foundation

import Moya

extension MapTarget {
var sampleData: Data {
switch self {
case .fetchRecentKeywordList:
return Data(
"""
{
"keywordList": [
{
"keyword": "리그오브디저트"
},
{
"keyword": "방탈출"
},
{
"keyword": "풀문"
},
{
"keyword": "마스터키"
}
],
"page": 1,
"total_pages": 1
}
""".utf8)
}
}
}
36 changes: 36 additions & 0 deletions Nagaza/Sources/Data/Repositories/Map/MapTarget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// MapTarget.swift
// Nagaza
//
// Created by SeungMin on 3/14/24.
//

import Moya

enum MapTarget {
case fetchRecentKeywordList
}

extension MapTarget: BaseTargetType {
var path: String {
switch self {
case .fetchRecentKeywordList:
return "v1/search/keyword"
}
}

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

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

33 changes: 33 additions & 0 deletions Nagaza/Sources/Domain/Entities/RecentKeyword.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// RecentKeyword.swift
// Nagaza
//
// Created by SeungMin on 3/13/24.
//

import Foundation

enum SearchSection {
case home
}

struct RecentKeyword: Hashable {
let identifier = UUID()
let keyword: String
}

struct RecentKeywordPage {
let keywordList: [RecentKeyword]
let page: Int
let totalPages: Int
}

extension RecentKeyword {
public func hash(into hasher: inout Hasher) {
hasher.combine(identifier)
}

public static func == (lhs: RecentKeyword, rhs: RecentKeyword) -> Bool {
lhs.identifier == rhs.identifier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Created by SeungMin on 1/6/24.
//

import Foundation

import RxSwift

protocol HomeRepositoryInterface {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// MapRepositoryInterface.swift
// Nagaza
//
// Created by SeungMin on 3/14/24.
//

import RxSwift

protocol MapRepositoryInterface {
func fetchRecentKeywordList() -> Single<RecentKeywordPage>
}
20 changes: 20 additions & 0 deletions Nagaza/Sources/Domain/UseCases/Map/MapUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// MapUseCase.swift
// Nagaza
//
// Created by SeungMin on 3/14/24.
//

import RxSwift

final class MapUseCase {
private let repository: MapRepositoryInterface

init(roomsRepository: MapRepositoryInterface) {
self.repository = roomsRepository
}

func fetchCafesList() -> Single<RecentKeywordPage> {
return repository.fetchRecentKeywordList()
}
}
10 changes: 7 additions & 3 deletions Nagaza/Sources/Presentation/Base/NagazaBaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ class NagazaBaseViewController: UIViewController {

/// Set up Navigation Bar
func navigationSetting() {
navigationController?.navigationBar.backIndicatorImage = NagazaAsset.Images.icArrowRightGray.image
navigationController?.navigationBar.backIndicatorTransitionMaskImage = NagazaAsset.Images.icArrowRightGray.image
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.tintColor = NagazaAsset.Colors.gray3.color
navigationItem.backBarButtonItem = UIBarButtonItem(
title: nil,
style: .plain,
target: nil,
action: nil
)

let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
Expand Down
29 changes: 29 additions & 0 deletions Nagaza/Sources/Presentation/Base/NagazaCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// NagazaCollectionViewCell.swift
// Nagaza
//
// Created by SeungMin on 3/14/24.
//

import UIKit
import RxSwift

class NagazaCollectionViewCell: UICollectionViewCell {
var disposeBag = DisposeBag()

override init(frame: CGRect) {
super.init(frame: frame)
makeUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func prepareForReuse() {
self.disposeBag = DisposeBag()
super.prepareForReuse()
}

func makeUI() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import UIKit

protocol MapFlowCoordinaterDependencies {
func makeMapViewController(actions: MapViewModelActions) -> MapViewController
func makeMapSearchViewController(actions: MapSearchViewModelActions) -> MapSearchViewController
}

final class MapFlowCoordinator: Coordinator {
Expand Down Expand Up @@ -37,13 +38,19 @@ final class MapFlowCoordinator: Coordinator {
}

func start() {
let actions = MapViewModelActions()
let actions = MapViewModelActions(toMapSearch: toMapSearch)
let vc = dependencies.makeMapViewController(actions: actions)

navigationController.setNavigationBarHidden(false, animated: false)
navigationController.pushViewController(vc, animated: false)
navigationController = UINavigationController(rootViewController: vc)

mapVC = vc
}

func toMapSearch() {
let actions = MapSearchViewModelActions()
let vc = dependencies.makeMapSearchViewController(actions: actions)

navigationController.pushViewController(vc, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class HomeViewController: NagazaBaseViewController {
}()

private lazy var scrollView = UIScrollView()

private lazy var recommendedContainer: UIView = {
let view = UIView()
view.backgroundColor = .clear
Expand Down Expand Up @@ -221,10 +221,10 @@ extension HomeViewController {
let roomCellRegistraition = UICollectionView.CellRegistration<CellType, ModelType> { [weak self] cell, indexPath, item in

cell.bind(with: item)
// cell.delegate = self
// cell.delegate = self
}

let headerRegistration = UICollectionView.SupplementaryRegistration<SectionHeaderView>(elementKind: ElementKind.sectionHeader) { supplementaryView, elementKind, indexPath in
let headerRegistration = UICollectionView.SupplementaryRegistration<SectionHeaderView>(elementKind: UICollectionView.elementKindSectionHeader) { supplementaryView, elementKind, indexPath in
let sectionType = HomeSectionType(rawValue: indexPath.section) ?? .comic
supplementaryView.themeLabel.text = sectionType.title
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ final class ThemeCell: UICollectionViewCell {
self.titleLabel.text = model.name
self.branchLabel.text = model.area
self.ratedLabel.text = String(model.total)
self.posterImageView.loadImage(from: model.imageUrlString)
// self.posterImageView.loadImage(from: model.imageUrlString)
}

private func updatePosterImage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import UIKit

final class SectionHeaderView: UICollectionReusableView {
static let identifier = String(describing: SectionHeaderView.self)

lazy var themeLabel: UILabel = {
let label = UILabel()

Expand Down
Loading

0 comments on commit 74a7997

Please sign in to comment.