Skip to content

Commit

Permalink
Merge pull request #519 from USACE/feature/cwbi-dev-offices
Browse files Browse the repository at this point in the history
Office endpoint
  • Loading branch information
jeffsuperglide authored Jan 15, 2025
2 parents 469c2a5 + fc538ce commit 7ba4f34
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
20 changes: 20 additions & 0 deletions api/handlers/office.go
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)
}
}
3 changes: 3 additions & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ func main() {
middleware.IsAdmin,
)

// Offices
public.GET("/offices", handlers.ListOffices(db))

// Products
public.GET("/product_ingest_status", handlers.GetProductIngestStatus(db))
public.GET("/product_slugs", handlers.GetProductSlugs(db))
Expand Down
29 changes: 29 additions & 0 deletions api/models/offices.go
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
}
27 changes: 25 additions & 2 deletions tests/cumulus-regression-admin.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"info": {
"_postman_id": "2273ceeb-3854-4c0b-bc24-e07eb7329e6e",
"_postman_id": "228e75eb-16e8-4f3e-9329-a47c43723725",
"name": "cumulus-regression-admin",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "13201855"
},
"item": [
{
Expand Down Expand Up @@ -2329,6 +2330,28 @@
"response": []
}
]
},
{
"name": "offices",
"item": [
{
"name": "Get Offices",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{base_url}}/offices",
"host": [
"{{base_url}}"
],
"path": [
"offices"
]
}
},
"response": []
}
]
}
],
"auth": {
Expand Down
8 changes: 4 additions & 4 deletions tests/postman_environment.local.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "14dd346f-5e5e-4e32-b924-fe72a5fb5451",
"id": "8de33252-1929-4feb-810a-841ca8e1349e",
"name": "Local",
"values": [
{
"key": "base_url",
"value": "http://localhost",
"value": "http://localhost/api",
"enabled": true
},
{
Expand All @@ -29,6 +29,6 @@
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2021-05-25T20:38:00.299Z",
"_postman_exported_using": "Postman/7.27.1"
"_postman_exported_at": "2025-01-14T16:32:42.912Z",
"_postman_exported_using": "Postman/11.23.3"
}

0 comments on commit 7ba4f34

Please sign in to comment.