-
Notifications
You must be signed in to change notification settings - Fork 0
[Feature] 링크, 폴더 삭제 로직 구현 #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
| /// 5. Firestore에 추가 | ||
| try await linkDocRef.setData([ | ||
| "id": linkDocRef.documentID, | ||
| "url": link.url, | ||
| "title": title ?? NSNull(), | ||
| "thumbnailUrl": imageUrls.thumbnail ?? NSNull(), | ||
| "faviconUrl": imageUrls.favicon ?? NSNull(), | ||
| "isPinned": false, | ||
| "createdBy": createdBy, | ||
| "lastAccessedAt": NSNull(), | ||
| "folderID": link.folderID ?? NSNull() | ||
| ]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존 DTO 객체로 매핑 후 데이터를 저장하는 방식은 특정 필드의 값이 nil인 프로퍼티는 firebase에 저장되지 않았습니다.
따라서, nil값의 상관없이 모든 필드를 저장하기 위해 딕셔너리를 활용하여 필드 키에 대한 값을 각각 지정해주는 방식으로 변경했습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct XXDTO {
let id: String
var parameters: [String: Any] {
[
"id": id,
]
}
}
|
|
||
| func moveLinkInFolder( | ||
| userID: String, | ||
| target linkID: String, | ||
| to folderID: String? | ||
| ) async throws |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
특정 Link를 특정 Folder로 포함시키는 메서드입니다.
|
|
||
| func moveLinksInFolder( | ||
| userID: String, | ||
| fromFolderID: String?, | ||
| toFolderID: String? | ||
| ) async throws | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
특정 Folder에 포함된 모든 Link들을 다른 Folder로 변경하는 메서드입니다.
이는 폴더 삭제 과정에서 폴더 하위 데이터를 삭제하지 않는 경우에 다른 폴더로 이동시키기 위함입니다.
| case .deleteLinkButtonTapped(let link): | ||
| state.isLoading = true | ||
| return .run { | ||
| do { | ||
| try await self.deleteLinkUseCase.execute(linkID: link.id) | ||
| return .onAppear | ||
| } catch { | ||
| return .occuredError | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재는 링크나 폴더를 삭제한 후, 해당 변경 사항을 반영하기 위해 전체 데이터를 Firebase로부터 다시 가져와서 UI를 갱신하고 있습니다.
그러나, 이 구조는 불러오는 데이터가 많아질수록 성능 저하 문제가 발생할 수 있기 때문에 후에 아래 구조로 변경할 예정입니다.
- 각 폴더(사이드 바 탭) 클릭 시 Firebase로부터 데이터 불러오기
- 단, 페이징을 활용해서 데이터를 일부만 가져오기 (Ex. 20개씩)
- 탭을 클릭할 때마다 데이터를 불러오지 않도록 하기 위해 캐싱 활용하기
| enum FirestoreFieldKey { | ||
| enum Link { | ||
| static let id = "id" | ||
| static let url = "url" | ||
| static let title = "title" | ||
| static let thumbnailUrl = "thumbnailUrl" | ||
| static let faviconUrl = "faviconUrl" | ||
| static let isPinned = "isPinned" | ||
| static let createdAt = "createdAt" | ||
| static let lastAccessedAt = "lastAccessedAt" | ||
| static let folderID = "folderID" | ||
| } | ||
|
|
||
| enum Folder { | ||
| static let id = "id" | ||
| static let name = "name" | ||
| static let createdAt = "createdAt" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firestore 문서에 저장되는 Field를 관리하기 위함입니다.
| enum CodingKeys: String, CodingKey { | ||
| case id = "id" | ||
| case url = "url" | ||
| case title = "title" | ||
| case thumbnailUrl = "thumbnailUrl" | ||
| case faviconUrl = "faviconUrl" | ||
| case isPinned = "isPinned" | ||
| case createdAt = "createdAt" | ||
| case lastAccessedAt = "lastAccessedAt" | ||
| case folderID = "folderID" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firestore 문서에 저장되는 Field를 관리하기 위해 FirestoreFieldKey를 구현했습니다.
(현재 커밋에 구현됨)
Firestore 데이터를 DTO로 매핑하기 위해서는 Firestore의 Field와 DTO의 프로퍼티가 매핑이 되어야하고, 이를 위해 CodingKey를 사용했습니다.
그런데, case id = FirestoreFieldKey.Link.id 처럼 CodingKey 열겨형 케이스에 값을 지정하고 싶었지만, CodingKey의 특성 상 리터럴 값을 직접 입력해야만 하고 있습니다.
현재 구조는 FirestoreFieldKey와 CodingKey의 열거형 값이 불일치할 경우 데이터 매핑 과정에서 문제가 발생할 수 있다고 느껴졌습니다.
이러한 실수를 예방하기 위해 다음 작업에서 FieldKey와 CodingKey의 열거형 값이 일치하는지 확인하는 테스트 코드를 작성할 예정입니다.
| ) | ||
| /// 2. 문서 업데이트 | ||
| try await linkDocRef.updateData([ | ||
| "folderID": folderID ?? NSNull() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSNull이 모든 경우에 필요한건지 확인해보면 좋을 것 같아요
| var lastAccessedAt: Date? | ||
| var folderID: String? | ||
|
|
||
| enum CodingKeys: String, CodingKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
불필요한 코드면 제거되는게 좋아보여요
|
|
||
| import Foundation | ||
|
|
||
| enum FirestoreFieldKey { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
공통화하기에 애매한 부분 같아요!



#️⃣ 연관된 이슈
📝 작업 내용
링크, 폴더 삭제 로직을 구현했습니다.
🎨 스크린샷
💬 추가 설명