| 52 | } |
| 53 | |
| 54 | func (s *Service) SyncUsers(w http.ResponseWriter, r *http.Request) { |
| 55 | body, err := io.ReadAll(r.Body) |
| 56 | if err != nil { |
| 57 | http.Error(w, "Failed to read request body", http.StatusBadRequest) |
| 58 | return |
| 59 | } |
| 60 | defer r.Body.Close() |
| 61 | |
| 62 | users := &common.Users{} |
| 63 | if err = proto.Unmarshal(body, users); err != nil { |
| 64 | http.Error(w, "Failed to decode user", http.StatusBadRequest) |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | if err = s.Backend().SyncUsers(r.Context(), users.GetUsers()); err != nil { |
| 69 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | response, _ := proto.Marshal(&common.Empty{}) |
| 74 | |
| 75 | w.Header().Set("Content-Type", "application/x-protobuf") |
| 76 | if _, err = w.Write(response); err != nil { |
| 77 | http.Error(w, "Failed to write response", http.StatusInternalServerError) |
| 78 | return |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | func (s *Service) SyncUsersChunked(w http.ResponseWriter, r *http.Request) { |
| 83 | reader := bufio.NewReader(r.Body) |