Перенес основы lab3 в lab4

This commit is contained in:
Daria0w0
2026-11-06 14:44:30 +03:00
parent ec540a1a72
commit 9197e151ba
59 changed files with 4761 additions and 3 deletions
+29
View File
@@ -0,0 +1,29 @@
package httpapi
import "net/http"
type createUserRequest struct {
Username string `json:"username"`
DisplayName string `json:"display_name"`
}
func (api *API) createUser(w http.ResponseWriter, r *http.Request) {
var body createUserRequest
if !readJSON(w, r, &body, "username", "display_name") {
return
}
user, err := api.messenger.RegisterUser(body.Username, body.DisplayName)
if err != nil {
writeAppError(w, err)
return
}
writeJSON(w, http.StatusCreated, user)
}
func (api *API) currentUser(w http.ResponseWriter, r *http.Request) {
user := userFromContext(r.Context())
writeJSON(w, http.StatusOK, user)
}