Skip to content

Commit

Permalink
Merge pull request #124 from depromeet/feat/#113-Home-API
Browse files Browse the repository at this point in the history
�[Feat/#113] CrewJoin API 개발 완료
  • Loading branch information
mooyoung2309 authored Jul 7, 2023
2 parents 50bc0e8 + 8cc4787 commit 31884f7
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 27 deletions.
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)"])
}
}
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

0 comments on commit 31884f7

Please sign in to comment.