Skip to content

Commit

Permalink
feat(Announcement): Image integration
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo849 committed Aug 24, 2024
1 parent 9cd9439 commit 86e82d2
Show file tree
Hide file tree
Showing 29 changed files with 8,208 additions and 1,581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/**
Represents an organization containing a list of todos.
Represents an organization containing a list of annuncements.
*/
public struct AnnouncementOrganizationEntity: Identifiable, Equatable {
/// Unique identifier for the organization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public struct AnnouncementSummaryEntity: Identifiable, Equatable {
public let createdAt: Date?

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

/// Title of the announcement
public let title: String
Expand All @@ -41,18 +41,18 @@ public struct AnnouncementSummaryEntity: Identifiable, Equatable {
public init(
id: Int64,
organizationId: Int64,
imageUrl: String? = nil,
createdAt: Date? = nil,
coverImageUrl: URL?,
createdAt: Date?,
title: String,
body: String,
endAt: Date? = nil,
placeName: String? = nil,
todoCount: Int? = nil
endAt: Date?,
placeName: String?,
todoCount: Int?
) {
self.id = id
self.organizationId = organizationId
self.createdAt = createdAt
self.imageUrl = imageUrl
self.coverImageUrl = coverImageUrl
self.title = title
self.body = body
self.endAt = endAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ final class _GetAnnouncementsByOrganizationUsecase {
)
)
.withUnretained(self)
.flatMap { _, result -> Observable<Output> in
.flatMap { owner, result -> Observable<Output> in
if let content = result.content {
// owner.page += 1 // TODO: v1.1.0에 페이징 로직 추가
owner.page += 1

let announcements = content.map {
AnnouncementSummaryEntity(
return AnnouncementSummaryEntity(
id: $0.announcementId ?? -1,
organizationId: input.organizationId,
imageUrl: $0.profileImageUrl,
coverImageUrl: URL(string: $0.profileImageUrl ?? ""),
createdAt: $0.createdAt,
title: $0.title ?? "",
body: $0.content ?? "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public final class GetAnnouncementsByOrganizationUsecase {
)

return internalUsecase.execute(internalInput)
.debug("::: ")
.map { internalOutput in
return Output(announcements: internalOutput.announcements)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import Foundation
Represents the information of a new organization to be created.
*/
public struct NewOrganizationEntity: Equatable {
/// Unique identifier for the organization.
///
/// - Note: that this is not a globally unique value among all organizations,
/// but just a distinguishing identifier.
// public let id: Int

/// Name of the organization.
public let name: String

Expand All @@ -33,14 +27,12 @@ public struct NewOrganizationEntity: Equatable {
public let promotionCode: String?

public init(
// id: Int,
name: String,
categories: [Int],
imageURL: String? = nil,
endDate: Date? = nil,
promotionCode: String? = nil
imageURL: String?,
endDate: Date?,
promotionCode: String?
) {
// self.id = id
self.name = name
self.categories = categories
self.imageURL = imageURL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public struct OrganizationEntity: Identifiable, Equatable {
/// Name of the organization.
public let name: String

/// List of category IDs associated with the organization.
public let categories: [Int]
/// List of category associated with the organization.
public let categories: [String]

/// URL of the image associated with the organization (optional).
public let imageURL: String?
Expand All @@ -38,7 +38,7 @@ public struct OrganizationEntity: Identifiable, Equatable {
public init(
id: Int,
name: String,
categories: [Int],
categories: [String],
imageURL: String? = nil,
endDate: Date? = nil,
promotionCode: String? = nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// OrganizationSummaryEntity.swift
// OrganizationEntity
//
// Created by DOYEON LEE on 8/24/24.
//

import Foundation

/**
Summary of information about the organization.
*/
public struct OrganizationSummaryEntity: Identifiable, Equatable {
/// Unique identifier for the organization.
public let id: Int

/// Name of the organization.
public let name: String

/// Profile image url of the organization.
public let profileImageUrl: URL?

public init(
id: Int,
name: String,
profileImageUrl: URL? = nil
) {
self.id = id
self.name = name
self.profileImageUrl = profileImageUrl
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class GetMyOrganizationsUsecase {
}

public struct Output {
public let organizations: [OrganizationEntity]
public let organizations: [OrganizationSummaryEntity]

public init(
organizations: [OrganizationEntity]
organizations: [OrganizationSummaryEntity]
) {
self.organizations = organizations
}
Expand All @@ -50,15 +50,13 @@ public class GetMyOrganizationsUsecase {
.init(pageable: .init(page: Int32(self.page), size: Constant.PageSize))
)
.map { result in
// self.page += 1 // TODO: v1.1.0 때 페이징 구현
self.page += 1

let organizations: [OrganizationEntity] = result.content?.map {
OrganizationEntity(
let organizations: [OrganizationSummaryEntity] = result.content?.map {
OrganizationSummaryEntity(
id: Int($0.organizationId),
name: $0.organizationName,
categories: [], // TODO: remove
leader: 0, // TODO: remove
member: 0 // TODO: remove
profileImageUrl: URL(string: $0.profileImage)
)
} ?? []

Expand All @@ -73,9 +71,9 @@ public class GetMyOrganizationsUsecase {
// MARK: - Mock
private struct Mock {
static let OrganizationEntities: [OrganizationEntity] = [
.init(id: 1, name: "CMC 15th", categories: [1, 2, 3], leader: 1, member: 10),
.init(id: 2, name: "멋진 동아리", categories: [1, 2, 3], leader: 1, member: 3),
.init(id: 3, name: "즐거운 소모임", categories: [1, 2, 3], leader: 2, member: 15)
.init(id: 1, name: "CMC 15th", categories: ["IT", "예술"], leader: 1, member: 10),
.init(id: 2, name: "멋진 동아리", categories: ["IT", "예술"], leader: 1, member: 3),
.init(id: 3, name: "즐거운 소모임", categories: ["IT", "예술"], leader: 2, member: 15)
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,36 @@
// Created by DOYEON LEE on 8/18/24.
//

import Foundation

import Container
import OrganizationEntity
import Foundation
import OrganizationDataInterface

import Swinject
import OrganizationEntity
import RxSwift
import Swinject

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

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

public struct Output {
public let organization: OrganizationEntity
}

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

// MARK: Initializer
public init() { }
public init() {}

// MARK: Execute method
public func execute(_ input: Input) -> Observable<Output> {
let outputObservable = organizationRepository
return organizationRepository
.getOrganizationDetail(
.init(
organizationId: Int64(input.organizationId)
Expand All @@ -46,14 +44,12 @@ public struct GetOrganizationDetailUsecase {
let organization = OrganizationEntity(
id: Int(result.organizationId),
name: result.organizationName,
categories: [],
categories: result.categories,
leader: Int(result.leaderCount ?? 0),
member: Int(result.participantCount ?? 0)
)

return Output(organization: organization)
}

return outputObservable
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class AnnouncementDetailViewController: BaseViewController<AnnouncementDe
reactor.state.map { $0.organization }
.compactMap { $0 }
.observe(on: MainScheduler.instance)
.debug(":::")
.subscribe(
with: self,
onNext: { owner, organization in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct AnnouncementPageConverter {
) -> AnnouncementItem = { announcement, organization in
return AnnouncementItem(
state: .default,
coverImageUrl: announcement.coverImageUrl,
title: announcement.title,
date: announcement.endAt?.toString(includeWeekday: true) ?? "-",
location: announcement.placeName ?? "-",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ final class AnnouncementItem: CompositionalItem {

let state: NofficeAnnouncementCard.State

let coverImageUrl: URL?

let title: String?

let date: String?
Expand All @@ -37,12 +39,14 @@ final class AnnouncementItem: CompositionalItem {
// MARK: Initializer
init(
state: NofficeAnnouncementCard.State,
coverImageUrl: URL? = nil,
title: String? = nil,
date: String? = nil,
location: String? = nil,
onTap: @escaping () -> Void = { }
) {
self.state = state
self.coverImageUrl = coverImageUrl
self.title = title
self.date = date
self.location = location
Expand Down Expand Up @@ -95,6 +99,9 @@ final class AnnouncementItemCell: UIView, CompositionalItemCell {
organizationCard.locationText = location
}

print("::: cover \(item.coverImageUrl)")
organizationCard.coverImageUrl = item.coverImageUrl

// action binding
organizationCard.rx.tapGesture()
.when(.recognized)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class AnnouncementPageViewController: BaseViewController<AnnouncementPageView> {
override func setupStateBind() {
reactor.state.map { $0.organizations }
.withUnretained(self)
.debug(":::")
.map { owner, organizations in
[
BannerSection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class SelectOrganizationPageReactor: Reactor {
enum Action {
case viewDidLoad
case tapNextPageButton
case changeSelectedOrganization(OrganizationEntity?)
case changeSelectedOrganization(OrganizationSummaryEntity?)
}

enum Mutation {
case setMyOrganizations([OrganizationEntity])
case setSelectedOrganization(OrganizationEntity?)
case setMyOrganizations([OrganizationSummaryEntity])
case setSelectedOrganization(OrganizationSummaryEntity?)
case changeNextButtonActive(Bool)
}

// MARK: State
struct State {
var myOrganizations: [OrganizationEntity] = []
var selectedOrganization: OrganizationEntity?
var myOrganizations: [OrganizationSummaryEntity] = []
var selectedOrganization: OrganizationSummaryEntity?
var nextButtonActive: Bool = false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SelectOrganizationPageView: BaseView {
}

// - Organization list
lazy var organizationGroup = BaseRadioGroup<OrganizationEntity>( // TODO: 추후 스크롤뷰로 변경..
lazy var organizationGroup = BaseRadioGroup<OrganizationSummaryEntity>( // TODO: 추후 스크롤뷰로 변경..
animation: true
) { option in
NofficeList(option: option) { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SelectOrganizationPageViewController: BaseViewController<SelectOrganizatio
// - Bind my organizations
reactor.state.map { $0.myOrganizations }
.distinctUntilChanged()
.observe(on: MainScheduler.asyncInstance)
.observe(on: MainScheduler.asyncInstance)
.withUnretained(self)
.subscribe(onNext: { owner, value in
owner.baseView.organizationGroup.updateSource(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ReactorKit
class OrganizationDetailReactor: Reactor {
// MARK: Action
enum Action {
case viewDidLoad(OrganizationEntity)
case viewDidLoad(OrganizationSummaryEntity)
}

enum Mutation {
Expand Down
Loading

0 comments on commit 86e82d2

Please sign in to comment.