WIP of user avatar work
Switching from laptop
This commit is contained in:
parent
ad90f9c95e
commit
6f9a511874
9 changed files with 68 additions and 2 deletions
|
|
@ -85,6 +85,26 @@ func authenticatedHandlerJSONPost[ReqType any](f handlerFunctionPostAuthenticate
|
|||
http.Redirect(w, r, path, http.StatusFound)
|
||||
})
|
||||
}
|
||||
|
||||
type handlerFunctionPutAuthenticated[ReqType any] func(context.Context, *http.Request, platform.User, ReqType) (string, *nhttp.ErrorWithStatus)
|
||||
|
||||
func authenticatedHandlerJSONPut[ReqType any](f handlerFunctionPutAuthenticated[ReqType]) http.Handler {
|
||||
return auth.NewEnsureAuth(func(w http.ResponseWriter, r *http.Request, u platform.User) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
req, e := parseRequest[ReqType](r)
|
||||
if e != nil {
|
||||
serializeError(w, e)
|
||||
return
|
||||
}
|
||||
ctx := r.Context()
|
||||
path, e := f(ctx, r, u, *req)
|
||||
if e != nil {
|
||||
serializeError(w, e)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, path, http.StatusFound)
|
||||
})
|
||||
}
|
||||
func parseRequest[ReqType any](r *http.Request) (*ReqType, *nhttp.ErrorWithStatus) {
|
||||
var req ReqType
|
||||
body, err := io.ReadAll(r.Body)
|
||||
|
|
|
|||
15
api/resource.go
Normal file
15
api/resource.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
//"encoding/json"
|
||||
)
|
||||
|
||||
type resource[T any] struct {
|
||||
inner *T
|
||||
}
|
||||
|
||||
func newResource[T any](inner *T) resource[T] {
|
||||
return resource[T]{
|
||||
inner: inner,
|
||||
}
|
||||
}
|
||||
|
|
@ -48,6 +48,7 @@ func AddRoutes(r chi.Router) {
|
|||
r.Method("GET", "/user/self", authenticatedHandlerJSON(getUserSelf))
|
||||
r.Method("GET", "/user/suggestion", authenticatedHandlerJSON(listUserSuggestion))
|
||||
r.Method("GET", "/user", authenticatedHandlerJSON(listUser))
|
||||
r.Method("PUT", "/user/{id}", authenticatedHandlerJSONPut(userPut))
|
||||
|
||||
// Unauthenticated endpoints
|
||||
r.Get("/district", apiGetDistrict)
|
||||
|
|
|
|||
|
|
@ -95,3 +95,7 @@ func listUserSuggestion(ctx context.Context, r *http.Request, user platform.User
|
|||
Users: users,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func userPut(ctx context.Context, r *http.Request, user platform.User, updates platform.User) {
|
||||
//if updates.Avatar
|
||||
}
|
||||
|
|
|
|||
14
db/migrations/00125_user_props.sql
Normal file
14
db/migrations/00125_user_props.sql
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
-- +goose Up
|
||||
ALTER TABLE user_
|
||||
ADD COLUMN is_active BOOLEAN,
|
||||
ADD COLUMN is_drone_pilot BOOLEAN,
|
||||
ADD COLUMN is_warrant BOOLEAN,
|
||||
ADD COLUMN avatar UUID;
|
||||
UPDATE user_ SET is_active = TRUE;
|
||||
ALTER TABLE user_ ALTER COLUMN is_active SET NOT NULL;
|
||||
-- +goose Down
|
||||
ALTER TABLE user_
|
||||
DROP COLUMN is_active,
|
||||
DROP COLUMN is_drone_pilot,
|
||||
DROP COLUMN is_warrant,
|
||||
DROP COLUMN avatar;
|
||||
|
|
@ -24,6 +24,7 @@ func (e NoUserError) Error() string { return "That user does not exist" }
|
|||
|
||||
type User struct {
|
||||
Active bool `json:"active"`
|
||||
Avatar string `json:"avatar"`
|
||||
DisplayName string `json:"display_name"`
|
||||
ID int `json:"id"`
|
||||
Initials string `json:"initials"`
|
||||
|
|
@ -53,6 +54,7 @@ func (u User) HasRoot() bool {
|
|||
func newUser(ctx context.Context, org Organization, user *models.User) User {
|
||||
u := User{
|
||||
Active: true,
|
||||
Avatar: user.Avatar,
|
||||
DisplayName: user.DisplayName,
|
||||
ID: int(user.ID),
|
||||
Initials: extractInitials(user.DisplayName),
|
||||
|
|
|
|||
10
ts/components/Card.vue
Normal file
10
ts/components/Card.vue
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<template>
|
||||
<div class="card mb-4">
|
||||
<div class="card-header text-white">
|
||||
<slot name="header"></slot>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<slot name="body"></slot>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -85,7 +85,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row"></div>
|
||||
<div class="col-lg-6">
|
||||
<!-- RCS Testing -->
|
||||
<div class="card mb-4">
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ const saveChanges = async () => {
|
|||
console.error("Failed to upload avatar", error);
|
||||
}
|
||||
}
|
||||
const response = await fetch(user.urls.api.user, {
|
||||
const response = await fetch(user.urls.api.users, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue