Skip to content

Commit

Permalink
Mostly just pull latest djangolang + subsequent changes
Browse files Browse the repository at this point in the history
  • Loading branch information
initialed85 committed Aug 9, 2024
1 parent 791b5fc commit e8c6776
Show file tree
Hide file tree
Showing 14 changed files with 2,354 additions and 705 deletions.
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ fi

# introspect the database and generate the Djangolang API
# note: the environment variables are coupled to the environment described in docker-compose.yaml
echo -e "\generating the api..."
DJANGOLANG_PACKAGE_NAME=api POSTGRES_DB=camry POSTGRES_PASSWORD=NoNVR!11 djangolang template
echo -e "\ngenerating the api..."
DJANGOLANG_API_ROOT=/api DJANGOLANG_PACKAGE_NAME=api POSTGRES_DB=camry POSTGRES_PASSWORD=NoNVR!11 djangolang template

# dump out the OpenAPI v3 schema for the Djangolang API
mkdir -p ./schema
./pkg/api/bin/api dump-openapi-json >./schema/openapi.json
DJANGOLANG_API_ROOT=/api ./pkg/api/bin/api dump-openapi-json >./schema/openapi.json

# generate the client for use by the frontend
echo -e "\ngenerating typescript client..."
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ services:
image: swaggerapi/swagger-ui:v5.4.2
environment:
- "BASE_URL=/"
- "SWAGGER_JSON_URL=http://host.docker.internal:7070/openapi.json"
- "SWAGGER_JSON_URL=http://host.docker.internal:7070/api/openapi.json"
ports:
- "7071:8080"
294 changes: 195 additions & 99 deletions frontend/src/api/api.d.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions frontend/src/components/CameraToggleButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export default function CameraToggleButtonGroup(
) {
const [value, setValue] = useState<string | null>();

const { data, error } = useQuery("get", "/cameras", {
const { data, error } = useQuery("get", "/api/cameras", {
params: {
query: {
order_by__asc: "name",
name__asc: "",
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/VideoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export interface VideoTableProps {
}

export function VideoTable(props: VideoTableProps) {
const { data, error, isLoading } = useQuery("get", "/videos", {
const { data, error, isLoading } = useQuery("get", "/api/videos", {
params: {
query: {
order_by__desc: "started_at",
started_at__desc: "",
camera_id__eq: props.cameraId || undefined,
started_at__gte: props.date
? `${props.date}T00:00:00+08:00`
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ require (
github.com/go-chi/chi/v5 v5.1.0
github.com/gomodule/redigo v1.9.2
github.com/google/uuid v1.6.0
github.com/initialed85/djangolang v0.0.18
github.com/initialed85/djangolang v0.0.21
github.com/jackc/pgtype v1.14.3
github.com/jackc/pgx/v5 v5.6.0
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
github.com/oapi-codegen/runtime v1.1.1
github.com/paulmach/orb v0.11.1
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
gopkg.in/yaml.v2 v2.4.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/initialed85/djangolang v0.0.18 h1:nUg9ptZOGtr5QS4o8qn9OOn1AzkLBNnUQuhyj6tr5G0=
github.com/initialed85/djangolang v0.0.18/go.mod h1:3mqaFDBq9zfX/18jyDCHs5UpH2r5XGgBj/SlRcgfY64=
github.com/initialed85/djangolang v0.0.21 h1:Fsv9tvNnQnGcXY0hl241av/Myndj73sacN4ngSsPkv0=
github.com/initialed85/djangolang v0.0.21/go.mod h1:3mqaFDBq9zfX/18jyDCHs5UpH2r5XGgBj/SlRcgfY64=
github.com/initialed85/structmeta v0.0.0-20240802152142-39f398ef1ab7 h1:G9Z1k4TyxQ/9Kk4ZSuw82WZCxJayZf12Aos2MorzKRg=
github.com/initialed85/structmeta v0.0.0-20240802152142-39f398ef1ab7/go.mod h1:hTGWTsfgy6Um+L8e3Qcj8/pBkHGcIGxEpZAKziWhQfc=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
Expand Down Expand Up @@ -277,8 +277,8 @@ golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDf
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/0_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

var mu = new(sync.Mutex)
var newFromItemFnByTableName = make(map[string]func(map[string]any) (any, error))
var getRouterFnByPattern = make(map[string]func(*sqlx.DB, *redis.Pool, []server.HTTPMiddleware, []server.ModelMiddleware) chi.Router)
var getRouterFnByPattern = make(map[string]server.GetRouterFn)
var allObjects = make([]any, 0)
var openApi *types.OpenAPI

Expand All @@ -28,7 +28,7 @@ func register(
object any,
newFromItem func(map[string]any) (any, error),
pattern string,
getRouterFn func(*sqlx.DB, *redis.Pool, []server.HTTPMiddleware, []server.ModelMiddleware) chi.Router,
getRouterFn server.GetRouterFn,
) {
allObjects = append(allObjects, object)
newFromItemFnByTableName[tableName] = newFromItem
Expand Down Expand Up @@ -68,7 +68,7 @@ func NewFromItem(tableName string, item map[string]any) (any, error) {
return newFromItemFn(item)
}

func GetRouter(db *sqlx.DB, redisPool *redis.Pool, httpMiddlewares []server.HTTPMiddleware, modelMiddlewares []server.ModelMiddleware) chi.Router {
func GetRouter(db *sqlx.DB, redisPool *redis.Pool, httpMiddlewares []server.HTTPMiddleware, objectMiddlewares []server.ObjectMiddleware, waitForChange server.WaitForChange) chi.Router {
r := chi.NewRouter()

for _, m := range httpMiddlewares {
Expand All @@ -77,7 +77,7 @@ func GetRouter(db *sqlx.DB, redisPool *redis.Pool, httpMiddlewares []server.HTTP

mu.Lock()
for pattern, getRouterFn := range getRouterFnByPattern {
r.Mount(pattern, getRouterFn(db, redisPool, httpMiddlewares, modelMiddlewares))
r.Mount(pattern, getRouterFn(db, redisPool, httpMiddlewares, objectMiddlewares, waitForChange))
}
mu.Unlock()

Expand Down Expand Up @@ -127,7 +127,7 @@ func RunServer(
db *sqlx.DB,
redisPool *redis.Pool,
httpMiddlewares []server.HTTPMiddleware,
modelMiddlewares []server.ModelMiddleware,
objectMiddlewares []server.ObjectMiddleware,
) error {
return server.RunServer(ctx, changes, addr, NewFromItem, GetRouter, db, redisPool, httpMiddlewares, modelMiddlewares)
return server.RunServer(ctx, changes, addr, NewFromItem, GetRouter, db, redisPool, httpMiddlewares, objectMiddlewares)
}
Binary file modified pkg/api/bin/api
Binary file not shown.
Loading

0 comments on commit e8c6776

Please sign in to comment.