diff --git a/handlers/pallidsturgeonhandler.go b/handlers/pallidsturgeonhandler.go index a32554d..8d43b1e 100644 --- a/handlers/pallidsturgeonhandler.go +++ b/handlers/pallidsturgeonhandler.go @@ -191,11 +191,17 @@ func (sd *PallidSturgeonHandler) GetYears(c echo.Context) error { } func (sd *PallidSturgeonHandler) GetHeaderData(c echo.Context) error { - siteId := c.QueryParam("siteId") - headerDataItems, err := sd.Store.GetHeaderData(siteId) + siteId, office, year, project := c.QueryParam("siteId"), c.QueryParam("office"), c.QueryParam("year"), c.QueryParam("project") + + headerDataItems, err := sd.Store.GetHeaderData(year, siteId, office, project) if err != nil { - return c.JSON(http.StatusInternalServerError, err.Error()) + return c.JSON(http.StatusBadRequest, &models.Response{ + Message: err.Error(), + Status: "Failed", + Data: nil, + }) } + return c.JSON(http.StatusOK, headerDataItems) } diff --git a/models/auth.go b/models/auth.go index 0c0c5f8..05a289a 100644 --- a/models/auth.go +++ b/models/auth.go @@ -70,7 +70,9 @@ type KeyCloakRole struct { } type Response struct { - Message string `json:"message"` + Message string `json:"message"` + Status string `json:"status"` + Data []string `json:"data"` } type Jwks struct { diff --git a/models/pallidsturgeon.go b/models/pallidsturgeon.go index f20e720..f4de6f4 100644 --- a/models/pallidsturgeon.go +++ b/models/pallidsturgeon.go @@ -121,16 +121,16 @@ type Year struct { } type HeaderData struct { - SiteId int `db:"site_id" json:"siteId"` - Year int `db:"year" json:"year"` - FieldOffice string `db:"fieldoffice" json:"fieldoffice"` - Project int `db:"project_id" json:"project"` - Segment int `db:"segment_id" json:"segment"` - Season string `db:"season" json:"season"` - Bend int `db:"bend" json:"bend"` - Bendrn string `db:"bendrn" json:"bendrn"` - BendRiverMile float64 `db:"bendrivermile" json:"bendrivermile"` - SampleUnitType string `db:"sample_unit_type" json:"sampleUnitType"` + SiteId int `db:"site_id" json:"siteId"` + Year int `db:"year" json:"year"` + FieldOffice string `db:"fieldoffice" json:"fieldoffice"` + Project int `db:"project_id" json:"project"` + Segment int `db:"segment_id" json:"segment"` + Season string `db:"season" json:"season"` + Bend int `db:"bend" json:"bend"` + Bendrn string `db:"bendrn" json:"bendrn"` + BendRiverMile *float64 `db:"bendrivermile" json:"bendrivermile"` + SampleUnitType string `db:"sample_unit_type" json:"sampleUnitType"` } type FishSummaryWithCount struct { diff --git a/stores/pallidsturgeonstore.go b/stores/pallidsturgeonstore.go index 6a24806..e22401f 100644 --- a/stores/pallidsturgeonstore.go +++ b/stores/pallidsturgeonstore.go @@ -541,14 +541,12 @@ func (s *PallidSturgeonStore) GetYears() ([]models.Year, error) { } var headerDataSql = `select si.site_id, si.year, si.fieldoffice, si.project_id, si.segment_id, si.season, si.bend, -si.bendrn, si.sample_unit_type, COALESCE(mo.bendrivermile,0.0) as bendrivermile from ds_sites si -inner join ds_moriver mo on si.site_id = mo.site_id -where si.site_id=:1 -group by si.site_id, si.year, si.fieldoffice, si.project_id, si.segment_id, si.season, si.bend, -si.bendrn, si.sample_unit_type, mo.bendrivermile` - -func (s *PallidSturgeonStore) GetHeaderData(siteId string) ([]models.HeaderData, error) { - rows, err := s.db.Query(headerDataSql, siteId) +si.bendrn, si.sample_unit_type, fnc.bend_river_mile from ds_sites si +join table (pallid_data_entry_api.data_entry_site_fnc(:1,:2,:3,null,null,null)) fnc on si.site_id = fnc.site_id +where fnc.site_id=:4` + +func (s *PallidSturgeonStore) GetHeaderData(year string, siteId string, office string, project string) ([]models.HeaderData, error) { + rows, err := s.db.Query(headerDataSql, year, office, project, siteId) headerDataItems := []models.HeaderData{} if err != nil {