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 @@ -13,7 +13,7 @@ import CoreNetworkInterface
public enum GoalEndpoint: Endpoint {
case fetchGoalList(date: String)
case createGoal(GoalCreateRequestDTO)
case fetchGoalDetailList(date: String)
case fetchGoalDetail(date: String, goalId: Int64)
case fetchGoalById(goalId: Int64)
case fetchGoalEditList(date: String)
case updateGoal(goalId: Int64, GoalUpdateRequestDTO)
Expand All @@ -28,7 +28,7 @@ extension GoalEndpoint {

case .createGoal: return "/api/v1/goals"

case .fetchGoalDetailList:
case .fetchGoalDetail:
return "/api/v1/photologs"

case let .fetchGoalById(goalId):
Expand Down Expand Up @@ -56,7 +56,7 @@ extension GoalEndpoint {
case .createGoal:
return .post

case .fetchGoalDetailList:
case .fetchGoalDetail:
return .get

case .fetchGoalById:
Expand Down Expand Up @@ -88,8 +88,11 @@ extension GoalEndpoint {
case let .fetchGoalEditList(date):
return [URLQueryItem(name: "date", value: date)]

case let .fetchGoalDetailList(date):
return [URLQueryItem(name: "targetDate", value: date)]
case let .fetchGoalDetail(date, goalId):
return [
URLQueryItem(name: "targetDate", value: date),
URLQueryItem(name: "goalId", value: String(goalId))
]

case .createGoal,
.fetchGoalById,
Expand All @@ -108,7 +111,7 @@ extension GoalEndpoint {
case let .createGoal(request):
return request

case .fetchGoalDetailList,
case .fetchGoalDetail,
.fetchGoalById,
.fetchGoalEditList,
.deleteGoal,
Expand Down
12 changes: 6 additions & 6 deletions Projects/Domain/Goal/Interface/Sources/GoalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import CoreNetworkInterface
public struct GoalClient {
public var fetchGoals: (String) async throws -> [Goal]
public var createGoal: (GoalCreateRequestDTO) async throws -> Goal
public var fetchGoalDetailList: (String) async throws -> GoalDetail
public var fetchGoalDetail: (String, Int64) async throws -> GoalDetail
public var fetchGoalById: (Int64) async throws -> Goal
public var fetchGoalEditList: (String) async throws -> [Goal]
public var updateGoal: (Int64, GoalUpdateRequestDTO) async throws -> Goal
Expand All @@ -41,7 +41,7 @@ public struct GoalClient {
public init(
fetchGoals: @escaping (String) async throws -> [Goal],
createGoal: @escaping (GoalCreateRequestDTO) async throws -> Goal,
fetchGoalDetailList: @escaping (String) async throws -> GoalDetail,
fetchGoalDetail: @escaping (String, Int64) async throws -> GoalDetail,
fetchGoalById: @escaping (Int64) async throws -> Goal,
fetchGoalEditList: @escaping (String) async throws -> [Goal],
updateGoal: @escaping (Int64, GoalUpdateRequestDTO) async throws -> Goal,
Expand All @@ -51,7 +51,7 @@ public struct GoalClient {
) {
self.fetchGoals = fetchGoals
self.createGoal = createGoal
self.fetchGoalDetailList = fetchGoalDetailList
self.fetchGoalDetail = fetchGoalDetail
self.fetchGoalById = fetchGoalById
self.fetchGoalEditList = fetchGoalEditList
self.updateGoal = updateGoal
Expand Down Expand Up @@ -83,8 +83,8 @@ extension GoalClient: TestDependencyKey {
yourVerification: trashVerification
)
},
fetchGoalDetailList: { _ in
assertionFailure("GoalClient.fetchGoalDetailList이 구현되지 않았습니다. withDependencies로 mock을 주입하세요.")
fetchGoalDetail: { _, _ in
assertionFailure("GoalClient.fetchGoalDetail이 구현되지 않았습니다. withDependencies로 mock을 주입하세요.")
return .init(partnerNickname: "", completedGoals: [])
},
fetchGoalById: { _ in
Expand Down Expand Up @@ -196,7 +196,7 @@ extension GoalClient: TestDependencyKey {
yourVerification: .init(isCompleted: false, imageURL: nil, emoji: nil)
)
},
fetchGoalDetailList: { _ in
fetchGoalDetail: { _, _ in
.init(
partnerNickname: "민정",
completedGoals: [
Expand Down
4 changes: 2 additions & 2 deletions Projects/Domain/Goal/Sources/GoalClient+Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ extension GoalClient: @retroactive DependencyKey {
throw error
}
},
fetchGoalDetailList: { date in
fetchGoalDetail: { date, goalId in
do {
let response: DetailGoalListResponseDTO = try await networkClient.request(
endpoint: GoalEndpoint.fetchGoalDetailList(date: date)
endpoint: GoalEndpoint.fetchGoalDetail(date: date, goalId: goalId)
)
return response.toEntity(response)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Projects/Domain/PhotoLog/Sources/PhotoLogClient+Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension PhotoLogClient: @retroactive DependencyKey {

var request = URLRequest(url: url)
request.httpMethod = "PUT"
request.setValue("image/png", forHTTPHeaderField: "Content-Type")
request.setValue("image/jpeg", forHTTPHeaderField: "Content-Type")

_ = try await URLSession.shared.upload(for: request, from: data)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ public struct GoalDetailReducer {
/// GoalDetail 화면 렌더링에 필요한 상태입니다.
@ObservableState
public struct State: Equatable {
public enum EntryPoint: Equatable {
case home
case stats
}

public let goalId: Int64
public let entryPoint: EntryPoint
public var item: GoalDetail?
public var currentGoalIndex: Int = 0
public var currentUser: GoalDetail.Owner
Expand All @@ -46,6 +52,26 @@ public struct GoalDetailReducer {
}
}

public var canSwipeLeft: Bool {
switch entryPoint {
case .home:
return !isEditing && currentUser == .you

case .stats:
return !isEditing && currentUser == .mySelf
}
}

public var canSwipeRight: Bool {
switch entryPoint {
case .home:
return !isEditing && currentUser == .mySelf

case .stats:
return !isEditing && currentUser == .you
}
}

public var goalName: String {
if let goalName = currentCompletedGoal?.goalName, !goalName.isEmpty {
return goalName
Expand All @@ -62,9 +88,6 @@ public struct GoalDetailReducer {
?? goalId
}

public var canSwipeUp: Bool { currentGoalIndex + 1 < completedGoalItems.count }
public var canSwipeDown: Bool { currentGoalIndex > 0 }

public var isCompleted: Bool {
pendingEditedImageData != nil || currentCard?.imageUrl != nil
}
Expand Down Expand Up @@ -104,10 +127,12 @@ public struct GoalDetailReducer {
/// ```
public init(
currentUser: GoalDetail.Owner,
entryPoint: EntryPoint,
id: Int64,
verificationDate: String
) {
self.currentUser = currentUser
self.entryPoint = entryPoint
self.goalId = id
self.verificationDate = verificationDate
}
Expand All @@ -125,9 +150,8 @@ public struct GoalDetailReducer {
case bottomButtonTapped
case navigationBarTapped(TXNavigationBar.Action)
case reactionEmojiTapped(ReactionEmoji)
case cardTapped
case cardSwipedUp
case cardSwipedDown
case cardSwipeLeft
case cardSwipeRight
case focusChanged(Bool)
case dimmedBackgroundTapped
case updateMyPhotoLog(GoalDetail.CompletedGoal.PhotoLog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import FeatureGoalDetailInterface
import FeatureProofPhotoInterface
import SharedDesignSystem
import SharedUtil
import SharedUtil

extension GoalDetailReducer {
// swiftlint: disable function_body_length
Expand All @@ -40,10 +41,11 @@ extension GoalDetailReducer {
// MARK: - LifeCycle
case .onAppear:
let date = state.verificationDate
let goalId = state.goalId

return .run { send in
do {
let item = try await goalClient.fetchGoalDetailList(date)
let item = try await goalClient.fetchGoalDetail(date, goalId)
await send(.fethedGoalDetailItem(item))
} catch {
await send(.fetchGoalDetailFailed)
Expand Down Expand Up @@ -95,27 +97,15 @@ extension GoalDetailReducer {
}
)

case .cardTapped:
state.currentUser = state.currentUser == .mySelf ? .you : .mySelf
state.commentText = state.comment
state.isCommentFocused = false
state.selectedReactionEmoji = state.currentCard?.reaction.flatMap(ReactionEmoji.init(from:))
return .send(.setCreatedAt(timeFormatter.displayText(from: state.currentCard?.createdAt)))

case .cardSwipedUp:
let nextIndex = state.currentGoalIndex + 1
guard nextIndex < state.completedGoalItems.count else { return .none }
state.currentGoalIndex = nextIndex
case .cardSwipeLeft:
state.currentUser = .mySelf
state.commentText = state.comment
state.isCommentFocused = false
state.selectedReactionEmoji = state.currentCard?.reaction.flatMap(ReactionEmoji.init(from:))
return .send(.setCreatedAt(timeFormatter.displayText(from: state.currentCard?.createdAt)))

case .cardSwipedDown:
guard state.currentGoalIndex > 0 else { return .none }
state.currentGoalIndex -= 1
case .cardSwipeRight:
state.currentUser = .you
state.commentText = state.comment
state.isCommentFocused = false
state.selectedReactionEmoji = state.currentCard?.reaction.flatMap(ReactionEmoji.init(from:))
return .send(.setCreatedAt(timeFormatter.displayText(from: state.currentCard?.createdAt)))

Expand Down Expand Up @@ -219,8 +209,14 @@ extension GoalDetailReducer {
do {
var fileName: String
if let pendingEditedImageData {
let optimizedImageData = ImageUploadOptimizer.optimizedJPEGData(
from: pendingEditedImageData
)
let uploadResponse = try await photoLogClient.fetchUploadURL(goalId)
try await photoLogClient.uploadImageData(pendingEditedImageData, uploadResponse.uploadUrl)
try await photoLogClient.uploadImageData(
optimizedImageData,
uploadResponse.uploadUrl
)
fileName = uploadResponse.fileName
} else {
let imageURLString = current.imageUrl ?? ""
Expand Down
Loading