Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions cmd/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"gin-api-1/internal/projects"
"gin-api-1/internal/subscriptions"
"gin-api-1/internal/tasks"
"gin-api-1/internal/users"
"gin-api-1/internal/websocket"
"gin-api-1/internal/workspace"
"gin-api-1/internal/workspacemembers"
Expand Down Expand Up @@ -55,6 +56,9 @@ func (app *application) routes() http.Handler {
dashboardService := dashboard.NewDashboardService(repo.New(app.db))
dashboardHandler := dashboard.NewDashboardHandler(dashboardService)

usersService := users.NewUsersService(repo.New(app.db), app.db)
usersHandler := users.NewUsersHandler(usersService)

/* Public routes */
v1 := r.Group("/api/v1")
{
Expand All @@ -78,6 +82,9 @@ func (app *application) routes() http.Handler {
{
authGroup.GET("/auth/me", authHandler.GetMe)

/* Users routes */
authGroup.GET("/users", usersHandler.GetUsers)

/* Dashboard routes */
authGroup.GET("/dashboard/kpis", dashboardHandler.GetKPIs)

Expand Down Expand Up @@ -108,6 +115,7 @@ func (app *application) routes() http.Handler {
authGroup.POST("/projects/:projectID/integrations/github", integrationsHandler.ConnectRepository)
authGroup.GET("/projects/:projectID/integrations/github", integrationsHandler.GetProjectIntegration)
authGroup.POST("/projects/:projectID/integrations/github/regenerate-secret", integrationsHandler.RegenerateSecret)
authGroup.GET("/projects/:projectID/integration-tasks", integrationsHandler.GetProjectIntegrationTasks)

/* Tasks routes */
authGroup.POST("/projects/:projectID/tasks", tasksHandler.CreateTask)
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ services:
interval: 10s
timeout: 5s
retries: 5
app:
build:
context: .
dockerfile: Dockerfile
container_name: gin-api-app
restart: unless-stopped
env_file:
- .env
environment:
GOOSE_DBSTRING: host=postgres user=${DATABASE_USERNAME} password=${DATABASE_PASSWORD} dbname=${DATABASE_NAME} sslmode=disable
ports:
- "${PORT:-3700}:${PORT:-3700}"
depends_on:
postgres:
condition: service_healthy
volumes:
postgres_data:
redis_data:
4 changes: 4 additions & 0 deletions internal/adapters/postgresql/sqlc/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 72 additions & 13 deletions internal/adapters/postgresql/sqlc/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@ FROM workspaces
WHERE user_id = $1
AND id = $2;

-- name: GetAccessibleWorkspaceByID :one
SELECT w.id, w.workspace_name, w.description, w.user_id, w.created_at, w.updated_at
FROM workspaces w
WHERE w.id = $1
AND (w.user_id = $2
OR EXISTS (SELECT 1
FROM workspace_members wm
WHERE wm.workspace_id = w.id
AND wm.user_id = $2));

-- name: GetUserWorkspaces :many
SELECT count(*) OVER () AS total_count, id,
workspace_name,
description,
user_id,
created_at,
updated_at
FROM workspaces
WHERE user_id = $1
ORDER BY created_at DESC LIMIT $2
SELECT count(*) OVER () AS total_count, w.id,
w.workspace_name,
w.description,
w.user_id,
w.created_at,
w.updated_at
FROM workspaces w
WHERE w.user_id = $1
OR EXISTS (SELECT 1
FROM workspace_members wm
WHERE wm.workspace_id = w.id
AND wm.user_id = $1)
ORDER BY w.created_at DESC LIMIT $2
OFFSET $3;

-- name: CreateWorkspace :one
Expand Down Expand Up @@ -242,6 +256,11 @@ FROM subscriptions
WHERE user_id = $1
AND status = 'ACTIVE' LIMIT 1;

-- name: GetProjectIntegration :one
SELECT *
FROM project_integrations
WHERE project_id = $1;

-- name: CreateIntegrationTask :one
INSERT INTO integration_tasks (id,
provider,
Expand Down Expand Up @@ -296,10 +315,50 @@ SET status = $3
WHERE external_id = $1
AND project_id = $2 RETURNING *;

-- name: GetProjectIntegrationTasks :many
SELECT count(*) OVER () AS total_count, id,
provider,
resource_type,
external_id,
repository_name,
issue_number,
title,
description,
status,
assignee_id,
payload,
project_id,
created_at,
updated_at
FROM integration_tasks
WHERE project_id = $1
ORDER BY created_at DESC LIMIT $2
OFFSET $3;

-- name: GetUsers :many
SELECT count(*) OVER () AS total_count,
id,
first_name,
last_name,
email,
created_at,
updated_at
FROM users
WHERE id <> sqlc.arg(excluded_user_id)
AND (first_name ILIKE '%' || sqlc.arg(search) || '%'
OR last_name ILIKE '%' || sqlc.arg(search) || '%'
OR email ILIKE '%' || sqlc.arg(search) || '%')
ORDER BY created_at DESC
LIMIT sqlc.arg(page_limit) OFFSET sqlc.arg(page_offset);

-- name: GetUserKPIs :one
WITH user_workspaces AS (SELECT id
FROM workspaces
WHERE user_id = $1)
WITH user_workspaces AS (SELECT w.id
FROM workspaces w
WHERE w.user_id = $1
OR EXISTS (SELECT 1
FROM workspace_members wm
WHERE wm.workspace_id = w.id
AND wm.user_id = $1))
SELECT (SELECT COUNT(*) FROM user_workspaces) AS total_workspaces,
(SELECT COUNT(DISTINCT p.id)
FROM projects p
Expand All @@ -314,4 +373,4 @@ SELECT (SELECT COUNT(*) FROM user_workspaces) AS total_workspaces,
(SELECT COUNT(DISTINCT wm.user_id)
FROM workspace_members wm
JOIN workspaces w ON w.id = wm.workspace_id
WHERE w.user_id = $1) AS team_members;
WHERE w.id IN (SELECT id FROM user_workspaces)) AS team_members;
Loading
Loading