feat: add VCard API integration with configuration and proxy endpoints
- Implemented VCard API controller with methods to manage configuration (save, get). - Added proxy functions to handle API requests for users, vcards, memberships, payments, transactions, logs, and miniwebs. - Included error handling and response formatting for API interactions.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// VcardApiConfig almacena las credenciales para conectar con la API Admin del
|
||||
// sistema VCard externo (Laravel + Sanctum, prefijo /api/admin/*).
|
||||
type VcardApiConfig struct {
|
||||
gorm.Model
|
||||
Nombre string `json:"nombre" gorm:"column:nombre;not null"`
|
||||
BaseURL string `json:"base_url" gorm:"column:base_url;type:text;not null"`
|
||||
BearerToken string `json:"bearer_token" gorm:"column:bearer_token;type:text;not null"`
|
||||
Activo bool `json:"activo" gorm:"column:activo;default:true"`
|
||||
}
|
||||
|
||||
func (VcardApiConfig) TableName() string { return "vcard_api_configs" }
|
||||
|
||||
func GetVcardApiConfig() (*VcardApiConfig, error) {
|
||||
var cfg VcardApiConfig
|
||||
if err := app.Http.Database.DB.First(&cfg).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func UpsertVcardApiConfig(nombre, baseURL, bearerToken string, activo bool) (*VcardApiConfig, error) {
|
||||
var cfg VcardApiConfig
|
||||
err := app.Http.Database.DB.First(&cfg).Error
|
||||
if err != nil {
|
||||
cfg = VcardApiConfig{
|
||||
Nombre: nombre,
|
||||
BaseURL: baseURL,
|
||||
BearerToken: bearerToken,
|
||||
Activo: activo,
|
||||
}
|
||||
if createErr := app.Http.Database.DB.Create(&cfg).Error; createErr != nil {
|
||||
return nil, createErr
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
cfg.Nombre = nombre
|
||||
cfg.BaseURL = baseURL
|
||||
if bearerToken != "" {
|
||||
cfg.BearerToken = bearerToken
|
||||
}
|
||||
cfg.Activo = activo
|
||||
if err := app.Http.Database.DB.Save(&cfg).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user