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 @@ -31,6 +31,9 @@ private extension AppGraph {
fetchGoalUseCase: developmentGraphSet
.developmentGoalUseCaseGraph
.fetchDevelopmentGoalUseCase,
updateGoalUseCase: developmentGraphSet
.developmentGoalUseCaseGraph
.updateDevelopmentGoalUseCase,
updateGoalStatusUseCase: developmentGraphSet
.developmentGoalUseCaseGraph
.updateDevelopmentGoalStatusUseCase
Expand Down
10 changes: 10 additions & 0 deletions Application/Data/Sources/DTO/DevelopmentGoalDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public struct DevelopmentGoalCreateRequest: Encodable {
}
}

public struct DevelopmentGoalUpdateRequest: Encodable {
public let title: String
public let markdownDescription: String

public init(title: String, markdownDescription: String) {
self.title = title
self.markdownDescription = markdownDescription
}
}

public struct DevelopmentGoalStatusRequest {
public let status: DevelopmentGoalStatus

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public protocol DevelopmentGoalService {
goalId: String,
request: DevelopmentGoalCreateRequest
) async throws -> DevelopmentGoalResponse
func updateGoal(
goalId: String,
request: DevelopmentGoalUpdateRequest
) async throws -> DevelopmentGoalResponse
func fetchGoal(goalId: String) async throws -> DevelopmentGoalResponse
func fetchGoals(_ query: DevelopmentGoalQuery) async throws -> [DevelopmentGoalResponse]
func fetchCompletionSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ final class DevelopmentGoalRepositoryImpl: DevelopmentGoalRepository {
}
}

func updateGoal(
_ goalId: String,
title: String,
description: String
) async throws -> DevelopmentGoal {
do {
let response = try await service.updateGoal(
goalId: goalId,
request: .init(title: title, markdownDescription: description)
)
return try response.toDomain()
} catch {
throw error.toDomain()
}
}

