Skip to content

Commit

Permalink
impv(OrganizationPresent): Add organization tab reactor and bind
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo849 committed Jul 31, 2024
1 parent 7651892 commit 9556603
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension AnnouncementTarget: TargetType {

var path: String {
switch self {
case .createOrganization:
case .createAnnouncement:
return "/organization"

case let .getOrganization(id):
Expand All @@ -43,7 +43,7 @@ extension AnnouncementTarget: TargetType {

var method: Moya.Method {
switch self {
case .createOrganization, .joinOrganization:
case .createAnnouncement, .joinOrganization:
return .post

case .getOrganization, .getOrganizationList:
Expand All @@ -57,8 +57,8 @@ extension AnnouncementTarget: TargetType {

var task: Task {
switch self {
case .createOrganization(let dto):
return .requestJSONEncodable(dto)
case .createAnnouncement:
return .requestPlain

case .joinOrganization(_, let userId):
return .requestParameters(
Expand All @@ -75,4 +75,3 @@ extension AnnouncementTarget: TargetType {
return ["Content-type": "application/json"]
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct BaseResponse<T: Codable>: Codable {
httpStatus: Int,
code: String,
message: String,
data: Codable
data: T
) {
self.timestamp = timestamp
self.httpStatus = httpStatus
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FetchAllAnnouncementUsecase.swift
// GetAllAnnouncementUsecase.swift
// AnnouncementEntity
//
// Created by DOYEON LEE on 7/22/24.
Expand All @@ -11,7 +11,7 @@ import AnnouncementEntity

import RxSwift

public struct FetchAllAnnouncementUsecase {
public struct GetAllAnnouncementUsecase {

public init() { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FetchAnnouncementDetailUsecase.swift
// GetAnnouncementDetailUsecase.swift
// AnnouncementUsecase
//
// Created by DOYEON LEE on 7/26/24.
Expand All @@ -11,7 +11,7 @@ import AnnouncementEntity

import RxSwift

public struct FetchAnnouncementDetailUsecase {
public struct GetAnnouncementDetailUsecase {

public init() { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FetchMyOrganizations.swift
// GetMyOrganizationsUsecase.swift
// OrganizationUsecase
//
// Created by DOYEON LEE on 7/22/24.
Expand All @@ -9,7 +9,7 @@ import OrganizationEntity

import RxSwift

public struct FetchMyOrganizations {
public struct GetMyOrganizationsUsecase {

public init() { }

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AnnouncementDetailReactor: Reactor {
let initialState: State = State()

// MARK: Dependency
private let fetchAnnouncementDetailUsecase = FetchAnnouncementDetailUsecase()
private let fetchAnnouncementDetailUsecase = GetAnnouncementDetailUsecase()

// MARK: DisposeBag
private let disposeBag = DisposeBag()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AnnouncementDetailViewController: BaseViewController<AnnouncementDe
if let announcement = announcement {
self.announcement = announcement
} else {
self.announcement = FetchAnnouncementDetailUsecase.mock
self.announcement = GetAnnouncementDetailUsecase.mock
}

super.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AnnouncementPageReactor: Reactor {
}

// MARK: Dependency
let fetchAllAnnouncementUsecase = FetchAllAnnouncementUsecase()
let fetchAllAnnouncementUsecase = GetAllAnnouncementUsecase()

let initialState: State = State()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SelectOrganizationPageReactor: Reactor {
let initialState: State = State()

// MARK: Dependency
private let fetchMyOrganizations = FetchMyOrganizations()
private let fetchMyOrganizations = GetMyOrganizationsUsecase()

// MARK: DisposeBag
private let disposeBag = DisposeBag()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extension Container {
static let shared: Container = {
let container = Container()

// - New organization funnel
container.register(NewOrganizationFunnelReactor.self) { resolver in
NewOrganizationFunnelReactor(
nameReactor: resolver.resolve(NewOrganizationNamePageReactor.self)!,
Expand Down Expand Up @@ -52,6 +53,18 @@ extension Container {
NewOrganizationCompletePageReactor()
}
.inObjectScope(.weak)

// - Organization tab
container.register(OrganizationTabReactor.self) { _ in
OrganizationTabReactor()
}
.inObjectScope(.transient)

// - Organization detail
container.register(OrganizationDetailReactor.self) { _ in
OrganizationDetailReactor()
}
.inObjectScope(.transient)

return container
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import OrganizationEntity

import RxSwift
import RxCocoa
import Swinject

class OrganizationDetailViewController: BaseViewController<OrganizationDetailView> {
// MARK: Reactor
private let reactor = Container.shared.resolve(OrganizationDetailReactor.self)!

// MARK: Data
private let organization: OrganizationEntity

// MARK: Initialzier
// example app 때문에 임시로 optional 처리
public init(organization: OrganizationEntity) {
self.organization = organization

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// OrganizationTabConverter.swift
// OrganizationPresent
//
// Created by DOYEON LEE on 7/31/24.
//

import DesignSystem
import OrganizationEntity

struct OrganizationTabConverter {
static func convert(
entities: [OrganizationEntity],
onTapNewButton: @escaping () -> Void,
onTapOrganizationRow: @escaping (OrganizationEntity) -> Void
) -> [any CompositionalSection] {
let sections: [any CompositionalSection] = [
NewOrganizationSection(
items: [
NewOrganizationItem() {
onTapNewButton()
}
]
),
OrganizationSection(
items: entities.map { organization in
OrganizationItem(
organizationName: organization.name
) {
onTapOrganizationRow(organization)
}
}
)
]

return sections
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ final class NewOrganizationItem: CompositionalItem {
typealias Cell = NewOrganizationAddItemCell

// MARK: Event
let onTapNewButton = PublishSubject<Void>()
let onTap: () -> Void

// MARK: DisposeBag
let disposeBag = DisposeBag()

init() { }
init(
onTapNewButton: @escaping () -> Void
) {
self.onTap = onTapNewButton
}

func hash(into hasher: inout Hasher) {
hasher.combine(String(describing: type(of: self)))
Expand Down Expand Up @@ -49,6 +53,7 @@ final class NewOrganizationAddItemCell: UIView, CompositionalItemCell {
// MARK: DisposeBag
private let disposeBag = DisposeBag()

// MARK: Initializer
required init?(coder: NSCoder) {
super.init(coder: coder)
setup()
Expand All @@ -70,7 +75,9 @@ final class NewOrganizationAddItemCell: UIView, CompositionalItemCell {
func configure(with item: NewOrganizationItem) {
// action binding
newButton.onTap
.bind(to: item.onTapNewButton)
.subscribe(onNext: {
item.onTap()
})
.disposed(by: disposeBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class OrganizationItem: CompositionalItem {
typealias Cell = OrganizationItemCell

// MARK: Event
let onTap = PublishSubject<Void>()
let onTap: () -> Void

// MARK: Data
let organizationName: String
Expand All @@ -26,8 +26,12 @@ final class OrganizationItem: CompositionalItem {
let disposeBag = DisposeBag()

// MARK: Initializer
init(organizationName: String) {
init(
organizationName: String,
onTap: @escaping () -> Void
) {
self.organizationName = organizationName
self.onTap = onTap
}

func hash(into hasher: inout Hasher) {
Expand Down Expand Up @@ -66,8 +70,10 @@ final class OrganizationItemCell: UIView, CompositionalItemCell {
organizationRow.organizationName = item.organizationName

// - Binding action
self.organizationRow.onTap
.bind(to: item.onTap)
organizationRow.onTap
.subscribe(onNext: {
item.onTap()
})
.disposed(by: disposeBag)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// OrganizationTabReactor.swift
// OrganizationPresent
//
// Created by DOYEON LEE on 7/31/24.
//

import OrganizationUsecase
import OrganizationEntity

import ReactorKit

class OrganizationTabReactor: Reactor {
// MARK: Action
enum Action {
case viewDidLoad
}

enum Mutation {
case setOrganizations([OrganizationEntity])
}

// MARK: State
struct State {
var organizations: [OrganizationEntity] = []
}

let initialState: State = State()

// MARK: ChildReactor

// MARK: Dependency
private let getMyOrganizationsUsecase = GetMyOrganizationsUsecase()

// MARK: DisposeBag
private let disposeBag = DisposeBag()

// MARK: Initializer
init() { }

// MARK: Action operation
func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .viewDidLoad:
return getMyOrganizationsUsecase.execute()
.map { Mutation.setOrganizations($0) }
}
}

func reduce(state: State, mutation: Mutation) -> State {
var state = state
switch mutation {
case let .setOrganizations(organizations):
state.organizations = organizations
}
return state
}

// MARK: Child bind
private func setupChildBind() { }

// MARK: Transform

// MARK: Private method
}
Loading

0 comments on commit 9556603

Please sign in to comment.