github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/api/jobserver/list.go (about)

     1  package jobserver
     2  
     3  import (
     4  	"encoding/json"
     5  	"net/http"
     6  
     7  	"github.com/pf-qiu/concourse/v6/atc"
     8  	"github.com/pf-qiu/concourse/v6/atc/db"
     9  )
    10  
    11  func (s *Server) ListJobs(pipeline db.Pipeline) http.Handler {
    12  	logger := s.logger.Session("list-jobs")
    13  
    14  	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    15  		jobs, err := pipeline.Dashboard()
    16  		if err != nil {
    17  			logger.Error("failed-to-get-dashboard", err)
    18  			w.WriteHeader(http.StatusInternalServerError)
    19  			return
    20  		}
    21  
    22  		if jobs == nil {
    23  			jobs = []atc.JobSummary{}
    24  		}
    25  
    26  		w.Header().Set("Content-Type", "application/json")
    27  		w.WriteHeader(http.StatusOK)
    28  
    29  		err = json.NewEncoder(w).Encode(jobs)
    30  		if err != nil {
    31  			logger.Error("failed-to-encode-jobs", err)
    32  			w.WriteHeader(http.StatusInternalServerError)
    33  		}
    34  	})
    35  }