(w http.ResponseWriter, r *http.Request)
| 233 | } |
| 234 | |
| 235 | func (h *handler) createUser(w http.ResponseWriter, r *http.Request) { |
| 236 | var u UserReq |
| 237 | if err := json.NewDecoder(r.Body).Decode(&u); err != nil { |
| 238 | http.Error(w, "bad request", http.StatusBadRequest) |
| 239 | return |
| 240 | } |
| 241 | |
| 242 | // hash password |
| 243 | hashed, err := util.HashPassword(u.Password) |
| 244 | if err != nil { |
| 245 | http.Error(w, "error hashing password", http.StatusInternalServerError) |
| 246 | return |
| 247 | } |
| 248 | u.Password = hashed |
| 249 | |
| 250 | created, err := h.client.CreateUser(h.ctx, toPBUserReq(u)) |
| 251 | if err != nil { |
| 252 | http.Error(w, "error creating user", http.StatusInternalServerError) |
| 253 | return |
| 254 | } |
| 255 | |
| 256 | res := toUserRes(created) |
| 257 | w.Header().Set("Content-Type", "application/json") |
| 258 | w.WriteHeader(http.StatusCreated) |
| 259 | json.NewEncoder(w).Encode(res) |
| 260 | } |
| 261 | |
| 262 | func (h *handler) listUsers(w http.ResponseWriter, r *http.Request) { |
| 263 | users, err := h.client.ListUsers(h.ctx, &pb.UserReq{}) |
nothing calls this directly
no test coverage detected