@@ -94,6 +94,13 @@ extension FirestoreService: FirestoreServiceProtocol {
9494
9595 if case . update = endpoint. method {
9696 guard let requestDTO = endpoint. requestDTO else {
97+ if let requestDTODictionary = endpoint. requestDTODictionary {
98+ return documentRef
99+ . updateData ( requestDTODictionary)
100+ . subscribe ( on: backgroundQueue)
101+ . convertFirestoreServiceError ( )
102+ . eraseToAnyPublisher ( )
103+ }
97104 return Fail ( error: FirestoreServiceError . invalidRequestDTO) . eraseToAnyPublisher ( )
98105 }
99106 do {
@@ -113,9 +120,11 @@ extension FirestoreService: FirestoreServiceProtocol {
113120 /// Save a document using endpoint. And the ID of the created document A is returned.
114121 ///
115122 /// Notes:
116- /// 1. If requestDTO is nil, only the document is created without any fields.
123+ /// 1. If requestDTO and requestDTODictionary are nil, only the document is created without any fields.
117124 /// The same applies if you set the document ID or give the document ID through firesotre's automatic document.
118- /// 2. If there is a response DTO at the endpoint,
125+ /// 2. If a respose dto dictionary is exist at the endpoint,
126+ /// It is saved in the document If documentId exists, the ID of the document is specified, otherwise it is automatically generated.
127+ /// 3. If there is a response DTO at the endpoint,
119128 /// fields and values are formed through the key values defined in CodingKeys through encode(to:) of the encodable.
120129 ///
121130 /// Depending on whether there is a specific ID or not, a document with a specified documentId or an automatic ID is created.
@@ -130,7 +139,26 @@ extension FirestoreService: FirestoreServiceProtocol {
130139 return Fail ( error: FirestoreServiceError . collectionNotFound) . eraseToAnyPublisher ( )
131140 }
132141
133- /// If request DTO is nil, it is assumed that only a document with no fields is created.
142+ if let requestDTODictionary = endpoint. requestDTODictionary {
143+ if let documentId {
144+ return collectionRef
145+ . document ( documentId)
146+ . setData ( requestDTODictionary)
147+ . subscribe ( on: backgroundQueue)
148+ . convertFirestoreServiceError ( )
149+ . map { _ in return documentId }
150+ . eraseToAnyPublisher ( )
151+ } else {
152+ return collectionRef
153+ . addDocument ( data: requestDTODictionary)
154+ . subscribe ( on: backgroundQueue)
155+ . map { $0. documentID }
156+ . convertFirestoreServiceError ( )
157+ . eraseToAnyPublisher ( )
158+ }
159+ }
160+
161+ /// If request DTO and requestDTODictionary are nil it is assumed that only a document with no fields is created.
134162 guard let requestDTO = endpoint. requestDTO else {
135163 if let documentId {
136164 return collectionRef
0 commit comments