Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public struct ClassBattleDetail: Equatable, Identifiable, Sendable {
public let participantsCount: Int
public let audioDuration: Int
public let options: [ClassBattleOption]
/// 카테고리 태그 이름(예: `철학`). 커스텀 배틀도 서버가 주제 카테고리를 태그로 붙인다.
public let categoryTags: [String]

public init(
id: Int,
Expand All @@ -24,7 +26,8 @@ public struct ClassBattleDetail: Equatable, Identifiable, Sendable {
currentStep: ClassBattleStep,
participantsCount: Int,
audioDuration: Int,
options: [ClassBattleOption]
options: [ClassBattleOption],
categoryTags: [String] = []
) {
self.id = id
self.title = title
Expand All @@ -37,5 +40,6 @@ public struct ClassBattleDetail: Equatable, Identifiable, Sendable {
self.participantsCount = participantsCount
self.audioDuration = audioDuration
self.options = options
self.categoryTags = categoryTags
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct ClassDebate: Equatable, Sendable {
public let canReply: Bool
public let canRetry: Bool
public let philosopherName: String
public let philosopherImageURL: URL?
public let participantOptionTitle: String
public let opponentOptionTitle: String
public let messages: [ClassDebateMessage]
Expand All @@ -21,6 +22,7 @@ public struct ClassDebate: Equatable, Sendable {
canReply: Bool,
canRetry: Bool,
philosopherName: String,
philosopherImageURL: URL? = nil,
participantOptionTitle: String,
opponentOptionTitle: String,
messages: [ClassDebateMessage],
Expand All @@ -34,6 +36,7 @@ public struct ClassDebate: Equatable, Sendable {
self.canReply = canReply
self.canRetry = canRetry
self.philosopherName = philosopherName
self.philosopherImageURL = philosopherImageURL
self.participantOptionTitle = participantOptionTitle
self.opponentOptionTitle = opponentOptionTitle
self.messages = messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation
public enum ClassError: LocalizedError, Equatable, Sendable {
case invalidCode
case closed
case ticketEnded
case alreadyJoined
case duplicateName
case accessDenied
Expand Down Expand Up @@ -42,7 +43,8 @@ public enum ClassError: LocalizedError, Equatable, Sendable {
public var message: String {
switch self {
case .invalidCode: return "참여 코드를 다시 확인해 주세요."
case .closed: return "종료된 클래스입니다."
case .closed: return "참여 기간이 마감된 클래스입니다."
case .ticketEnded: return "이용 기간이 끝난 클래스입니다."
case .alreadyJoined: return "이미 참여한 클래스입니다."
case .duplicateName: return "이미 사용 중인 이름이에요."
case .accessDenied: return "클래스 결과를 볼 권한이 없어요."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public enum ClassTicketError: LocalizedError, Equatable, Sendable {
case claimed
case activeTicket
case notFound
/// 없는 코드를 1시간 안에 5번 넣어 1시간 동안 입력이 막힘(`TICKET_429_LOCKED`).
case locked
case invalidResponse
case network(String)

Expand All @@ -20,6 +22,7 @@ public enum ClassTicketError: LocalizedError, Equatable, Sendable {
case .claimed: return "이미 다른 계정에 등록된 이용권 코드예요."
case .activeTicket: return "이미 사용 중인 이용권이 있어요. 만료 후 등록할 수 있어요."
case .notFound: return "등록된 이용권이 없어요."
case .locked: return "코드를 5번 잘못 입력해 1시간 동안 입력할 수 없어요."
case .invalidResponse: return "이용권 정보를 읽지 못했어요. 다시 시도해 주세요."
case let .network(message): return message
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct ClassJoinPreview: Equatable, Sendable {
public let battleThumbnailURL: URL?
public let battleType: String
public let memberCount: Int
public let activeMemberCount: Int
public let capacity: Int
public let closeAt: Date

Expand All @@ -17,6 +18,7 @@ public struct ClassJoinPreview: Equatable, Sendable {
battleThumbnailURL: URL?,
battleType: String,
memberCount: Int,
activeMemberCount: Int? = nil,
capacity: Int,
closeAt: Date
) {
Expand All @@ -26,6 +28,7 @@ public struct ClassJoinPreview: Equatable, Sendable {
self.battleThumbnailURL = battleThumbnailURL
self.battleType = battleType
self.memberCount = memberCount
self.activeMemberCount = activeMemberCount ?? memberCount
self.capacity = capacity
self.closeAt = closeAt
}
Expand All @@ -38,6 +41,7 @@ public struct ClassJoinPreview: Equatable, Sendable {
battleThumbnailURL: room.battle.thumbnailURL,
battleType: room.battleType.rawValue,
memberCount: room.memberCount,
activeMemberCount: room.activeMemberCount,
capacity: room.memberCapacity ?? 0,
closeAt: room.deadline
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public struct ClassRoom: Equatable, Identifiable, Sendable {
public let deadline: Date
public let ticketExpiresAt: Date?
public let closeAt: Date?
/// 사용 좌석 수. 활동한 뒤 나간 사람도 포함한다. 남은 자리는 `memberCapacity - memberCount`.
public let memberCount: Int
/// 현재 명단 인원(참여하는 운영자 포함). 화면의 "멤버 N명"에 쓴다.
public let activeMemberCount: Int
public let memberCapacity: Int?
public let role: ClassRole
public let status: ClassStatus
Expand All @@ -32,6 +35,7 @@ public struct ClassRoom: Equatable, Identifiable, Sendable {
deadline: Date,
closeAt: Date? = nil,
memberCount: Int,
activeMemberCount: Int? = nil,
role: ClassRole,
status: ClassStatus,
allowsAnonymousOpinion: Bool,
Expand All @@ -50,6 +54,7 @@ public struct ClassRoom: Equatable, Identifiable, Sendable {
self.ticketExpiresAt = ticketExpiresAt
self.closeAt = closeAt
self.memberCount = memberCount
self.activeMemberCount = activeMemberCount ?? memberCount
self.memberCapacity = memberCapacity
self.role = role
self.status = status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ private extension ClassRoom {
deadline: deadline,
closeAt: closeAt,
memberCount: memberCount,
activeMemberCount: memberCount,
role: role,
status: status,
allowsAnonymousOpinion: allowsAnonymousOpinion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ struct ClassBattleSessionDTO: Decodable, Sendable {
let options: [Option]
}

struct Tag: Decodable, Sendable {
let name: String
}

let battleInfo: Info
let description: String?
let shareUrl: String?
let userVoteStatus: String?
let currentStep: String?
let categoryTags: [Tag]?

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ClassDomainInterface
struct ClassDebateDTO: Decodable, Sendable {
struct Philosopher: Decodable, Sendable {
let name: String
let imageUrl: String?
}

struct Option: Decodable, Sendable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct ClassListItemDTO: Decodable, Sendable {
let battleThumbnailUrl: String?
let battleType: ClassBattleType
let memberCount: Int
let activeMemberCount: Int?
let capacity: Int
let closeAt: String
let closed: Bool
Expand All @@ -31,6 +32,7 @@ struct ClassDetailDataDTO: Decodable, Sendable {
let battle: Battle
let battleType: ClassBattleType
let memberCount: Int
let activeMemberCount: Int?
let capacity: Int
let deadline: String?
let ticketExpiresAt: String
Expand All @@ -47,6 +49,7 @@ struct ClassJoinPreviewDataDTO: Decodable, Sendable {
let battleThumbnailUrl: String?
let battleType: String
let memberCount: Int
let activeMemberCount: Int?
let capacity: Int
let closeAt: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ extension ClassBattleSessionDTO.Battle {
currentStep: currentStep,
participantsCount: battleInfo.participantsCount ?? 0,
audioDuration: battleInfo.audioDuration ?? 0,
options: battleInfo.options.map { $0.toDomain() }
options: battleInfo.options.map { $0.toDomain() },
categoryTags: categoryTags?.map(\.name) ?? []
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ClassDomainInterface
import Foundation

extension ClassDebateDTO.Message {
func toDomain() throws -> ClassDebateMessage {
Expand Down Expand Up @@ -26,6 +27,7 @@ extension ClassDebateDTO {
canReply: canReply,
canRetry: canRetry,
philosopherName: philosopher.name,
philosopherImageURL: philosopher.imageUrl.flatMap(URL.init(string:)),
participantOptionTitle: participantOption.title,
opponentOptionTitle: opponentOption.title,
messages: messages.map { try $0.toDomain() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extension ClassListItemDTO {
deadline: .distantFuture,
closeAt: closeDate,
memberCount: memberCount,
activeMemberCount: activeMemberCount,
role: try myRole.classRole(),
status: closed ? .closed : .open,
allowsAnonymousOpinion: false,
Expand All @@ -38,6 +39,7 @@ extension ClassDetailDataDTO {
deadline: try deadline.map { try $0.classDate() } ?? .distantFuture,
closeAt: try closeAt.classDate(),
memberCount: memberCount,
activeMemberCount: activeMemberCount,
role: try myRole.classRole(),
status: closed ? .closed : .open,
allowsAnonymousOpinion: false,
Expand All @@ -59,6 +61,7 @@ extension ClassJoinPreviewDataDTO {
battleThumbnailURL: battleThumbnailUrl.flatMap(URL.init(string:)),
battleType: battleType,
memberCount: memberCount,
activeMemberCount: activeMemberCount,
capacity: capacity,
closeAt: try closeAt.classDate()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ enum ClassErrorMapper {
private static func classError(code: String) -> ClassError? {
switch code {
case "CLASS_404_CODE": return .invalidCode
case "CLASS_409_CLOSED", "CLASS_409_TICKET_ENDED": return .closed
case "CLASS_409_CLOSED": return .closed
case "CLASS_409_TICKET_ENDED": return .ticketEnded
case "CLASS_409_JOINED": return .alreadyJoined
case "CLASS_409_NAME": return .duplicateName
case "CLASS_404": return .notFound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extension ClassRepositoryImpl {
case "TICKET_409_CLAIMED": return .claimed
case "TICKET_409_ACTIVE": return .activeTicket
case "TICKET_404": return .notFound
case "TICKET_429_LOCKED": return .locked
default: return .network(response.message ?? "이용권 정보를 불러오지 못했어요.")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct ClassErrorMappingTests {
@Test(arguments: [
("CLASS_404_CODE", ClassError.invalidCode),
("CLASS_409_CLOSED", .closed),
("CLASS_409_TICKET_ENDED", .closed),
("CLASS_409_TICKET_ENDED", .ticketEnded),
("CLASS_409_JOINED", .alreadyJoined),
("CLASS_409_NAME", .duplicateName),
("CLASS_404", .notFound),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public struct ClassAIChatFeature {
}

public var opponentAvatarURL: URL? {
selectedOptionID == 1 ? room.battle.philosopherBImageURL : room.battle.philosopherAImageURL
// 이름과 얼굴이 어긋나지 않게 서버가 준 토론 철학자 이미지를 먼저 쓴다.
if let url = debate?.philosopherImageURL { return url }
return selectedOptionID == 1 ? room.battle.philosopherBImageURL : room.battle.philosopherAImageURL
}

public var quickReplies: [String] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public struct ClassBattleFlowFeature {
}

public var voteCategoryLabel: String? {
guard let category = room?.battle.categoryDisplayTitle, !category.isEmpty else { return nil }
// 클래스 배틀 상세의 카테고리 태그를 먼저 쓴다. 커스텀 배틀은 방 정보에 카테고리가 없다.
let category = session?.battle.categoryTags.first ?? room?.battle.categoryDisplayTitle
guard let category, !category.isEmpty else { return nil }
return "#\(category)"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private extension ClassDetailView {
Button { send(.membersTapped) } label: {
informationRow(
"클래스 멤버",
detail: "총 \(store.room.memberCount)명이 참여하고 있어요",
detail: "총 \(store.room.activeMemberCount)명이 참여하고 있어요",
actionTitle: "보기"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public struct ClassMemberFeature {

public var memberCountTitle: String {
guard let capacity = room.memberCapacity, capacity > 0 else {
return "멤버 \(room.memberCount)"
return "멤버 \(room.activeMemberCount)"
}
return "멤버 \(room.memberCount) / \(capacity)"
return "멤버 \(room.activeMemberCount) / \(capacity)"
}

public var visibleMembers: [ClassMember] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum ClassTicketRegisterNotice: Equatable, Sendable {
case registrationExpired
case alreadyActive
case registerFailed
case locked

/// Android `toRegisterDialog`와 같은 매핑. 사용 중 이용권(`TICKET_409_ACTIVE`)만 iOS에서 따로 안내한다.
public init(error: ClassTicketError) {
Expand All @@ -24,6 +25,7 @@ public enum ClassTicketRegisterNotice: Equatable, Sendable {
case .invalidCode, .revoked: self = .invalidCode
case .registrationExpired: self = .registrationExpired
case .activeTicket: self = .alreadyActive
case .locked: self = .locked
case .notFound, .invalidResponse, .network: self = .registerFailed
}
}
Expand All @@ -35,6 +37,7 @@ public enum ClassTicketRegisterNotice: Equatable, Sendable {
case .registrationExpired: return .ticketRegistrationExpired()
case .alreadyActive: return .ticketAlreadyActive()
case .registerFailed: return .ticketRegisterFailed()
case .locked: return .ticketLocked()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public struct ClassTicketFeature {
return String(scalars)
}

/// 이용권 코드 길이. 예: `PKE05D2E1`
public static let codeLength = 9

public var canCheckCode: Bool {
!normalizedCode.isEmpty && !isChecking && !isLoadingExistingTicket
}
Expand Down Expand Up @@ -141,6 +144,11 @@ public struct ClassTicketFeature {
Reduce { state, action in
switch action {
case .binding(\.code):
// 코드는 `PKE` + 16진수 6자리(9자)다. 영문·숫자가 9자를 넘으면 잘라낸다.
let codeCharacters = state.normalizedCode.filter { $0 != "-" }
if codeCharacters.count > State.codeLength {
state.code = String(codeCharacters.prefix(State.codeLength))
}
let wasLookingUpRegisteredTicket = state.preview != nil && state.isLoadingExistingTicket
state.preview = nil
if wasLookingUpRegisteredTicket {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private extension ClassTicketView {
}
.pretendardFont(.labelSmall)

TextField("", text: $store.code, prompt: Text("전달 받은 코드를 입력해주세요").foregroundStyle(.gray300))
TextField("", text: $store.code, prompt: Text("예: PKE05D2E1").foregroundStyle(.gray300))
.textInputAutocapitalization(.characters)
.autocorrectionDisabled()
.keyboardType(.asciiCapable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private extension MyClassRoomCard {
HStack(spacing: 6) {
metaItem(
systemName: "person",
text: "멤버 \(room.memberCount)명"
text: "멤버 \(room.activeMemberCount)명"
)

if let deadlineText {
Expand Down
Loading
Loading