]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - api/market_config.go
Update static assets.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / api / market_config.go
index e7b2341760f0d4a64df680767de8b0ea2afeb5ff..c7e2e15428b181eb46f48260e852935dea2b0e6b 100644 (file)
@@ -5,9 +5,9 @@ import (
        "strings"
        "time"
 
+       "git.immae.eu/Cryptoportfolio/Front.git/db"
+       "git.immae.eu/Cryptoportfolio/Front.git/markets"
        "github.com/jloup/utils"
-       "immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front/db"
-       "immae.eu/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front/markets"
 )
 
 type MarketConfigQuery struct {
@@ -76,7 +76,7 @@ func (q TestMarketCredentialsQuery) Run() (interface{}, *Error) {
        }
 
        if config == nil || config.Config["key"] == "" || config.Config["secret"] == "" {
-               return nil, &Error{InvalidMarketCredentials, "no market credentials", fmt.Errorf("market credentials are empty for marketId '%v'", q.In.Market)}
+               return nil, &Error{MarketCredentialsNotConfigured, "no market credentials", fmt.Errorf("market credentials are empty for marketId '%v'", q.In.Market)}
        }
 
        resultErr := CallExternalService(fmt.Sprintf("'%s' TestCredentials", q.In.Market), EXTERNAL_SERVICE_TIMEOUT_SECONDS*time.Second, func() error {
@@ -97,10 +97,23 @@ func (q TestMarketCredentialsQuery) Run() (interface{}, *Error) {
                return nil
        })
 
-       if resultErr != nil {
+       var newStatus db.MarketConfigStatus = config.Status
+
+       if ErrorIs(resultErr, InvalidMarketCredentials) || ErrorIs(resultErr, IPRestrictedApiKey) || ErrorIs(resultErr, MarketCredentialsNotConfigured) {
+               newStatus = db.MarketConfigInvalidCredentials
+       } else if resultErr != nil {
+               return nil, NewInternalError(resultErr)
+       } else if resultErr != nil {
                return nil, NewInternalError(resultErr)
        }
 
+       if newStatus != config.Status {
+               config, err = db.SetMarketConfigStatus(*config, newStatus)
+               if err != nil {
+                       return nil, NewInternalError(err)
+               }
+       }
+
        return nil, nil
 }
 
@@ -158,7 +171,7 @@ func (q UpdateMarketConfigQuery) Run() (interface{}, *Error) {
 
        var newStatus db.MarketConfigStatus = db.MarketConfigEnabled
 
-       if ErrorIs(resultErr, InvalidMarketCredentials) || ErrorIs(resultErr, IPRestrictedApiKey) {
+       if ErrorIs(resultErr, InvalidMarketCredentials) || ErrorIs(resultErr, IPRestrictedApiKey) || ErrorIs(resultErr, MarketCredentialsNotConfigured) {
                newStatus = db.MarketConfigInvalidCredentials
        } else if resultErr != nil {
                return nil, NewInternalError(resultErr)