Skip to content

Commit

Permalink
Add API method for deleting a database.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-osman committed Aug 4, 2022
1 parent 6205c70 commit 203a9a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions status/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func (s *Status) apiContainersState(c *gin.Context) {

func (s *Status) apiDbDatabases(c *gin.Context) {
var (
name = c.Param("name")
db = c.Param("db")
)
d, err := s.dbman.Get(name)
d, err := s.dbman.Get(db)
if err != nil {
failure(c, http.StatusBadRequest, errInvalidDatabase)
return
Expand All @@ -115,6 +115,23 @@ func (s *Status) apiDbDatabases(c *gin.Context) {
c.JSON(http.StatusOK, l)
}

func (s *Status) apiDbDatabasesDelete(c *gin.Context) {
var (
db = c.Param("db")
name = c.Param("name")
)
d, err := s.dbman.Get(db)
if err != nil {
failure(c, http.StatusBadRequest, errInvalidDatabase)
return
}
if err := d.DeleteDatabase(name); err != nil {
failure(c, http.StatusInternalServerError, err.Error())
return
}
success(c)
}

func (s *Status) webSocket(c *gin.Context) {
if err := s.logger.AddClient(c.Writer, c.Request); err != nil {
// TODO: not sure if we can return a response here since we don't know
Expand Down
3 changes: 2 additions & 1 deletion status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func New(cfg *Config) *Status {
api.GET("/status", s.apiStatus)
api.GET("/containers", s.apiContainers)
api.POST("/containers/:id/state", s.apiContainersState)
api.GET("/db/:name/databases", s.apiDbDatabases)
api.GET("/db/:db/databases", s.apiDbDatabases)
api.DELETE("/db/:db/databases/:name", s.apiDbDatabasesDelete)
api.GET("/ws", s.webSocket)
}
r.NoRoute(func(c *gin.Context) {
Expand Down

0 comments on commit 203a9a9

Please sign in to comment.