Record project continuation changes
This commit is contained in:
@@ -34,6 +34,10 @@ func (m *Module) RegisterRoutes(router chi.Router) {
|
||||
r.Get("/devices", m.handleTrustedDevices)
|
||||
r.Post("/devices/{deviceID}/revoke", m.handleRevokeTrustedDevice)
|
||||
})
|
||||
router.Route("/users", func(r chi.Router) {
|
||||
r.Get("/", m.handleListUsers)
|
||||
r.Post("/", m.handleCreateUser)
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Module) handleInstallationStatus(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -78,6 +82,32 @@ func (m *Module) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
httpx.WriteJSON(w, http.StatusOK, result)
|
||||
}
|
||||
|
||||
func (m *Module) handleListUsers(w http.ResponseWriter, r *http.Request) {
|
||||
actorUserID := r.URL.Query().Get("actor_user_id")
|
||||
users, err := m.service.ListUsers(r.Context(), actorUserID)
|
||||
if err != nil {
|
||||
status, message := m.service.MapError(err)
|
||||
httpx.WriteError(w, status, message)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"users": users})
|
||||
}
|
||||
|
||||
func (m *Module) handleCreateUser(w http.ResponseWriter, r *http.Request) {
|
||||
var cmd CreateUserCommand
|
||||
if err := json.NewDecoder(r.Body).Decode(&cmd); err != nil {
|
||||
httpx.WriteError(w, http.StatusBadRequest, "invalid user payload")
|
||||
return
|
||||
}
|
||||
user, err := m.service.CreateUser(r.Context(), cmd)
|
||||
if err != nil {
|
||||
status, message := m.service.MapError(err)
|
||||
httpx.WriteError(w, status, message)
|
||||
return
|
||||
}
|
||||
httpx.WriteJSON(w, http.StatusCreated, map[string]any{"user": user})
|
||||
}
|
||||
|
||||
func (m *Module) handleRefresh(w http.ResponseWriter, r *http.Request) {
|
||||
var cmd RefreshCommand
|
||||
if err := json.NewDecoder(r.Body).Decode(&cmd); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user