Skip to content
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

[Feat/#113] CrewJoin API 개발 완료 #124

Merged
merged 2 commits into from
Jul 7, 2023
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
4 changes: 2 additions & 2 deletions Projects/App/Sources/RootStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public struct RootStore: ReducerProtocol {
case mainTab(MainTabViewStore.State)

public init() {
// self = .onboarding(.init())
self = .mainTab(.init())
self = .onboarding(.init())
// self = .mainTab(.init())
}
}

Expand Down
11 changes: 8 additions & 3 deletions Projects/Domain/Crew/Interface/Sources/CrewClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ import ComposableArchitecture

public struct CrewClient {
public var makeCrew: @Sendable (String, Int) async throws -> CrewInfo
public var joinCrew: @Sendable (String) async throws -> CrewInfo

public init(makeCrew: @escaping @Sendable (String, Int) async throws -> CrewInfo) {
public init(makeCrew: @escaping @Sendable (String, Int) async throws -> CrewInfo,
joinCrew: @escaping @Sendable (String) async throws -> CrewInfo) {
self.makeCrew = makeCrew
self.joinCrew = joinCrew
}
}

extension CrewClient: TestDependencyKey {
public static var previewValue = Self(
makeCrew: unimplemented("\(Self.self).makeCrew")
makeCrew: unimplemented("\(Self.self).makeCrew"),
joinCrew: unimplemented("\(Self.self).joinCrew")
)

public static let testValue = Self(
makeCrew: unimplemented("\(Self.self).makeCrew")
makeCrew: unimplemented("\(Self.self).makeCrew"),
joinCrew: unimplemented("\(Self.self).joinCrew")
)
}
10 changes: 9 additions & 1 deletion Projects/Domain/Crew/Interface/Sources/CrewEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ import CoreNetworkInterface
import CoreKeyChainStore

public struct CrewEndpoint {
public static func makeCrew(_ requestDTO: MakeCrewRequestDTO) -> Endpoint<MakeCrewResponseDTO> {
public static func makeCrew(_ requestDTO: MakeCrewRequestDTO) -> Endpoint<CrewResponseDTO> {
let accessToken = KeyChainStore.shared.load(property: .accessToken)

return Endpoint(path: "crews",
httpMethod: .post,
bodyParameters: requestDTO,
headers: ["Authorization" : "Bearer \(accessToken)"])
}

public static func joinCrew(_ code: String) -> Endpoint<CrewResponseDTO> {
let accessToken = KeyChainStore.shared.load(property: .accessToken)

return Endpoint(path: "crews/join/\(code)",
httpMethod: .post,
headers: ["Authorization" : "Bearer \(accessToken)"])
}
Comment on lines +22 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p5;

매 요청마다 auth가 필요하다면, accessToken을 Endpoint 내부에서 처리하는 방식은 어떤가요 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NetworkProvider 쪽에 아예 박아버리려다가 accessToken 없이 헤더를 넣어야하는 케이스도 혹시 생길까봐 유동적으로 넣을 수 있도록 넣어놨어

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// MakeCrewResponseDTO.swift
// CrewResponseDTO.swift
// DomainCrewInterface
//
// Created by 박현우 on 2023/07/01.
//

import Foundation

public struct MakeCrewResponseDTO: Codable {
public struct CrewResponseDTO: Codable {

let crewId: String
let crewName: String
Expand All @@ -33,6 +33,6 @@ public struct MakeCrewResponseDTO: Codable {
}
}

public extension MakeCrewResponseDTO {
static let mock = MakeCrewResponseDTO(crewId: "1", crewName: "8이팅", goalCount: 3, code: "XCKDd2ew", participants: ["현우", "영모", "태현"])
public extension CrewResponseDTO {
static let mock = CrewResponseDTO(crewId: "1", crewName: "8이팅", goalCount: 3, code: "XCKDd2ew", participants: ["현우", "영모", "태현"])
}
10 changes: 5 additions & 5 deletions Projects/Domain/Crew/Interface/Sources/Models/CrewInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import Foundation

public struct CrewInfo: Equatable {
let crewId: String
let crewName: String
let goalCount: Int
let code: String
let participants: [String]
public let crewId: String
public let crewName: String
public let goalCount: Int
public let code: String
public let participants: [String]

public init(crewId: String,
crewName: String,
Expand Down
23 changes: 16 additions & 7 deletions Projects/Domain/Crew/Sources/CrewClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ import DomainCrewInterface
import CoreNetwork

extension CrewClient: DependencyKey {
public static let liveValue = CrewClient { crewName, goalCount in
let makeCrewRequestDTO = MakeCrewRequestDTO(crewName: crewName, goalCount: goalCount)
let apiEndpoint = CrewEndpoint.makeCrew(makeCrewRequestDTO)
let response = try await NetworkProvider.shared.sendRequest(apiEndpoint).toDomain()

return response
}
public static let liveValue = CrewClient(
makeCrew: { crewName, goalCount in
let makeCrewRequestDTO = MakeCrewRequestDTO(crewName: crewName, goalCount: goalCount)
let apiEndpoint = CrewEndpoint.makeCrew(makeCrewRequestDTO)
let response = try await NetworkProvider.shared.sendRequest(apiEndpoint).toDomain()

return response
},
joinCrew: { code in
let apiEndpoint = CrewEndpoint.joinCrew(code)
let response = try await NetworkProvider.shared.sendRequest(apiEndpoint).toDomain()

return response
}
)

}

extension DependencyValues {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import ComposableArchitecture
import Domain

public struct CrewJoinStore: ReducerProtocol {
private let reducer: Reduce<State, Action>
Expand All @@ -31,7 +32,8 @@ public struct CrewJoinStore: ReducerProtocol {
case binding(BindingAction<State>)

case dismissCrewJoinView
case crewJoinButtonTapped
case joinCrew
case joinCrewResponse(TaskResult<CrewInfo>)
case isCrewJoinCompleted

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct CrewJoinView: View {
Spacer()

PumpingSubmitButton(title : "참여하기", isEnable: viewStore.isSatisfied) {
viewStore.send(.crewJoinButtonTapped)
viewStore.send(.joinCrew)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public struct CrewMakeStore: ReducerProtocol {
@BindingState public var crewName: String = ""
@BindingState public var goalCount: Int = 1
public var isSatisfied: Bool = false
public var receivedCrewInfo: CrewInfo?

public init() {

Expand Down
20 changes: 18 additions & 2 deletions Projects/Feature/Crew/Sources/Home/CrewJoin/CrewJoinStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import ComposableArchitecture
import FeatureCrewInterface
import Domain

extension CrewJoinStore {
public init() {
@Dependency(\.crewClient) var crewClient

let reducer: Reduce<State, Action> = .init { state, action in
switch action {
case .binding:
Expand All @@ -25,10 +28,23 @@ extension CrewJoinStore {
state.code = ""
return .none

case .crewJoinButtonTapped:
// 크루 참여 API
case .joinCrew:
return .task { [code = state.code] in
await .joinCrewResponse(
TaskResult {
try await crewClient.joinCrew(code)
}
)
}

case let .joinCrewResponse(.success(crewInfo)):
print(crewInfo)
return .send(.dismissCrewJoinView)

case let .joinCrewResponse(.failure(error)):
print(error.localizedDescription)
return .none

default:
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension CrewMakeStore {
return .none

case .copyCode:
UIPasteboard.general.string = "복사한 값"
UIPasteboard.general.string = state.receivedCrewInfo?.code
return .none

case .makeCrew:
Expand All @@ -65,6 +65,7 @@ extension CrewMakeStore {

case let .makeCrewResponse(.success(crewInfo)):
print(crewInfo)
state.receivedCrewInfo = crewInfo
return .send(.goToCrewMakeCompleteView)

case let .makeCrewResponse(.failure(error)):
Expand Down