Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
42 changes: 42 additions & 0 deletions ddpui/api/admin_portal/organizations_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from ninja import Router
from django.http import Http404
from ddpui.models.org import Org

admin_org_router = Router()


@admin_org_router.get("/v1/organizations")
@admin_org_router.get("/v1/organizations/")
def get_admin_organizations(request, name: str = None):
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
"""
List organizations with optional filtering
"""
queryset = Org.objects.all()

if name:
queryset = queryset.filter(name__icontains=name)

orgs = queryset.values("id", "name", "slug")

return {
"success": True,
"count": queryset.count(),
"data": list(orgs)
}


@admin_org_router.get("/v1/organizations/{org_id}")
@admin_org_router.get("/v1/organizations/{org_id}/")
def get_single_org(request, org_id: int):
"""
Get single organization by ID
"""
org = Org.objects.filter(id=org_id).values("id", "name", "slug").first()

if not org:
raise Http404("Organization not found")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

return {
"success": True,
"data": org
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
5 changes: 3 additions & 2 deletions ddpui/migrations/0085_syncstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class Migration(migrations.Migration):
("connection_id", models.CharField(max_length=36)),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
("attempt", models.IntegerField(default=0)),
("status", models.TextField()),
(
(
"sync_type",
models.CharField(
choices=[("manual", "manual"), ("orchestrate", "orchestrate")]
max_length=20,
choices=[("manual", "manual"), ("orchestrate", "orchestrate")],
),
),
("sync_time", models.DateTimeField()),
Expand Down
14 changes: 10 additions & 4 deletions ddpui/models/airbyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ class SyncStats(models.Model):
"""single table to track connection sync stats"""

org = models.ForeignKey(Org, on_delete=models.CASCADE)
connection_id = models.CharField(max_length=36)
connection_id = models.CharField(max_length=50)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
job_id = models.IntegerField(null=True)
attempt = models.IntegerField(default=0)
status = models.TextField()
sync_type = models.CharField(choices=[("manual", "manual"), ("orchestrate", "orchestrate")])

# ✅ FIXED LINE (added max_length)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
sync_type = models.CharField(
max_length=20,
choices=[("manual", "manual"), ("orchestrate", "orchestrate")]
)

sync_time = models.DateTimeField()
sync_duration_s = models.BigIntegerField(default=0)
sync_records = models.BigIntegerField(default=0)
Expand Down Expand Up @@ -66,7 +72,7 @@ class AirbyteJob(models.Model):
started_at = models.DateTimeField(null=True) # because the api spec says this will be optional
ended_at = models.DateTimeField(
null=True
) # when the job ended; can be null if we pull or sync an ongonig job
) # when the job ended; can be null if we pull or sync an ongoing job
created_at = models.DateTimeField() # when the job was created in airbyte
updated_at = models.DateTimeField(auto_now=True) # when the django record was last updated

Expand Down Expand Up @@ -109,4 +115,4 @@ def latest_failed_attempt_id(self):
if failed_attempts:
return max(failed_attempts, key=lambda x: x["id"])["id"]

return None
return None
7 changes: 3 additions & 4 deletions ddpui/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
from ddpui.api.filter_api import filter_router
from ddpui.api.public_api import public_router
from ddpui.api.report_api import report_router

from ddpui.api.admin_portal.organizations_api import admin_org_router

src_api = NinjaAPI(
urls_namespace="api",
title="Dalgo backend apis",
description="Open source ELT orchestrator",
docs_url="/api/docs",
# auth=auth.CustomAuthMiddleware(),
auth=auth.CustomJwtAuthMiddleware(),
auth=auth.CustomJwtAuthMiddleware()
)


Expand Down Expand Up @@ -108,7 +107,7 @@ def ninja_default_error_handler(
src_api.add_router("/api/dashboards/", dashboard_native_router)
src_api.add_router("/api/filters/", filter_router)
src_api.add_router("/api/reports/", report_router)

src_api.add_router("/api/admin/", admin_org_router)
# Public API without authentication
public_api = NinjaAPI(
urls_namespace="public-api",
Expand Down