-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #519 from USACE/feature/cwbi-dev-offices
Office endpoint
- Loading branch information
Showing
5 changed files
with
81 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/USACE/cumulus-api/api/models" | ||
"github.com/jackc/pgx/v4/pgxpool" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// ListOffices returns a list of all parameters | ||
func ListOffices(db *pgxpool.Pool) echo.HandlerFunc { | ||
return func(c echo.Context) error { | ||
oo, err := models.ListOffices(db) | ||
if err != nil { | ||
return c.String(http.StatusInternalServerError, err.Error()) | ||
} | ||
return c.JSON(http.StatusOK, oo) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package models | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/georgysavva/scany/pgxscan" | ||
"github.com/google/uuid" | ||
"github.com/jackc/pgx/v4/pgxpool" | ||
) | ||
|
||
type Office struct { | ||
ID uuid.UUID `json:"id"` | ||
Symbol string `json:"symbol"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func ListOffices(db *pgxpool.Pool) ([]Office, error) { | ||
sql := ` | ||
SELECT | ||
o.id | ||
, o.symbol | ||
, o.name | ||
FROM | ||
office o | ||
` | ||
var oo []Office | ||
err = pgxscan.Select(context.TODO(), db, &oo, sql) | ||
return oo, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters