Skip to content

Commit

Permalink
[FEAT] #48 - Guide API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
Seokki-Kwon committed Mar 3, 2025
1 parent 99e8442 commit c438562
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 10 deletions.
15 changes: 12 additions & 3 deletions dnd-12th-2-iOS/dnd-12th-2-iOS/Client/GuideClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ import ComposableArchitecture
import Moya

struct GuideClient {
static let provider = MoyaProvider<GoalAPI>(session: Session(interceptor: AuthIntercepter.shared), plugins: [MoyaLoggingPlugin()])
var fetchTips: () async throws -> Guide
static let provider = MoyaProvider<GuideAPI>(session: Session(interceptor: AuthIntercepter.shared), plugins: [MoyaLoggingPlugin()])
}

extension GuideClient: DependencyKey {
static let liveValue = Self (

fetchTips: {
do {
let result: BaseResponse<GuideResponseDto> = try await provider.async.request(.fetchNewTip)
guard let result = result.data else {
throw APIError.parseError
}
return result.toDomain()
}
}
)
}

extension DependencyValues {
var guideClient: GoalClient {
var guideClient: GuideClient {
get { self[GuideClient.self] }
set { self[GuideClient.self] = newValue }
}
Expand Down
11 changes: 11 additions & 0 deletions dnd-12th-2-iOS/dnd-12th-2-iOS/Model/Guide.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Guide.swift
// dnd-12th-2-iOS
//
// Created by 권석기 on 3/3/25.
//

struct Guide {
let newGoalGuide: String
let newPlanGuide: String
}
5 changes: 3 additions & 2 deletions dnd-12th-2-iOS/dnd-12th-2-iOS/Network/API/GuideAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation
import Moya

enum GuideAPI {
case fetchNewTip
}

extension GuideAPI: TargetType {
Expand All @@ -18,8 +19,8 @@ extension GuideAPI: TargetType {

var path: String {
switch self {
default:
return ""
case .fetchNewTip:
return "/new"
}
}

Expand Down
17 changes: 17 additions & 0 deletions dnd-12th-2-iOS/dnd-12th-2-iOS/Network/DTO/GuideResponseDto.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// GuideResponseDto.swift
// dnd-12th-2-iOS
//
// Created by 권석기 on 3/3/25.
//

struct GuideResponseDto: Decodable {
let newGoalGuide: String
let newPlanGuide: String
}

extension GuideResponseDto {
func toDomain() -> Guide {
.init(newGoalGuide: newGoalGuide, newPlanGuide: newPlanGuide)
}
}
11 changes: 6 additions & 5 deletions dnd-12th-2-iOS/dnd-12th-2-iOS/Presentation/Goal/GoalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct GoalView: View {
var body: some View {
WithPerceptionTracking {
ZStack(alignment: .bottom) {

VStack( spacing: 0) {
Text("목표")
.bodyXLargeSemibold()
Expand All @@ -23,11 +22,11 @@ struct GoalView: View {
DDRoundTextFiled(text: $store.goalInfo.goalTitle)
.padding(.top, 8)

Text("진행 상황을 측정할 수 있도록 목표를 세워보세요. 
예: ‘한 달 동안 영어책 1권 완독’")
Text(store.newGoalGuide)
.bodyMediumMedium()
.alignmentLeading()
.foregroundStyle(Color.purple500)
.padding(.top, 4)
.padding(.top, 4)

Text("계획")
.bodyXLargeSemibold()
Expand All @@ -37,7 +36,7 @@ struct GoalView: View {
DDRoundTextFiled(text: $store.goalInfo.planTitle)
.padding(.top, 8)

Text("빠르게 끝낼 것과 중요한 것을 구분해볼까요?")
Text(store.newPlanGuide)
.bodyMediumMedium()
.alignmentLeading()
.foregroundStyle(Color.purple500)
Expand Down Expand Up @@ -102,11 +101,13 @@ struct GoalView: View {
store.send(.completeButtonTapped)
})
}

.navigationBar(left: {
DDBackButton(action: {})
.hidden(!store.isShowBackButton)
})
.onAppear {
store.send(.fetchTips)
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions dnd-12th-2-iOS/dnd-12th-2-iOS/Presentation/Goal/MakeGoal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ struct MakeGoal {
// 계획 설정
var goalInfo: Goal

// 목표 가이드
var newGoalGuide = ""

// 계획 가이드
var newPlanGuide = ""

// backButton 숨김여부
var isShowBackButton: Bool {
goalType != .firstGoal
Expand Down Expand Up @@ -126,12 +132,26 @@ struct MakeGoal {

// startPickerTapped
case endPickerTapped

case fetchTips
case fetchTipsResponse(Guide)
}

@Dependency(\.guideClient) var guideClient

var body: some Reducer<State, Action> {
BindingReducer()
Reduce { state, action in
switch action {
case .fetchTips:
return .run { send in
let response = try await guideClient.fetchTips()
await send(.fetchTipsResponse(response))
}
case let .fetchTipsResponse(response):
state.newGoalGuide = response.newGoalGuide
state.newPlanGuide = response.newPlanGuide
return .none
case .startPickerTapped:
state.isShowStartPicker = true
state.isShowEndPicker = false
Expand Down

0 comments on commit c438562

Please sign in to comment.