| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package api
- import (
- "encoding/json"
- "net/http"
- "strconv"
- "github.com/go-chi/chi"
- "github.com/porter-dev/porter/internal/models"
- )
- // HandleListProjectInfra returns a list of infrasa for a project
- func (app *App) HandleListProjectInfra(w http.ResponseWriter, r *http.Request) {
- projID, err := strconv.ParseUint(chi.URLParam(r, "project_id"), 0, 64)
- if err != nil || projID == 0 {
- app.handleErrorFormDecoding(err, ErrProjectDecode, w)
- return
- }
- infras, err := app.Repo.Infra().ListInfrasByProjectID(uint(projID))
- if err != nil {
- app.handleErrorRead(err, ErrProjectDataRead, w)
- return
- }
- extInfras := make([]*models.InfraExternal, 0)
- for _, infra := range infras {
- extInfras = append(extInfras, infra.Externalize())
- }
- w.WriteHeader(http.StatusOK)
- if err := json.NewEncoder(w).Encode(extInfras); err != nil {
- app.handleErrorFormDecoding(err, ErrProjectDecode, w)
- return
- }
- }
|