X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=api%2Fmarket_config.go;fp=api%2Fmarket_config.go;h=c7e2e15428b181eb46f48260e852935dea2b0e6b;hb=4495b984d3e60874281f37cdb2dbe2cf1c3874ab;hp=e02c3ba48f5f44fdff6abedf8a7d76f98ef10e83;hpb=372ed7400f57355eb7dd98058b10ddeb1e1ff635;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/api/market_config.go b/api/market_config.go index e02c3ba..c7e2e15 100644 --- a/api/market_config.go +++ b/api/market_config.go @@ -5,9 +5,9 @@ import ( "strings" "time" - "github.com/jloup/utils" "git.immae.eu/Cryptoportfolio/Front.git/db" "git.immae.eu/Cryptoportfolio/Front.git/markets" + "github.com/jloup/utils" ) type MarketConfigQuery struct { @@ -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)