func fetchGoal(_ goalId: String) async throws -> DevelopmentGoal {
do {
return try await service.fetchGoal(goalId: goalId).toDomain()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ struct DevelopmentGoalRepositoryImplTests {
#expect(request.markdownDescription == "설명")
}

@Test("목표 수정은 제목과 markdownDescription 요청을 서비스에 전달한다")
func 목표_수정은_제목과_markdownDescription_요청을_서비스에_전달한다() async throws {
let service = DevelopmentGoalServiceSpy()
let repository = DevelopmentGoalRepositoryImpl(service: service)

let goal = try await repository.updateGoal(
"goal-1",
title: "바꾼 목표",
description: "바꾼 설명"
)

let request = try #require(await service.updateRequest())
#expect(goal.id == "goal-1")
#expect(request.goalId == "goal-1")
#expect(request.title == "바꾼 목표")
#expect(request.markdownDescription == "바꾼 설명")
}

@Test("완료 검증 문맥은 목표 서비스 응답만으로 복원한다")
func 완료_검증_문맥은_목표_서비스_응답만으로_복원한다() async throws {
let service = DevelopmentGoalServiceSpy()
Expand Down Expand Up @@ -79,6 +97,12 @@ private actor DevelopmentGoalServiceSpy: DevelopmentGoalService {
let markdownDescription: String
}

struct UpdateRequest {
let goalId: String
let title: String
let markdownDescription: String
}

struct TransitionRequest {
let goalId: String
let status: DevelopmentGoalStatus
Expand All @@ -101,6 +125,7 @@ private actor DevelopmentGoalServiceSpy: DevelopmentGoalService {
createdAt: .distantPast
)
private var recordedCreateRequest: CreateRequest?
private var recordedUpdateRequest: UpdateRequest?
private var recordedCompletionSnapshotGoalIds = [String]()
private var recordedTransitionRequest: TransitionRequest?

Expand All @@ -115,6 +140,18 @@ private actor DevelopmentGoalServiceSpy: DevelopmentGoalService {
return goal
}

func updateGoal(
goalId: String,
request: DevelopmentGoalUpdateRequest
) async throws -> DevelopmentGoalResponse {
recordedUpdateRequest = .init(
goalId: goalId,
title: request.title,
markdownDescription: request.markdownDescription
)
return goal
}

func fetchGoal(goalId: String) async throws -> DevelopmentGoalResponse {
goal
}
Expand All @@ -141,6 +178,10 @@ private actor DevelopmentGoalServiceSpy: DevelopmentGoalService {
recordedCreateRequest
}

func updateRequest() -> UpdateRequest? {
recordedUpdateRequest
}

func completionSnapshotGoalIds() -> [String] {
recordedCompletionSnapshotGoalIds
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public final class DevelopmentGoalUseCaseGraph {
FetchDevelopmentGoalsUseCaseImpl(input.repository)
}

@Provide
private func makeUpdateDevelopmentGoalUseCase() -> UpdateDevelopmentGoalUseCase {
UpdateDevelopmentGoalUseCaseImpl(input.repository)
}

@Provide
private func makeUpdateDevelopmentGoalStatusUseCase() -> UpdateDevelopmentGoalStatusUseCase {
UpdateDevelopmentGoalStatusUseCaseImpl(input.repository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public protocol DevelopmentGoalRepository {
title: String,
description: String
) async throws -> DevelopmentGoal
func updateGoal(
_ goalId: String,
title: String,
description: String
) async throws -> DevelopmentGoal
func fetchGoal(_ goalId: String) async throws -> DevelopmentGoal
func fetchGoals(_ query: DevelopmentGoal.Query) async throws -> [DevelopmentGoal]
func fetchCompletionSnapshot(for goalId: String) async throws -> DevelopmentGoal.CompletionSnapshot
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// UpdateDevelopmentGoalUseCase.swift
// Domain
//
// Created by opfic on 11/23/26.
//

public protocol UpdateDevelopmentGoalUseCase {
func execute(_ goalId: String, title: String, description: String) async throws -> DevelopmentGoal
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// UpdateDevelopmentGoalUseCaseImpl.swift
// Domain
//
// Created by opfic on 11/23/26.
//

public final class UpdateDevelopmentGoalUseCaseImpl: UpdateDevelopmentGoalUseCase {
private let repository: DevelopmentGoalRepository

init(_ repository: DevelopmentGoalRepository) {
self.repository = repository
}

public func execute(_ goalId: String, title: String, description: String) async throws -> DevelopmentGoal {
try await repository.updateGoal(goalId, title: title, description: description)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ private actor DevelopmentGoalRepositorySpy: DevelopmentGoalRepository {
return goal
}

func updateGoal(
_ goalId: String,
title: String,
description: String
) async throws -> DevelopmentGoal {
goal
}

func fetchGoal(_ goalId: String) async throws -> DevelopmentGoal {
recordedFetchedGoalIds.append(goalId)
return goal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ actor DevelopmentRecordGoalRepositorySpy: DevelopmentGoalRepository {
goal
}

func updateGoal(
_ goalId: String,
title: String,
description: String
) async throws -> DevelopmentGoal {
goal
}

func fetchGoal(_ goalId: String) async throws -> DevelopmentGoal {
goal
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ private actor DevelopmentGoalRepositorySpy: DevelopmentGoalRepository {
try result.get()
}

func updateGoal(
_ goalId: String,
title: String,
description: String
) async throws -> DevelopmentGoal {
try result.get()
}

func fetchGoal(_ goalId: String) async throws -> DevelopmentGoal {
recordedFetchedGoalIds.append(goalId)
return try result.get()
Expand Down
21 changes: 21 additions & 0 deletions Application/Infra/Sources/Service/DevelopmentGoalServiceImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class DevelopmentGoalServiceImpl: DevelopmentGoalService {
case fetchGoals
case fetchCompletionSnapshot
case transitionGoalStatus
case updateGoal
}
}

Expand Down Expand Up @@ -50,6 +51,26 @@ final class DevelopmentGoalServiceImpl: DevelopmentGoalService {
}
}

func updateGoal(
goalId: String,
request: DevelopmentGoalUpdateRequest
) async throws -> DevelopmentGoalResponse {
guard let uid = Auth.auth().currentUser?.uid else { throw DataLayerError.notAuthenticated }

do {
try Self.validateTitle(request.title)
let reference = store.document(FirestorePath.developmentGoal(uid, goalId: goalId))
var data = try encoder.encode(request)
data[DevelopmentGoalFieldKey.updatedAt.rawValue] = FieldValue.serverTimestamp()
try await reference.updateData(data)
return try await fetchGoal(uid: uid, goalId: goalId)
} catch {
logger.error("Failed to update development goal", error: error)
record(error, code: .updateGoal)
throw error
}
}

func fetchGoal(goalId: String) async throws -> DevelopmentGoalResponse {
guard let uid = Auth.auth().currentUser?.uid else { throw DataLayerError.notAuthenticated }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public enum DevelopmentDependencyPreparation {
_ dependencies: inout DependencyValues,
createGoalUseCase: CreateDevelopmentGoalUseCase,
fetchGoalUseCase: FetchDevelopmentGoalUseCase,
updateGoalUseCase: UpdateDevelopmentGoalUseCase,
updateGoalStatusUseCase: UpdateDevelopmentGoalStatusUseCase
) {
dependencies.developmentCreateGoalUseCase = createGoalUseCase
dependencies.developmentFetchGoalUseCase = fetchGoalUseCase
dependencies.developmentUpdateGoalUseCase = updateGoalUseCase
dependencies.developmentUpdateGoalStatusUseCase = updateGoalStatusUseCase
}

Expand Down Expand Up @@ -70,6 +72,11 @@ extension DependencyValues {
set { self[FetchRecordsUseCaseKey.self] = newValue }
}

var developmentUpdateGoalUseCase: UpdateDevelopmentGoalUseCase {
get { self[UpdateGoalUseCaseKey.self] }
set { self[UpdateGoalUseCaseKey.self] = newValue }
}

var developmentUpdateGoalStatusUseCase: UpdateDevelopmentGoalStatusUseCase {
get { self[UpdateGoalStatusUseCaseKey.self] }
set { self[UpdateGoalStatusUseCaseKey.self] = newValue }
Expand Down Expand Up @@ -134,6 +141,12 @@ private enum FetchRecordsUseCaseKey: DependencyKey {
}
}

private enum UpdateGoalUseCaseKey: DependencyKey {
static var liveValue: UpdateDevelopmentGoalUseCase {
preconditionFailure("UpdateDevelopmentGoalUseCase must be provided.")
}
}

private enum UpdateGoalStatusUseCaseKey: DependencyKey {
static var liveValue: UpdateDevelopmentGoalStatusUseCase {
preconditionFailure("UpdateDevelopmentGoalStatusUseCase must be provided.")
Expand Down
Loading