-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
task #273 채널 생성 및 삭제 시점 변경 #275
Changes from all commits
11b5f1b
e827796
3edd74d
3787384
50d354b
7fb24ae
7b18c15
f0beffa
b42c404
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Combine | ||
|
||
import LiveStationDomainInterface | ||
|
||
final class MockCreateChannelUsecaseImpl: CreateChannelUsecase { | ||
func execute(name: String) -> AnyPublisher<ChannelEntity, any Error> { | ||
Future { promise in | ||
promise(.success(ChannelEntity(id: "", name: name))) | ||
}.eraseToAnyPublisher() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ import Combine | |||||
import Foundation | ||||||
|
||||||
import BaseFeatureInterface | ||||||
import LiveStationDomainInterface | ||||||
|
||||||
public class SignUpViewModel: ViewModel { | ||||||
public struct Input { | ||||||
|
@@ -16,6 +17,8 @@ public class SignUpViewModel: ViewModel { | |||||
private let output = Output() | ||||||
private var cancellables = Set<AnyCancellable>() | ||||||
|
||||||
private let createChannelUsecase: any CreateChannelUsecase | ||||||
|
||||||
public func transform(input: Input) -> Output { | ||||||
input.didWriteUserName | ||||||
.sink { [weak self] name in | ||||||
|
@@ -35,7 +38,9 @@ public class SignUpViewModel: ViewModel { | |||||
return output | ||||||
} | ||||||
|
||||||
public init() { } | ||||||
public init(createChannelUsecase: CreateChannelUsecase) { | ||||||
self.createChannelUsecase = createChannelUsecase | ||||||
} | ||||||
|
||||||
private func validate(with name: String?) -> Bool { | ||||||
guard let name else { return false } | ||||||
|
@@ -47,6 +52,15 @@ public class SignUpViewModel: ViewModel { | |||||
UserDefaults.standard.set(name, forKey: "USER_NAME") | ||||||
|
||||||
let savedName = UserDefaults.standard.string(forKey: "USER_NAME") | ||||||
output.isSaved.send(savedName == name) | ||||||
|
||||||
createChannelUsecase.execute(name: "Guest") | ||||||
.sink { _ in | ||||||
} receiveValue: { [weak self] channelEntity in | ||||||
UserDefaults.standard.set(channelEntity.id, forKey: "CHANNEL_ID") | ||||||
let savedID = UserDefaults.standard.string(forKey: "CHANNEL_ID") | ||||||
|
||||||
self?.output.isSaved.send(savedName == name && savedID != nil) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nil 값 확인이 아닌 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그방법도 좋은 것 같습니다! 다음에 수정해서 반영해두겠습니다! |
||||||
} | ||||||
.store(in: &cancellables) | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,8 +52,6 @@ public class BroadcastCollectionViewModel: ViewModel { | |
private let output = Output() | ||
|
||
private let fetchChannelListUsecase: any FetchChannelListUsecase | ||
private let createChannelUsecase: any CreateChannelUsecase | ||
private let deleteChannelUsecase: any DeleteChannelUsecase | ||
private let fetchChannelInfoUsecase: any FetchChannelInfoUsecase | ||
private let makeBroadcastUsecase: any MakeBroadcastUsecase | ||
private let fetchAllBroadcastUsecase: any FetchAllBroadcastUsecase | ||
|
@@ -68,22 +66,18 @@ public class BroadcastCollectionViewModel: ViewModel { | |
let extensionBundleID = "kr.codesquad.boostcamp9.Shook.BroadcastUploadExtension" | ||
|
||
private let userName = UserDefaults.standard.string(forKey: "USER_NAME") ?? "" | ||
private var channelName: String = "" | ||
private var broadcastName: String = "" | ||
private var channelDescription: String = "" | ||
private var channel: ChannelEntity? | ||
private var channelID = UserDefaults.standard.string(forKey: "CHANNEL_ID") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 하면 init 될때만 가져오기때문에 당장은 문제가 없지만 추후 채널 아이디가 변경될 경우 (새로운 채널을 생성했을때?) 고려해야할 부분 같습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오, 그 부분도 생각을 해야될 것 같습니다! 지금 유저입장에서는 닉네임이 자기 채널처럼 보이기 때문에 아마 닉네임쪽이랑 같이 변경되어야할 것 같긴합니다! |
||
|
||
public init( | ||
fetchChannelListUsecase: FetchChannelListUsecase, | ||
createChannelUsecase: CreateChannelUsecase, | ||
deleteChannelUsecase: DeleteChannelUsecase, | ||
fetchChannelInfoUsecase: FetchChannelInfoUsecase, | ||
makeBroadcastUsecase: MakeBroadcastUsecase, | ||
fetchAllBroadcastUsecase: FetchAllBroadcastUsecase, | ||
deleteBroadCastUsecase: DeleteBroadcastUsecase | ||
) { | ||
self.fetchChannelListUsecase = fetchChannelListUsecase | ||
self.createChannelUsecase = createChannelUsecase | ||
self.deleteChannelUsecase = deleteChannelUsecase | ||
self.fetchChannelInfoUsecase = fetchChannelInfoUsecase | ||
self.makeBroadcastUsecase = makeBroadcastUsecase | ||
self.fetchAllBroadcastUsecase = fetchAllBroadcastUsecase | ||
|
@@ -104,7 +98,7 @@ public class BroadcastCollectionViewModel: ViewModel { | |
self.output.streamingStartButtonIsActive.send(validness.isValid) | ||
self.output.errorMessage.send(validness.errorMessage) | ||
if validness.isValid { | ||
channelName = name | ||
broadcastName = name | ||
} | ||
} | ||
.store(in: &cancellables) | ||
|
@@ -123,9 +117,9 @@ public class BroadcastCollectionViewModel: ViewModel { | |
|
||
input.didTapFinishStreamingButton | ||
.flatMap { [weak self] _ in | ||
guard let self, let channel else { return Empty<(Void, Void), Error>().eraseToAnyPublisher() } | ||
return deleteChannelUsecase.execute(channelID: channel.id) | ||
.zip(deleteBroadCastUsecase.execute(id: channel.id)) | ||
guard let self, | ||
let channelID else { return Empty<Void, Error>().eraseToAnyPublisher() } | ||
return deleteBroadCastUsecase.execute(id: channelID) | ||
.eraseToAnyPublisher() | ||
} | ||
.sink { _ in | ||
|
@@ -135,16 +129,12 @@ public class BroadcastCollectionViewModel: ViewModel { | |
.store(in: &cancellables) | ||
|
||
input.didTapStartBroadcastButton | ||
.flatMap { [weak self] _ in | ||
guard let self else { return Empty<ChannelEntity, Error>().eraseToAnyPublisher() } | ||
output.isReadyToStream.send(false) | ||
return createChannelUsecase.execute(name: channelName) | ||
} | ||
.flatMap { [weak self] in | ||
guard let self else { return Empty<ChannelInfoEntity, Error>().eraseToAnyPublisher() } | ||
channel = $0 | ||
return fetchChannelInfoUsecase.execute(channelID: $0.id) | ||
.zip(makeBroadcastUsecase.execute(id: $0.id, title: $0.name, owner: userName, description: channelDescription)) | ||
guard let self, | ||
let channelID else { return Empty<ChannelInfoEntity, Error>().eraseToAnyPublisher() } | ||
output.isReadyToStream.send(false) | ||
return fetchChannelInfoUsecase.execute(channelID: channelID) | ||
.zip(makeBroadcastUsecase.execute(id: channelID, title: broadcastName, owner: userName, description: channelDescription)) | ||
.map { channelInfo, _ in channelInfo } | ||
.eraseToAnyPublisher() | ||
} | ||
|
@@ -168,7 +158,7 @@ public class BroadcastCollectionViewModel: ViewModel { | |
let broadcast = broadcastInfoEntities.first { $0.id == channelEntity.id } | ||
return Channel( | ||
id: channelEntity.id, | ||
title: channelEntity.name, | ||
title: broadcast?.title ?? "Unknown", | ||
thumbnailImageURLString: channelEntity.imageURLString, | ||
owner: broadcast?.owner ?? "Unknown", | ||
description: broadcast?.description ?? "" | ||
|
@@ -210,15 +200,10 @@ public class BroadcastCollectionViewModel: ViewModel { | |
/// - Parameter _: 방송 이름 | ||
/// - Returns: (Bool, String?) - 유효 여부와 에러 메시지 | ||
private func valid(_ value: String) -> (isValid: Bool, errorMessage: String?) { | ||
let isLengthValid = 3...20 ~= value.count | ||
let isCharactersValid = value.allSatisfy { $0.isLetter || $0.isNumber || $0 == "_" } | ||
let trimmedValue = value.trimmingCharacters(in: .whitespaces) | ||
|
||
if !isLengthValid && !isCharactersValid { | ||
return (false, "3글자 이상,20글자 이하로 입력해 주세요. 특수문자는 언더바(_)만 가능합니다.") | ||
} else if !isLengthValid { | ||
return (false, "최소 3글자 이상, 최대 20글자 이하로 입력해 주세요.") | ||
} else if !isCharactersValid { | ||
return (false, "특수문자는 언더바(_)만 가능합니다.") | ||
if trimmedValue.isEmpty { | ||
return (false, "공백을 제외하고 최소 1글자 이상 입력해주세요.") | ||
} else { | ||
return (true, nil) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usecase 2개가 덜어졌네요!! 👀🥹👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