You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Architecture with standard features: config, health check, logging, middleware log tracing
13
+

#### *Response:* 1: success, 0: not found, -1: error
175
+
```json
176
+
1
177
+
```
178
+
179
+
#### Problems for patch
180
+
If we pass a struct as a parameter, we cannot control what fields we need to update. So, we must pass a map as a parameter.
181
+
```go
182
+
typeUserServiceinterface {
183
+
Update(ctx context.Context, user *User) (int64, error)
184
+
Patch(ctx context.Context, user map[string]interface{}) (int64, error)
185
+
}
186
+
```
187
+
We must solve 2 problems:
188
+
1. At http handler layer, we must convert the user struct to map, with json format, and make sure the nested data types are passed correctly.
189
+
2. At repository layer, from json format, we must convert the json format to database format (in this case, we must convert to bson of Mongo)
190
+
191
+
#### Solutions for patch
192
+
At http handler layer, we use [core-go/service](https://github.com/core-go/service), to convert the user struct to map, to make sure we just update the fields we need to update
193
+
```go
194
+
import server "github.com/core-go/service"
195
+
196
+
func(h *UserHandler) Patch(whttp.ResponseWriter, r *http.Request) {
0 commit comments