exists.go 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package slack_integration
  2. import (
  3. "github.com/porter-dev/porter/api/server/shared/apierrors"
  4. "net/http"
  5. "github.com/porter-dev/porter/api/server/handlers"
  6. "github.com/porter-dev/porter/api/server/shared/config"
  7. "github.com/porter-dev/porter/api/types"
  8. "github.com/porter-dev/porter/internal/models"
  9. )
  10. type SlackIntegrationExists struct {
  11. handlers.PorterHandler
  12. }
  13. func NewSlackIntegrationExists(
  14. config *config.Config,
  15. ) *SlackIntegrationExists {
  16. return &SlackIntegrationExists{
  17. PorterHandler: handlers.NewDefaultPorterHandler(config, nil, nil),
  18. }
  19. }
  20. func (p *SlackIntegrationExists) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  21. project, _ := r.Context().Value(types.ProjectScope).(*models.Project)
  22. slackInts, err := p.Repo().SlackIntegration().ListSlackIntegrationsByProjectID(project.ID)
  23. if err != nil {
  24. p.HandleAPIError(w, r, apierrors.NewErrInternal(err))
  25. return
  26. }
  27. if len(slackInts) != 0 {
  28. w.WriteHeader(http.StatusOK)
  29. } else {
  30. w.WriteHeader(http.StatusNotFound)
  31. }
  32. }