fix: type overriding
This commit is contained in:
@ -11,14 +11,13 @@ import (
|
|||||||
"gitea.local/admin/hspguard/internal/web"
|
"gitea.local/admin/hspguard/internal/web"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ApiServiceDTO struct {
|
type ApiServiceDTO struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
ClientID string `json:"client_id"`
|
ClientID string `json:"client_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description *string `json:"description"`
|
||||||
RedirectUris []string `json:"redirect_uris"`
|
RedirectUris []string `json:"redirect_uris"`
|
||||||
Scopes []string `json:"scopes"`
|
Scopes []string `json:"scopes"`
|
||||||
GrantTypes []string `json:"grant_types"`
|
GrantTypes []string `json:"grant_types"`
|
||||||
@ -32,7 +31,7 @@ func NewApiServiceDTO(service repository.ApiService) ApiServiceDTO {
|
|||||||
ID: service.ID,
|
ID: service.ID,
|
||||||
ClientID: service.ClientID,
|
ClientID: service.ClientID,
|
||||||
Name: service.Name,
|
Name: service.Name,
|
||||||
Description: service.Description.String,
|
Description: service.Description,
|
||||||
RedirectUris: service.RedirectUris,
|
RedirectUris: service.RedirectUris,
|
||||||
Scopes: service.Scopes,
|
Scopes: service.Scopes,
|
||||||
GrantTypes: service.GrantTypes,
|
GrantTypes: service.GrantTypes,
|
||||||
@ -129,10 +128,7 @@ func (h *AdminHandler) AddApiService(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if req.Description != "" {
|
if req.Description != "" {
|
||||||
params.Description = pgtype.Text{
|
params.Description = &req.Description
|
||||||
String: req.Description,
|
|
||||||
Valid: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
service, err := h.repo.CreateApiService(r.Context(), params)
|
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{
|
updated, err := h.repo.UpdateApiService(r.Context(), repository.UpdateApiServiceParams{
|
||||||
ClientID: service.ClientID,
|
ClientID: service.ClientID,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Description: pgtype.Text{
|
Description: &req.Description,
|
||||||
String: req.Description,
|
|
||||||
Valid: true,
|
|
||||||
},
|
|
||||||
RedirectUris: req.RedirectUris,
|
RedirectUris: req.RedirectUris,
|
||||||
Scopes: req.Scopes,
|
Scopes: req.Scopes,
|
||||||
GrantTypes: req.GrantTypes,
|
GrantTypes: req.GrantTypes,
|
||||||
|
@ -167,7 +167,7 @@ func (h *AuthHandler) getProfile(w http.ResponseWriter, r *http.Request) {
|
|||||||
"phone_number": user.PhoneNumber,
|
"phone_number": user.PhoneNumber,
|
||||||
"isAdmin": user.IsAdmin,
|
"isAdmin": user.IsAdmin,
|
||||||
"last_login": user.LastLogin,
|
"last_login": user.LastLogin,
|
||||||
"profile_picture": user.ProfilePicture.String,
|
"profile_picture": user.ProfilePicture,
|
||||||
"updated_at": user.UpdatedAt,
|
"updated_at": user.UpdatedAt,
|
||||||
"created_at": user.CreatedAt,
|
"created_at": user.CreatedAt,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -222,7 +222,7 @@ func (h *AuthHandler) login(w http.ResponseWriter, r *http.Request) {
|
|||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
ProfilePicture string `json:"profile_picture"`
|
ProfilePicture *string `json:"profile_picture"`
|
||||||
// Avatar
|
// Avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ func (h *AuthHandler) login(w http.ResponseWriter, r *http.Request) {
|
|||||||
FullName: user.FullName,
|
FullName: user.FullName,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Id: user.ID.String(),
|
Id: user.ID.String(),
|
||||||
ProfilePicture: user.ProfilePicture.String,
|
ProfilePicture: user.ProfilePicture,
|
||||||
// Avatar
|
// Avatar
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
web.Error(w, "failed to encode response", http.StatusInternalServerError)
|
web.Error(w, "failed to encode response", http.StatusInternalServerError)
|
||||||
|
@ -81,7 +81,7 @@ func (h *OAuthHandler) tokenEndpoint(w http.ResponseWriter, r *http.Request) {
|
|||||||
// TODO:
|
// TODO:
|
||||||
EmailVerified: true,
|
EmailVerified: true,
|
||||||
Name: user.FullName,
|
Name: user.FullName,
|
||||||
Picture: user.ProfilePicture.String,
|
Picture: user.ProfilePicture,
|
||||||
Nonce: nonce,
|
Nonce: nonce,
|
||||||
Roles: []string{"user", "admin"},
|
Roles: []string{"user", "admin"},
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
|
@ -12,7 +12,7 @@ type ApiClaims struct {
|
|||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
EmailVerified bool `json:"email_verified"`
|
EmailVerified bool `json:"email_verified"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Picture string `json:"picture"`
|
Picture *string `json:"picture"`
|
||||||
Nonce string `json:"nonce"`
|
Nonce string `json:"nonce"`
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
// TODO: add given_name, family_name, locale...
|
// TODO: add given_name, family_name, locale...
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"gitea.local/admin/hspguard/internal/web"
|
"gitea.local/admin/hspguard/internal/web"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5/pgtype"
|
|
||||||
"github.com/minio/minio-go/v7"
|
"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{
|
if err := h.repo.UpdateProfilePicture(r.Context(), repository.UpdateProfilePictureParams{
|
||||||
ProfilePicture: pgtype.Text{
|
ProfilePicture: &uploadInfo.Key,
|
||||||
String: uploadInfo.Key,
|
|
||||||
Valid: true,
|
|
||||||
},
|
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
web.Error(w, "failed to update profile picture", http.StatusInternalServerError)
|
web.Error(w, "failed to update profile picture", http.StatusInternalServerError)
|
||||||
|
Reference in New Issue
Block a user