Compare commits

...

3 Commits

Author SHA1 Message Date
6a1fc193f4 fix: double scrollbar on desktop 2025-06-04 20:07:58 +02:00
118877f727 feat: user update last login 2025-06-04 20:07:48 +02:00
7b8fe6baf2 fix: set content-type to json 2025-06-04 20:07:39 +02:00
8 changed files with 46 additions and 1 deletions

View File

@ -62,6 +62,8 @@ func (h *AdminHandler) GetApiServices(w http.ResponseWriter, r *http.Request) {
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(Response{
Items: apiServices,
Count: len(apiServices),
@ -147,6 +149,9 @@ func (h *AdminHandler) AddApiService(w http.ResponseWriter, r *http.Request) {
}
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(Response{
Service: NewApiServiceDTO(service),
Credentials: ApiServiceCredentials{
@ -174,6 +179,8 @@ func (h *AdminHandler) GetApiService(w http.ResponseWriter, r *http.Request) {
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(NewApiServiceDTO(service)); err != nil {
web.Error(w, "failed to encode response", http.StatusInternalServerError)
}
@ -209,6 +216,8 @@ func (h *AdminHandler) RegenerateApiServiceSecret(w http.ResponseWriter, r *http
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(ApiServiceCredentials{
ClientId: service.ClientID,
ClientSecret: clientSecret,
@ -272,6 +281,8 @@ func (h *AdminHandler) UpdateApiService(w http.ResponseWriter, r *http.Request)
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(NewApiServiceDTO(updated)); err != nil {
web.Error(w, "failed to send updated api service", http.StatusInternalServerError)
}

View File

@ -47,6 +47,8 @@ func (h *AdminHandler) GetUsers(w http.ResponseWriter, r *http.Request) {
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(&Response{
Items: items,
Count: len(items),
@ -71,6 +73,8 @@ func (h *AdminHandler) GetUser(w http.ResponseWriter, r *http.Request) {
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(NewUserDTO(&user)); err != nil {
web.Error(w, "failed to encode user dto", http.StatusInternalServerError)
}

View File

@ -137,6 +137,8 @@ func (h *AuthHandler) refreshToken(w http.ResponseWriter, r *http.Request) {
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(Response{
AccessToken: access,
RefreshToken: refresh,
@ -213,6 +215,11 @@ func (h *AuthHandler) login(w http.ResponseWriter, r *http.Request) {
return
}
if err := h.repo.UpdateLastLogin(r.Context(), user.ID); err != nil {
web.Error(w, "failed to update user's last login", http.StatusInternalServerError)
return
}
encoder := json.NewEncoder(w)
type Response struct {

View File

@ -19,6 +19,9 @@ func (h *OAuthHandler) OpenIdConfiguration(w http.ResponseWriter, r *http.Reques
w.Header().Set("Content-Type", "application/json")
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(Response{
TokenEndpoint: h.cfg.Jwt.Issuer + "/api/v1/oauth/token",
AuthorizationEndpoint: h.cfg.Jwt.Issuer + "/api/v1/oauth/authorize",

View File

@ -118,6 +118,17 @@ func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (uuid.UU
return id, err
}
const updateLastLogin = `-- name: UpdateLastLogin :exec
UPDATE users
SET last_login = NOW()
WHERE id = $1
`
func (q *Queries) UpdateLastLogin(ctx context.Context, id uuid.UUID) error {
_, err := q.db.Exec(ctx, updateLastLogin, id)
return err
}
const updateProfilePicture = `-- name: UpdateProfilePicture :exec
UPDATE users
SET profile_picture = $1

View File

@ -98,6 +98,8 @@ func (h *UserHandler) register(w http.ResponseWriter, r *http.Request) {
Id string `json:"id"`
}
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(Response{
Id: id.String(),
}); err != nil {
@ -184,6 +186,8 @@ func (h *UserHandler) uploadAvatar(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
encoder := json.NewEncoder(w)
w.Header().Set("Content-Type", "application/json")
if err := encoder.Encode(Response{AvatarID: uploadInfo.Key}); err != nil {
web.Error(w, "failed to write response", http.StatusInternalServerError)
}

View File

@ -19,3 +19,8 @@ SELECT * FROM users WHERE id = $1 LIMIT 1;
UPDATE users
SET profile_picture = $1
WHERE id = $2;
-- name: UpdateLastLogin :exec
UPDATE users
SET last_login = NOW()
WHERE id = $1;

View File

@ -7,7 +7,7 @@ import { Outlet } from "react-router";
const DashboardLayout: FC = () => {
return (
<div className="relative z-10 flex items-center justify-center min-h-screen">
<Card className="overflow-y-auto min-h-screen w-full min-w-full shadow-lg bg-white/85 dark:bg-black/85 backdrop-blur-md sm:rounded-none">
<Card className="min-h-screen w-full min-w-full max-h-screen shadow-lg bg-white/85 dark:bg-black/85 backdrop-blur-md sm:rounded-none overflow-y-auto sm:overflow-hidden">
<div className="flex flex-col w-full h-full flex-1 items-center sm:pt-0 relative">
<div className="flex flex-row items-center absolute left-4 top-4">
<img src="/icon.png" alt="icon" className="w-6 h-6" />