Skip to content

Commit 8cd4755

Browse files
committed
[Network] #192 - 메모 API 연결
1 parent 1c0d8bb commit 8cd4755

11 files changed

Lines changed: 97 additions & 10 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum ArchiveEndpoint {
1919
case toggleFavorite(photoID: Int, request: ToggleFavoriteDTO)
2020
case excludePhotosInAlbum(albumID: Int, request: DeletePhotoRequestDTO)
2121
case editFolderName(albumID: Int, request: FolderDTO.Request)
22+
case updateMemo(photoID: Int, request: UpdateMemoRequestDTO)
2223
}
2324

2425
extension ArchiveEndpoint: Endpoint {
@@ -58,6 +59,8 @@ extension ArchiveEndpoint: Endpoint {
5859
return "folders/\(albumID)/photos"
5960
case .editFolderName(let albumID, _):
6061
return "folders/\(albumID)"
62+
case .updateMemo(let id, _):
63+
return "photos/\(id)"
6164
}
6265
}
6366

@@ -117,6 +120,8 @@ extension ArchiveEndpoint: Endpoint {
117120
return .delete
118121
case .editFolderName:
119122
return .patch
123+
case .updateMemo:
124+
return .put
120125
}
121126
}
122127

@@ -144,6 +149,8 @@ extension ArchiveEndpoint: Endpoint {
144149
return request
145150
case .editFolderName(_, let request):
146151
return request
152+
case .updateMemo(_, let request):
153+
return request
147154
}
148155
}
149156
}

Neki-iOS/Features/Archive/Sources/Data/Sources/DTO/PhotoListDTO.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public enum PhotoListDTO {
2929
folderID: $0.folderID,
3030
isfavorite: $0.favorite,
3131
contentType: $0.contentType,
32-
createdAt: $0.createdAt
32+
createdAt: $0.createdAt,
33+
memo: "" // TODO: 서버 반영되면 수정
3334
)
3435
}
3536
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// UpdateMemoRequestDTO.swift
3+
// Neki-iOS
4+
//
5+
// Created by OneTen on 3/28/26.
6+
//
7+
8+
import Foundation
9+
10+
public struct UpdateMemoRequestDTO: Encodable {
11+
let memo, capturedAt: String
12+
}

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ extension DefaultArchiveRepository {
222222
folderID: oldItem.folderID,
223223
isfavorite: request,
224224
contentType: oldItem.contentType,
225-
createdAt: oldItem.createdAt
225+
createdAt: oldItem.createdAt,
226+
memo: oldItem.memo
226227
)
227228
list[index] = newItem
228229
photoCache[key] = list
@@ -252,6 +253,53 @@ extension DefaultArchiveRepository {
252253

253254
self.isAlbumCacheDirty = true
254255
}
256+
257+
func updatePhotoMemo(photoID: Int, memo: String) async throws {
258+
var capturedAt = ""
259+
if let cachedItem = photoCache.values.flatMap({ $0 }).first(where: { $0.photoID == photoID }) {
260+
capturedAt = cachedItem.createdAt
261+
} else if let cachedItem = favoritePhotoCache.first(where: { $0.photoID == photoID }) {
262+
capturedAt = cachedItem.createdAt
263+
} else {
264+
capturedAt = Date().ISO8601Format()
265+
}
266+
267+
let requestDTO = UpdateMemoRequestDTO(memo: memo, capturedAt: capturedAt)
268+
let endpoint = ArchiveEndpoint.updateMemo(photoID: photoID, request: requestDTO)
269+
let _ = try await networkProvider.request(endpoint: endpoint)
270+
271+
for (key, var list) in photoCache {
272+
if let index = list.firstIndex(where: { $0.photoID == photoID }) {
273+
let oldItem = list[index]
274+
let newItem = PhotoEntity(
275+
photoID: oldItem.photoID,
276+
imageURL: oldItem.imageURL,
277+
folderID: oldItem.folderID,
278+
isfavorite: oldItem.isfavorite,
279+
contentType: oldItem.contentType,
280+
createdAt: oldItem.createdAt,
281+
memo: memo
282+
)
283+
list[index] = newItem
284+
photoCache[key] = list
285+
}
286+
}
287+
288+
if let index = favoritePhotoCache.firstIndex(where: { $0.photoID == photoID }) {
289+
let oldItem = favoritePhotoCache[index]
290+
let newItem = PhotoEntity(
291+
photoID: oldItem.photoID,
292+
imageURL: oldItem.imageURL,
293+
folderID: oldItem.folderID,
294+
isfavorite: oldItem.isfavorite,
295+
contentType: oldItem.contentType,
296+
createdAt: oldItem.createdAt,
297+
memo: memo
298+
)
299+
favoritePhotoCache[index] = newItem
300+
}
301+
302+
}
255303
}
256304

257305

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct ArchiveClient {
2222
public var toggleFavorite: (_ photoID: Int, _ request: Bool) async throws -> Void
2323
public var excludePhotosInAlbum: (_ albumID: Int, _ photoIDs: [Int]) async throws -> Void
2424
public var editAlbumName: (_ albumID: Int, _ name: String) async throws -> Void
25+
public var updatePhotoMemo: (_ photoID: Int, _ memo: String) async throws -> Void
2526
}
2627

2728
extension ArchiveClient: DependencyKey {
@@ -61,6 +62,9 @@ extension ArchiveClient: DependencyKey {
6162
},
6263
editAlbumName: { albumID, name in
6364
try await archiveRepository.editAlbumName(albumID: albumID, name: name)
65+
},
66+
updatePhotoMemo: { photoID, memo in
67+
try await archiveRepository.updatePhotoMemo(photoID: photoID, memo: memo)
6468
}
6569
)
6670
}

Neki-iOS/Features/Archive/Sources/Domain/Sources/Entities/PhotoEntity.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ struct PhotoEntity {
1414
let isfavorite: Bool
1515
let contentType: String
1616
let createdAt: String
17+
let memo: String?
1718
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protocol ArchiveRepository: Sendable {
2222
func toggleFavorite(photoID: Int, request: Bool) async throws
2323
func excludePhotosInAlbum(albumID: Int, photoIDs: [Int]) async throws
2424
func editAlbumName(albumID: Int, name: String) async throws
25+
func updatePhotoMemo(photoID: Int, memo: String) async throws
2526

2627
// Delete
2728
func deletePhotoList(photoIDs: [Int]) async throws

Neki-iOS/Features/Archive/Sources/Presentation/Sources/Feature/ArchiveAlbumDetailFeature.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ struct ArchiveAlbumDetailFeature {
221221
imageURLString: entity.imageURL,
222222
isFavorite: entity.isfavorite,
223223
date: entity.createdAt.toISO8601Date(),
224-
folderId: currentAlbumId
224+
folderId: currentAlbumId,
225+
memo: entity.memo ?? ""
225226
)
226227
}
227228

Neki-iOS/Features/Archive/Sources/Presentation/Sources/Feature/ArchiveAllPhotosFeature.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ struct ArchiveAllPhotosFeature {
205205
imageURLString: entity.imageURL,
206206
isFavorite: entity.isfavorite,
207207
date: entity.createdAt.toISO8601Date(),
208-
folderId: entity.folderID
208+
folderId: entity.folderID,
209+
memo: entity.memo ?? ""
209210
)
210211
}
211212

Neki-iOS/Features/Archive/Sources/Presentation/Sources/Feature/ArchiveFavoriteAlbumFeature.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ struct ArchiveFavoriteAlbumFeature {
174174
imageURLString: entity.imageURL,
175175
isFavorite: true,
176176
date: entity.createdAt.toISO8601Date(),
177-
folderId: currentAlbumId
177+
folderId: currentAlbumId,
178+
memo: entity.memo ?? ""
178179
)
179180
}
180181

0 commit comments

Comments
 (0)