Перенес основы lab3 в lab4
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user