fix: type overriding

This commit is contained in:
2025-06-04 12:33:22 +02:00
parent c27d837ab0
commit 849b5935c2
5 changed files with 16 additions and 27 deletions

View File

@ -11,14 +11,13 @@ import (
"gitea.local/admin/hspguard/internal/web"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
)
type ApiServiceDTO struct {
ID uuid.UUID `json:"id"`
ClientID string `json:"client_id"`
Name string `json:"name"`
Description string `json:"description"`
Description *string `json:"description"`
RedirectUris []string `json:"redirect_uris"`
Scopes []string `json:"scopes"`
GrantTypes []string `json:"grant_types"`
@ -32,7 +31,7 @@ func NewApiServiceDTO(service repository.ApiService) ApiServiceDTO {
ID: service.ID,
ClientID: service.ClientID,
Name: service.Name,
Description: service.Description.String,
Description: service.Description,
RedirectUris: service.RedirectUris,
Scopes: service.Scopes,
GrantTypes: service.GrantTypes,
@ -129,10 +128,7 @@ func (h *AdminHandler) AddApiService(w http.ResponseWriter, r *http.Request) {
}
if req.Description != "" {
params.Description = pgtype.Text{
String: req.Description,
Valid: true,
}
params.Description = &req.Description
}
service, err := h.repo.CreateApiService(r.Context(), params)
@ -264,10 +260,7 @@ func (h *AdminHandler) UpdateApiService(w http.ResponseWriter, r *http.Request)
updated, err := h.repo.UpdateApiService(r.Context(), repository.UpdateApiServiceParams{
ClientID: service.ClientID,
Name: req.Name,
Description: pgtype.Text{
String: req.Description,
Valid: true,
},
Description: &req.Description,
RedirectUris: req.RedirectUris,
Scopes: req.Scopes,
GrantTypes: req.GrantTypes,

View File

@ -167,7 +167,7 @@ func (h *AuthHandler) getProfile(w http.ResponseWriter, r *http.Request) {
"phone_number": user.PhoneNumber,
"isAdmin": user.IsAdmin,
"last_login": user.LastLogin,
"profile_picture": user.ProfilePicture.String,
"profile_picture": user.ProfilePicture,
"updated_at": user.UpdatedAt,
"created_at": user.CreatedAt,
}); err != nil {
@ -222,7 +222,7 @@ func (h *AuthHandler) login(w http.ResponseWriter, r *http.Request) {
FullName string `json:"full_name"`
Email string `json:"email"`
Id string `json:"id"`
ProfilePicture string `json:"profile_picture"`
ProfilePicture *string `json:"profile_picture"`
// Avatar
}
@ -234,7 +234,7 @@ func (h *AuthHandler) login(w http.ResponseWriter, r *http.Request) {
FullName: user.FullName,
Email: user.Email,
Id: user.ID.String(),
ProfilePicture: user.ProfilePicture.String,
ProfilePicture: user.ProfilePicture,
// Avatar
}); err != nil {
web.Error(w, "failed to encode response", http.StatusInternalServerError)

View File

@ -81,7 +81,7 @@ func (h *OAuthHandler) tokenEndpoint(w http.ResponseWriter, r *http.Request) {
// TODO:
EmailVerified: true,
Name: user.FullName,
Picture: user.ProfilePicture.String,
Picture: user.ProfilePicture,
Nonce: nonce,
Roles: []string{"user", "admin"},
RegisteredClaims: jwt.RegisteredClaims{

View File

@ -12,7 +12,7 @@ type ApiClaims struct {
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
Name string `json:"name"`
Picture string `json:"picture"`
Picture *string `json:"picture"`
Nonce string `json:"nonce"`
Roles []string `json:"roles"`
// TODO: add given_name, family_name, locale...

View File

@ -19,7 +19,6 @@ import (
"gitea.local/admin/hspguard/internal/web"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/minio/minio-go/v7"
)
@ -170,10 +169,7 @@ func (h *UserHandler) uploadAvatar(w http.ResponseWriter, r *http.Request) {
}
if err := h.repo.UpdateProfilePicture(r.Context(), repository.UpdateProfilePictureParams{
ProfilePicture: pgtype.Text{
String: uploadInfo.Key,
Valid: true,
},
ProfilePicture: &uploadInfo.Key,
ID: user.ID,
}); err != nil {
web.Error(w, "failed to update profile picture", http.StatusInternalServerError)