| 16 | ) |
| 17 | |
| 18 | func (s *Service) SyncUser(w http.ResponseWriter, r *http.Request) { |
| 19 | body, err := io.ReadAll(r.Body) |
| 20 | if err != nil { |
| 21 | http.Error(w, "Failed to read request body", http.StatusBadRequest) |
| 22 | return |
| 23 | } |
| 24 | defer r.Body.Close() |
| 25 | |
| 26 | user := &common.User{} |
| 27 | if err = proto.Unmarshal(body, user); err != nil { |
| 28 | http.Error(w, "Failed to decode user", http.StatusBadRequest) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | if user.GetEmail() == "" { |
| 33 | http.Error(w, "email is required", http.StatusBadRequest) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | log.Printf("Got user: %v", user.GetEmail()) |
| 38 | |
| 39 | if err = s.Backend().SyncUser(r.Context(), user); err != nil { |
| 40 | log.Printf("Error syncing user: %v", err) |
| 41 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | response, _ := proto.Marshal(&common.Empty{}) |
| 46 | |
| 47 | w.Header().Set("Content-Type", "application/x-protobuf") |
| 48 | if _, err = w.Write(response); err != nil { |
| 49 | http.Error(w, "Failed to write response", http.StatusInternalServerError) |
| 50 | return |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func (s *Service) SyncUsers(w http.ResponseWriter, r *http.Request) { |
| 55 | body, err := io.ReadAll(r.Body) |