chore: update
This commit is contained in:
@@ -21,6 +21,14 @@ func NewHandler(svc *Service, helm *HelmProvisioner) *Handler {
|
||||
type createRequest struct {
|
||||
LeadID string `json:"lead_id" binding:"omitempty,uuid4"`
|
||||
Username string `json:"username" binding:"omitempty,min=3,max=64,alphanum"`
|
||||
|
||||
// Réglages saisis dans le popup de déploiement (voir ProvisionConfig).
|
||||
TelegramBotToken string `json:"telegram_bot_token" binding:"omitempty"`
|
||||
NowPaymentsAPIKey string `json:"nowpayments_api_key" binding:"omitempty"`
|
||||
NowPaymentsIPNSecret string `json:"nowpayments_ipn_secret" binding:"omitempty"`
|
||||
StorageDriver string `json:"storage_driver" binding:"omitempty,oneof=local s3"`
|
||||
S3Bucket string `json:"s3_bucket" binding:"omitempty,max=63"`
|
||||
S3Endpoint string `json:"s3_endpoint" binding:"omitempty,max=255"`
|
||||
}
|
||||
|
||||
type DetailDemoUserRequest struct {
|
||||
@@ -43,13 +51,23 @@ func (h *Handler) Create(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "requête invalide"})
|
||||
return
|
||||
}
|
||||
d, err := h.svc.Create(req.LeadID, req.Username)
|
||||
cfg := ProvisionConfig{
|
||||
TelegramBotToken: req.TelegramBotToken,
|
||||
NowPaymentsAPIKey: req.NowPaymentsAPIKey,
|
||||
NowPaymentsIPNSecret: req.NowPaymentsIPNSecret,
|
||||
StorageDriver: req.StorageDriver,
|
||||
S3Bucket: req.S3Bucket,
|
||||
S3Endpoint: req.S3Endpoint,
|
||||
}
|
||||
d, err := h.svc.Create(req.LeadID, req.Username, cfg)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, ErrCapacityReached):
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "capacité maximale de démos atteinte"})
|
||||
case errors.Is(err, ErrPoolExhausted):
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "plus de ressources externes disponibles pour le moment (slots Telegram/NowPayments épuisés)"})
|
||||
case errors.Is(err, ErrUserHasActiveDemo):
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "ce client a déjà une démo active"})
|
||||
case errors.Is(err, ErrS3ConfigIncomplete), errors.Is(err, ErrInvalidStorageDriver):
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
default:
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "erreur serveur"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user