Skip to content

Commit 7c8d9bd

Browse files
committed
[Feat] #206 - Data, Domain API 연결 세팅
1 parent 3f99739 commit 7c8d9bd

5 files changed

Lines changed: 94 additions & 0 deletions

File tree

Neki-iOS/Features/Archive/Sources/Data/Sources/ArchiveEndpoint.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public enum ArchiveEndpoint {
2020
case excludePhotosInAlbum(albumID: Int, request: DeletePhotoRequestDTO)
2121
case editFolderName(albumID: Int, request: FolderDTO.Request)
2222
case updateMemo(photoID: Int, request: UpdateMemoRequestDTO)
23+
case duplicatePhoto(request: UpdateMappingPhotoRequestDTO)
24+
case movePhoto(request: UpdateMappingPhotoRequestDTO)
2325
}
2426

2527
extension ArchiveEndpoint: Endpoint {
@@ -61,6 +63,10 @@ extension ArchiveEndpoint: Endpoint {
6163
return "folders/\(albumID)"
6264
case .updateMemo(let id, _):
6365
return "photos/\(id)"
66+
case .duplicatePhoto:
67+
return "folders/photos/copy"
68+
case .movePhoto:
69+
return "folders/photos/move"
6470
}
6571
}
6672

@@ -122,6 +128,10 @@ extension ArchiveEndpoint: Endpoint {
122128
return .patch
123129
case .updateMemo:
124130
return .put
131+
case .duplicatePhoto:
132+
return .post
133+
case .movePhoto:
134+
return .patch
125135
}
126136
}
127137

@@ -151,6 +161,10 @@ extension ArchiveEndpoint: Endpoint {
151161
return request
152162
case .updateMemo(_, let request):
153163
return request
164+
case .duplicatePhoto(let request):
165+
return request
166+
case .movePhoto(let request):
167+
return request
154168
}
155169
}
156170
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// UpdateMappingPhotoRequestDTO.swift
3+
// Neki-iOS
4+
//
5+
// Created by OneTen on 4/12/26.
6+
//
7+
8+
import Foundation
9+
10+
public struct UpdateMappingPhotoRequestDTO: Codable {
11+
let sourceFolderID: Int?
12+
let photoIDS, targetFolderIDS: [Int]
13+
14+
enum CodingKeys: String, CodingKey {
15+
case sourceFolderID = "sourceFolderId"
16+
case photoIDS = "photoIds"
17+
case targetFolderIDS = "targetFolderIds"
18+
}
19+
}

Neki-iOS/Features/Archive/Sources/Data/Sources/DefaultArchiveRepository.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,57 @@ extension DefaultArchiveRepository {
306306
}
307307

308308
}
309+
310+
func duplicatePhoto(sourceFolderId: Int?, photoIDs: [Int], targetFolderIDs: [Int]) async throws {
311+
let request = UpdateMappingPhotoRequestDTO(
312+
sourceFolderID: sourceFolderId,
313+
photoIDS: photoIDs,
314+
targetFolderIDS: targetFolderIDs
315+
)
316+
let endpoint = ArchiveEndpoint.duplicatePhoto(request: request)
317+
let _ = try await networkProvider.request(endpoint: endpoint)
318+
319+
// 앨범 정보 캐시 갱신
320+
self.isAlbumCacheDirty = true
321+
322+
// Target 폴더들의 캐시를 다음 진입 시 새로 받아오도록 유도
323+
for targetID in targetFolderIDs {
324+
self.isPhotoCacheDirty[targetID] = true
325+
}
326+
}
327+
328+
func movePhoto(sourceFolderId: Int?, photoIDs: [Int], targetFolderIDs: [Int]) async throws {
329+
let request = UpdateMappingPhotoRequestDTO(
330+
sourceFolderID: sourceFolderId,
331+
photoIDS: photoIDs,
332+
targetFolderIDS: targetFolderIDs
333+
)
334+
let endpoint = ArchiveEndpoint.movePhoto(request: request)
335+
let _ = try await networkProvider.request(endpoint: endpoint)
336+
337+
// 앨범 정보 캐시 갱신
338+
self.isAlbumCacheDirty = true
339+
340+
// Source 폴더(혹은 전체 사진) 캐시 갱신
341+
if let sourceID = sourceFolderId {
342+
if var list = photoCache[sourceID] {
343+
list.removeAll { photoIDs.contains($0.photoID) }
344+
photoCache[sourceID] = list
345+
}
346+
} else {
347+
self.isPhotoCacheDirty[nil] = true
348+
}
349+
350+
// Target 폴더(혹은 전체 사진) 캐시 갱신
351+
if targetFolderIDs.isEmpty {
352+
self.isPhotoCacheDirty[nil] = true
353+
} else {
354+
for targetID in targetFolderIDs {
355+
self.isPhotoCacheDirty[targetID] = true
356+
}
357+
}
358+
}
359+
309360
}
310361

311362

Neki-iOS/Features/Archive/Sources/Domain/Sources/Client/ArchiveClient.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct ArchiveClient {
2424
public var editAlbumName: (_ albumID: Int, _ name: String) async throws -> Void
2525
public var updatePhotoMemo: (_ photoID: Int, _ memo: String) async throws -> Void
2626
public var clearCache: () async -> Void
27+
public var duplicatePhoto: (_ sourceFolderId: Int?, _ photoIDs: [Int], _ targetFolderIDs: [Int]) async throws -> Void
28+
public var movePhoto: (_ sourceFolderId: Int?, _ photoIDs: [Int], _ targetFolderIDs: [Int]) async throws -> Void
2729
}
2830

2931
extension ArchiveClient: DependencyKey {
@@ -69,6 +71,12 @@ extension ArchiveClient: DependencyKey {
6971
},
7072
clearCache: {
7173
await archiveRepository.clearCache()
74+
},
75+
duplicatePhoto: { sourceFolderId, photoIDs, targetFolderIDs in
76+
try await archiveRepository.duplicatePhoto(sourceFolderId: sourceFolderId, photoIDs: photoIDs, targetFolderIDs: targetFolderIDs)
77+
},
78+
movePhoto: { sourceFolderId, photoIDs, targetFolderIDs in
79+
try await archiveRepository.movePhoto(sourceFolderId: sourceFolderId, photoIDs: photoIDs, targetFolderIDs: targetFolderIDs)
7280
}
7381
)
7482
}

Neki-iOS/Features/Archive/Sources/Domain/Sources/Interfaces/Repositories/ArchiveRepository.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ protocol ArchiveRepository: Sendable {
2323
func excludePhotosInAlbum(albumID: Int, photoIDs: [Int]) async throws
2424
func editAlbumName(albumID: Int, name: String) async throws
2525
func updatePhotoMemo(photoID: Int, memo: String) async throws
26+
func duplicatePhoto(sourceFolderId: Int?, photoIDs: [Int], targetFolderIDs: [Int]) async throws
27+
func movePhoto(sourceFolderId: Int?, photoIDs: [Int], targetFolderIDs: [Int]) async throws
2628

2729
// Delete
2830
func deletePhotoList(photoIDs: [Int]) async throws

0 commit comments

Comments
 (0)