feat: accept description and is active fields
This commit is contained in:
@ -29,6 +29,6 @@ func NewApiServiceDTO(service repository.ApiService) ApiServiceDTO {
|
||||
GrantTypes: service.GrantTypes,
|
||||
CreatedAt: service.CreatedAt,
|
||||
UpdatedAt: service.UpdatedAt,
|
||||
IsActive: false,
|
||||
IsActive: service.IsActive,
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"gitea.local/admin/hspguard/internal/util"
|
||||
"gitea.local/admin/hspguard/internal/web"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type AdminHandler struct {
|
||||
@ -107,14 +108,24 @@ func (h *AdminHandler) AddApiService(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
service, err := h.repo.CreateApiService(r.Context(), repository.CreateApiServiceParams{
|
||||
params := repository.CreateApiServiceParams{
|
||||
ClientID: clientId,
|
||||
ClientSecret: hashSecret,
|
||||
Name: req.Name,
|
||||
RedirectUris: req.RedirectUris,
|
||||
Scopes: req.Scopes,
|
||||
GrantTypes: req.GrantTypes,
|
||||
})
|
||||
IsActive: req.IsActive,
|
||||
}
|
||||
|
||||
if req.Description != "" {
|
||||
params.Description = pgtype.Text{
|
||||
String: req.Description,
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
|
||||
service, err := h.repo.CreateApiService(r.Context(), params)
|
||||
if err != nil {
|
||||
web.Error(w, "failed to create new api service", http.StatusInternalServerError)
|
||||
return
|
||||
@ -124,8 +135,24 @@ func (h *AdminHandler) AddApiService(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
service.ClientSecret = clientSecret
|
||||
|
||||
type ApiServiceCredentials struct {
|
||||
ClientId string `json:"client_id"`
|
||||
ClientSecret string `json:"client_secret"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Service ApiServiceDTO `json:"service"`
|
||||
Credentials ApiServiceCredentials `json:"credentials"`
|
||||
}
|
||||
|
||||
encoder := json.NewEncoder(w)
|
||||
if err := encoder.Encode(NewApiServiceDTO(service)); err != nil {
|
||||
if err := encoder.Encode(Response{
|
||||
Service: NewApiServiceDTO(service),
|
||||
Credentials: ApiServiceCredentials{
|
||||
ClientId: service.ClientID,
|
||||
ClientSecret: service.ClientSecret,
|
||||
},
|
||||
}); err != nil {
|
||||
web.Error(w, "failed to encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user