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
[Eddy] Firestore 관련 요청을 타입과 레퍼런스와 상관없이 Generic하게 수정 #54
Conversation
|
||
typealias FirestoreUID = String | ||
typealias FireabaseAuthUID = String | ||
|
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.
🙋FirestoreUID 랑 FireabaseAuthUID 를 따로 놓는이유가 있을까요? Auth 의 uid 랑 fireStore 의 uid 는 같지 않나요?
import FirebaseFirestoreSwift | ||
|
||
protocol FirestoreRequest { | ||
associatedtype Modeltype: Codable |
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.
associatedtype
은 아직 사용하지 않는거죵?
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.
아래 26번째 줄 UserRequest
에서 사용하고 있습니다!
|
||
var docReference: DocumentReference { | ||
db.collection("users").document(uid) | ||
} |
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.
🔵 사용되는 Collection 은 이미 정해져있는거니 Collection reference 를 enum 으로 따로 빼 놓고 사용하는건 어떨까요?
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.
enum 으로 정의하는 것도 좋은 방법이네유!
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.
이 부분도 뭔가 enum으로 구조화할 수 있을 거 같은데, Reference의 타입이 3가지(DocumentReference, CollectionReference, Query)나 되고, 거기에 따라서 실행해야하는 메서드 이름도 다 달라서 어떻게 해야할지 머리를 쥐어짜는 중...
개선해서 다시 push 해보겠습니다.
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.
깔끔하게 정리정돈된 코드를 보는 것 같아 속이 편안해 집니다~
request 에 필요한 데이터를 구조체로 묶는 것 만으로 역할이 분명해 졌다고 느꼈습니다.
protocol 을 사용하니 디코딩할때 타입 변환도 편하네요 고생하셨습니다!
} | ||
} | ||
|
||
struct UserRequest: FirestoreRequest { |
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.
각각의 Request 를 struct 로 묶는 방법 이로군요 🤔 좋은 시도인것 같습니다! 공통적으로 사용하는 Firestore.firestore() 를 extension 으로 묶은것도 좋네욧
completion(.failure(.emptyData)) | ||
return | ||
} | ||
guard let decodedModel = try? document.data(as: Request.Modeltype.self) else { |
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.
👏🏻👏🏻 protocol 를 채택한 모델을 이용해서 이렇게 간단하게 디코딩할 수 있네요!
@@ -23,7 +23,7 @@ extension FirestoreRequest { | |||
} | |||
|
|||
struct UserRequest: FirestoreRequest { | |||
typealias Modeltype = User | |||
typealias Modeltype = UserProfile |
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.
User 가 UserProfile 로 바뀌었네요! 훨씬 명확해 진 것 같습니다
📙 작업 내역
FirestoreRequest
프로토콜,UserRequest
타입을 추가🤔 고민과 해결
💭 기타 설명