Skip to content

Commit

Permalink
dataheader bendrivermile bugfix (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
jguevarra authored Apr 23, 2024
1 parent 07554c8 commit c0034c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
12 changes: 9 additions & 3 deletions handlers/pallidsturgeonhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion models/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions models/pallidsturgeon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 6 additions & 8 deletions stores/pallidsturgeonstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c0034c5

Please sign in to comment.