From 38a1b7ad442124e1bb4c89c16cf7b3ebc33c8c92 Mon Sep 17 00:00:00 2001 From: Joakim Bygdell Date: Mon, 4 Nov 2024 13:01:20 +0100 Subject: [PATCH] Simplify deprecation function The heavy lifting is down in the database function. --- sda/cmd/api/api.go | 23 +---------------------- sda/cmd/api/api_test.go | 2 +- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/sda/cmd/api/api.go b/sda/cmd/api/api.go index 649a7231e..8eb2f004a 100644 --- a/sda/cmd/api/api.go +++ b/sda/cmd/api/api.go @@ -527,30 +527,9 @@ func listC4ghHashes(c *gin.Context) { func deprecateC4ghHash(c *gin.Context) { keyHash := strings.TrimPrefix(c.Param("keyHash"), "/") - - hashes, err := Conf.API.DB.ListKeyHashes() - if err != nil { - c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error()) - - return - } - found := false - for _, h := range hashes { - if h.Hash == keyHash { - found = true - - break - } - } - if !found { - c.AbortWithStatusJSON(http.StatusBadRequest, fmt.Errorf("%s not found", keyHash)) - - return - } - err = Conf.API.DB.DeprecateKeyHash(keyHash) if err != nil { - c.AbortWithStatusJSON(http.StatusInternalServerError, err.Error()) + c.AbortWithStatusJSON(http.StatusBadRequest, err.Error()) return } diff --git a/sda/cmd/api/api_test.go b/sda/cmd/api/api_test.go index bab7e247d..cdbeb75ed 100644 --- a/sda/cmd/api/api_test.go +++ b/sda/cmd/api/api_test.go @@ -1450,7 +1450,7 @@ func (suite *TestSuite) TestDeprecateC4ghHash() { // a second time gives an error since the key is alreadu deprecated resp2, err := client.Do(req) assert.NoError(suite.T(), err) - assert.Equal(suite.T(), http.StatusInternalServerError, resp2.StatusCode) + assert.Equal(suite.T(), http.StatusBadRequest, resp2.StatusCode) defer resp2.Body.Close() }