Skip to content

Commit

Permalink
add show secret param
Browse files Browse the repository at this point in the history
  • Loading branch information
philipphomberger committed Apr 27, 2024
1 parent fa1f64c commit 3a53da7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions controller/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func CreateSecret(c *gin.Context) {
templateCollection := database.GetCollection(database.DB, "secrets")
result, err := templateCollection.InsertOne(ctx, newSecret)
if err != nil {
c.JSON(http.StatusInternalServerError, responses.GenericResponse{Status: http.StatusInternalServerError, Message: "error", Data: map[string]interface{}{"data": err.Error()}})
c.JSON(http.StatusInternalServerError, responses.GenericResponse{Status: http.StatusInternalServerError, Message: "error", Data: err.Error()})
return
}
c.JSON(http.StatusCreated, responses.GenericResponse{Status: http.StatusCreated, Message: "success", Data: map[string]interface{}{"data": result}})
c.JSON(http.StatusOK, responses.GenericResponse{Status: http.StatusOK, Message: "success", Data: result})
}

func GetSecrets(c *gin.Context) {
Expand All @@ -47,7 +47,7 @@ func GetSecrets(c *gin.Context) {
if err := result.All(ctx, &results); err != nil {
panic(err)
}
c.JSON(http.StatusOK, responses.GenericResponse{Status: http.StatusOK, Message: "success", Data: map[string]interface{}{"data": results}})
c.JSON(http.StatusOK, responses.GenericResponse{Status: http.StatusOK, Message: "success", Data: results})
}

func GetSecret(c *gin.Context) {
Expand All @@ -70,7 +70,7 @@ func GetSecret(c *gin.Context) {
} else {
result.Value = "*********"
}
c.JSON(http.StatusOK, responses.GenericResponse{Status: http.StatusOK, Message: "success", Data: map[string]interface{}{"data": result}})
c.JSON(http.StatusOK, responses.GenericResponse{Status: http.StatusOK, Message: "success", Data: result})
}

func DelSecret(c *gin.Context) {
Expand All @@ -87,7 +87,7 @@ func DelSecret(c *gin.Context) {
}
panic(err)
}
c.JSON(http.StatusOK, responses.GenericResponse{Status: http.StatusOK, Message: "success delete", Data: map[string]interface{}{"data": result}})
c.JSON(http.StatusOK, responses.GenericResponse{Status: http.StatusOK, Message: "success delete", Data: result})
}

func PutSecret(c *gin.Context) {
Expand All @@ -97,13 +97,13 @@ func PutSecret(c *gin.Context) {
var newSecret models.Secret
//validate the request body
if err := c.BindJSON(&newSecret); err != nil {
c.JSON(http.StatusBadRequest, responses.GenericResponse{Status: http.StatusBadRequest, Message: "error", Data: map[string]interface{}{"data": err.Error()}})
c.JSON(http.StatusBadRequest, responses.GenericResponse{Status: http.StatusBadRequest, Message: "error", Data: err.Error()})
return
}

//use the validator library to validate required fields
if validationErr := validate.Struct(&newSecret); validationErr != nil {
c.JSON(http.StatusBadRequest, responses.GenericResponse{Status: http.StatusBadRequest, Message: "error", Data: map[string]interface{}{"data": validationErr.Error()}})
c.JSON(http.StatusBadRequest, responses.GenericResponse{Status: http.StatusBadRequest, Message: "error", Data: validationErr.Error()})
return
}
var result models.Secret
Expand All @@ -118,5 +118,5 @@ func PutSecret(c *gin.Context) {
panic(err)
}

c.JSON(http.StatusCreated, responses.GenericResponse{Status: http.StatusCreated, Message: "success replaced", Data: map[string]interface{}{"data": result}})
c.JSON(http.StatusCreated, responses.GenericResponse{Status: http.StatusCreated, Message: "success replaced", Data: result})
}
6 changes: 3 additions & 3 deletions responses/secret.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package responses

type GenericResponse struct {
Status int `json:"status"`
Message string `json:"message"`
Data map[string]interface{} `json:"data"`
Status int `json:"status"`
Message string `json:"message"`
Data any `json:"data"`
}

0 comments on commit 3a53da7

Please sign in to comment.