Skip to content

Commit

Permalink
feat(AnnouncementDomain): Add AnnouncementSummaryEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo849 committed Aug 18, 2024
1 parent a451a9a commit 9b7d988
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// AnnouncementSummaryEntity.swift
// AnnouncementEntity
//
// Created by DOYEON LEE on 8/18/24.
//

import Foundation

/**
Represents a announcement in group(organization).
*/
public struct AnnouncementSummaryEntity: Identifiable, Equatable {
/// Unique identifier for the announcement item
public let id: Int

/// ID of organization that will generate announcement
public let organizationId: Int

/// Announcement creation date
public let createdAt: Date?

/// Image URL for the announcement illustration. (optional)
public let imageUrl: String?

/// Title of the announcement
public let title: String

/// Body text of the announcement
public let body: String

/// Place of the announcement (optional)
public let placeName: String?

/// Count of todo items (optional)
public let todoCount: Int?

public init(
id: Int,
organizationId: Int,
imageUrl: String? = nil,
createdAt: Date? = nil,
title: String,
body: String,
placeName: String? = nil,
todoCount: Int? = nil
) {
self.id = id
self.organizationId = organizationId
self.createdAt = createdAt
self.imageUrl = imageUrl
self.title = title
self.body = body
self.placeName = placeName
self.todoCount = todoCount
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ extension AppleLoginUsecase: ASAuthorizationControllerDelegate,
return Observable.error(Error.invalidToken)
}
}
.debug()
.subscribe(onNext: { [weak self] output in
self?.authorizationResultSubject.onNext(output)
}, onError: { [weak self] error in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,77 @@
//
// GetAnnouncementsByGroup.swift
// GetAnnouncementsByGroupUsecase.swift
// AnnouncementUsecase
//
// Created by DOYEON LEE on 8/1/24.
//

import Foundation

import Container
import OrganizationEntity
import AnnouncementEntity
import OrganizationDataInterface

import Swinject
import RxSwift

public struct GetAnnouncementsByGroup {
import RxSwift

public struct GetAnnouncementsByGroupUsecase {
// MARK: DTO
public struct Input {
public let organizationId: Int

public init(organizationId: Int) {
self.organizationId = organizationId
}
}

public struct Output {
public let announcements: [AnnouncementSummaryEntity]
}

// MARK: Error
public enum Error: LocalizedError {
case contentFieldNotFound
}

// MARK: Dependency
private let organizationRepository = Container.shared.resolve(OrganizationRepositoryInterface.self)!

// MARK: Initializer
public init() { }

public func execute(groupId: Int) -> Observable<[AnnouncementEntity]> {
return .just(Mock.AnnouncementEntities)
// MARK: Execute method
public func execute(_ input: Input) -> Observable<Output> {


let outputObservable = organizationRepository.getPublishedAnnouncements(
.init(
organizationId: Int64(input.organizationId),
pageable: .init() // TODO:
)
).flatMap { result -> Observable<Output> in
if let content = result.content {
let announcements = content.map {
AnnouncementSummaryEntity(
id: Int($0.announcementId ?? -1),
organizationId: input.organizationId,
imageUrl: $0.profileImageUrl,
createdAt: $0.createdAt,
title: $0.title ?? "",
body: $0.content ?? "",
placeName: $0.placeLinkName,
todoCount: 0 // todo 조회 API 사용? 같이 담아줄 수 있는지 요청 필요
)
}
return Observable.just(Output(announcements: announcements))
} else {
return Observable.error(Error.contentFieldNotFound)
}
}

return outputObservable
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ import AnnouncementEntity

struct OrganizationDetailConverter {
static func convert(
from announcements: [AnnouncementEntity],
onTapAnnouncementItem: @escaping (AnnouncementEntity) -> Void
from announcements: [AnnouncementSummaryEntity],
onTapAnnouncementItem: @escaping (AnnouncementSummaryEntity) -> Void
) -> [any CompositionalSection] {
return [
AnnouncementSection(
items: announcements.map { announcement in
AnnouncementItem(
id: announcement.id,
title: announcement.title,
endDate: announcement.endAt,
place: announcement.place?.name,
todoCount: announcement.todos?.count,
place: announcement.placeName,
todoCount: announcement.todoCount,
body: announcement.body,
createdDate: announcement.createdAt ?? .now,
onTap: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class OrganizationDetailReactor: Reactor {

enum Mutation {
case setOrganization(OrganizationEntity)
case setAnnouncements([AnnouncementEntity])
case setAnnouncements([AnnouncementSummaryEntity])
}

// MARK: State
struct State {
var organization: OrganizationEntity?
var announcements: [AnnouncementEntity] = []
var announcements: [AnnouncementSummaryEntity] = []
}

let initialState: State = State()
Expand All @@ -36,7 +36,7 @@ class OrganizationDetailReactor: Reactor {
// MARK: Dependency
private let getOrganizationDetailUsecase = GetOrganizationDetailUsecase()

private let getAnnouncementsByGroupUseCase = GetAnnouncementsByGroup()
private let getAnnouncementsByGroupUseCase = GetAnnouncementsByGroupUsecase()

// MARK: DisposeBag
private let disposeBag = DisposeBag()
Expand All @@ -50,12 +50,15 @@ class OrganizationDetailReactor: Reactor {
case let .viewDidLoad(organization):
let setOrganization = getOrganizationDetailUsecase
.execute(.init(organizationId: organization.id))
.map { Mutation.setOrganization($0.organization) }
.map { output in
Mutation.setOrganization(output.organization)
}

let setAnnouncements = getAnnouncementsByGroupUseCase
.execute(groupId: organization.id)
.delay(.seconds(2), scheduler: MainScheduler.instance)
.map { Mutation.setAnnouncements($0) }
.execute(.init(organizationId: organization.id))
.map { output in
Mutation.setAnnouncements(output.announcements)
}

return .merge(
setOrganization,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class OrganizationDetailViewController: BaseViewController<OrganizationDetailVie
)
]
)
.debug()
.bind(to: baseView.announcementsCollectionView.sectionBinder)
.disposed(by: disposeBag)
}
Expand Down Expand Up @@ -92,11 +91,11 @@ class OrganizationDetailViewController: BaseViewController<OrganizationDetailVie
.filter { !$0.isEmpty }
.map {
OrganizationDetailConverter.convert(from: $0) { announcement in
Router.shared.push(
.announcementDetail(
announcementEntity: announcement
)
)
// Router.shared.push(
// .announcementDetail(
// announcementEntity: announcement
// )
// )
}
}
.bind(to: baseView.announcementsCollectionView.sectionBinder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class OrganizationTabReactor: Reactor {
switch action {
case .viewDidLoad:
return getMyOrganizationsUsecase.execute(.init())
.debug()
.map { Mutation.setOrganizations($0.organizations) }
}
}
Expand All @@ -52,7 +51,6 @@ class OrganizationTabReactor: Reactor {
var state = state
switch mutation {
case let .setOrganizations(organizations):
print("와웅")
state.organizations = organizations
}
return state
Expand Down

0 comments on commit 9b7d988

Please sign in to comment.