Skip to content

Commit

Permalink
feat(*): add endpoint to fetch application remote
Browse files Browse the repository at this point in the history
  • Loading branch information
yashre-bh committed Mar 25, 2023
1 parent 4d268bf commit a03e079
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions services/master/controllers/application.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controllers

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"strconv"
Expand Down Expand Up @@ -303,3 +305,24 @@ func FetchMetrics(c *gin.Context) {
"data": metricsRecord,
})
}

func FetchAppRemote (c *gin.Context) {
appName := c.Param("app")
config, err := mongo.FetchSingleApp(appName)
if err != nil {
c.AbortWithStatusJSON(400, gin.H{
"success": false,
"error": err.Error(),
})
}

response := &types.ApplicationRemote{
GitURL: config.Git.RepoURL,
}

fmt.Println(response)

responseBody := new(bytes.Buffer)
json.NewEncoder(responseBody).Encode(response)
c.Data(200, "application/json", responseBody.Bytes())
}
1 change: 1 addition & 0 deletions services/master/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func NewService() http.Handler {
app.PATCH("/:app/transfer/:user", m.IsAppOwner, c.TransferApplicationOwnership)
app.GET("/:app/term", m.IsAppOwner, c.DeployWebTerminal)
app.GET("/:app/metrics", m.IsAppOwner, c.FetchMetrics)
app.GET("/:app/remote", m.IsAppOwner, c.FetchAppRemote)
}

db := router.Group("/dbs")
Expand Down
4 changes: 4 additions & 0 deletions types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ type ApplicationConfig struct {
Success bool `json:"success,omitempty" bson:"-"`
}

type ApplicationRemote struct {
GitURL string `json:"giturl" bson:"giturl"`
}

// GetName returns the application's name
func (app *ApplicationConfig) GetName() string {
return app.Name
Expand Down

0 comments on commit a03e079

Please sign in to comment.