Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualize charts with data from integrations #156

Merged
merged 28 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/[email protected]
with:
go-version: ^1.23
go-version: ^1.24
id: go

- name: Check out code
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.23 AS build-env
FROM golang:1.24 AS build-env
WORKDIR /go/malak

LABEL org.opencontainers.image.description="Open source Investors' relationship hub for Founders"
Expand Down
2 changes: 2 additions & 0 deletions cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func addHTTPCommand(c *cobra.Command, cfg *config.Config) {
shareRepo := postgres.NewShareRepository(db)
preferenceRepo := postgres.NewPreferenceRepository(db)
integrationRepo := postgres.NewIntegrationRepo(db)
dashRepo := postgres.NewDashboardRepo(db)

googleAuthProvider := socialauth.NewGoogle(*cfg)

Expand Down Expand Up @@ -274,6 +275,7 @@ func addHTTPCommand(c *cobra.Command, cfg *config.Config) {
srv, cleanupSrv := server.New(logger,
util.DeRef(cfg), db,
tokenManager, googleAuthProvider,
dashRepo,
userRepo, workspaceRepo, planRepo, contactRepo,
updateRepo, contactlistRepo, deckRepo, shareRepo,
preferenceRepo, integrationRepo, mid, gulterHandler,
Expand Down
69 changes: 66 additions & 3 deletions dashboard.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,71 @@
package malak

import "github.com/google/uuid"
import (
"context"
"time"

"github.com/google/uuid"
"github.com/uptrace/bun"
)

var (
ErrDashboardNotFound = MalakError("dashboard not found")
)

type Dashboard struct {
ID uuid.UUID `json:"id,omitempty"`
Reference Reference `json:"reference,omitempty"`
ID uuid.UUID `bun:"type:uuid,default:uuid_generate_v4(),pk" json:"id,omitempty"`
Reference Reference `json:"reference,omitempty"`
Description string `json:"description,omitempty"`
Title string `json:"title,omitempty"`
WorkspaceID uuid.UUID `json:"workspace_id,omitempty"`

ChartCount int64 `json:"chart_count,omitempty"`

CreatedAt time.Time `json:"created_at,omitempty" bun:",default:current_timestamp"`
UpdatedAt time.Time `json:"updated_at,omitempty" bun:",default:current_timestamp"`

DeletedAt *time.Time `bun:",soft_delete,nullzero" json:"-,omitempty"`

bun.BaseModel `json:"-"`
}

type DashboardChart struct {
ID uuid.UUID `bun:"type:uuid,default:uuid_generate_v4(),pk" json:"id,omitempty"`
WorkspaceIntegrationID uuid.UUID `json:"workspace_integration_id,omitempty"`
Reference Reference `json:"reference,omitempty"`
WorkspaceID uuid.UUID `json:"workspace_id,omitempty"`
DashboardID uuid.UUID `json:"dashboard_id,omitempty"`

ChartID uuid.UUID `json:"chart_id,omitempty"`
IntegrationChart *IntegrationChart `json:"chart,omitempty" bun:"rel:belongs-to,join:chart_id=id"`

CreatedAt time.Time `json:"created_at,omitempty" bun:",default:current_timestamp"`
UpdatedAt time.Time `json:"updated_at,omitempty" bun:",default:current_timestamp"`

DeletedAt *time.Time `bun:",soft_delete,nullzero" json:"-,omitempty"`

bun.BaseModel `json:"-"`
}

type ListDashboardOptions struct {
Paginator Paginator
WorkspaceID uuid.UUID
}

type FetchDashboardOption struct {
WorkspaceID uuid.UUID
Reference Reference
}

type FetchDashboardChartsOption struct {
WorkspaceID uuid.UUID
DashboardID uuid.UUID
}

type DashboardRepository interface {
Create(context.Context, *Dashboard) error
Get(context.Context, FetchDashboardOption) (Dashboard, error)
AddChart(context.Context, *DashboardChart) error
List(context.Context, ListDashboardOptions) ([]Dashboard, int64, error)
GetCharts(context.Context, FetchDashboardChartsOption) ([]DashboardChart, error)
}
40 changes: 20 additions & 20 deletions dev/otel-collector.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
receivers:
prometheus:
config:
scrape_configs:
- job_name: "bundler"
scrape_interval: 10s
static_configs:
- targets: ["host.docker.internal:4337"]
basic_auth:
username: malak
password: malak
prometheus:
config:
scrape_configs:
- job_name: "bundler"
scrape_interval: 10s
static_configs:
- targets: ["host.docker.internal:4337"]
basic_auth:
username: malak
password: malak

processors:
batch:
batch:

exporters:
otlp:
endpoint: "otel:4317"
tls:
insecure: true
otlp:
endpoint: "otel:4317"
tls:
insecure: true

service:
pipelines:
metrics:
receivers: [prometheus]
processors: [batch]
exporters: [otlp]
pipelines:
metrics:
receivers: [prometheus]
processors: [batch]
exporters: [otlp]
1 change: 1 addition & 0 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ package malak
//go:generate mockgen -source=internal/pkg/billing/billing.go -destination=mocks/billing.go -package=malak_mocks
//go:generate mockgen -source=internal/secret/secret.go -destination=mocks/secret.go -package=malak_mocks
//go:generate mockgen -source=integration.go -destination=mocks/integration.go -package=malak_mocks
//go:generate mockgen -source=dashboard.go -destination=mocks/dashboard.go -package=malak_mocks
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ayinke-llc/malak

go 1.23.1
go 1.24.0

require (
github.com/ThreeDotsLabs/watermill v1.3.7
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ github.com/ThreeDotsLabs/watermill v1.3.7 h1:NV0PSTmuACVEOV4dMxRnmGXrmbz8U83LENO
github.com/ThreeDotsLabs/watermill v1.3.7/go.mod h1:lBnrLbxOjeMRgcJbv+UiZr8Ylz8RkJ4m6i/VN/Nk+to=
github.com/ThreeDotsLabs/watermill-redisstream v1.4.2 h1:FY6tsBcbhbJpKDOssU4bfybstqY0hQHwiZmVq9qyILQ=
github.com/ThreeDotsLabs/watermill-redisstream v1.4.2/go.mod h1:69++855LyB+ckYDe60PiJLBcUrpckfDE2WwyzuVJRCk=
github.com/adelowo/gulter v0.0.0-20250118125244-ee5e3db48073 h1:wFakW12hAz7xQa6cLWruPTeIPPdn3fZ8OxcD7P+6r7k=
github.com/adelowo/gulter v0.0.0-20250118125244-ee5e3db48073/go.mod h1:emNdddTD8yk9NjprSHOXGqgMGk0Tj7j69gG8zyywv2M=
github.com/adelowo/gulter v0.0.0-20250212151604-30b84bd42d8d h1:q4UZxiHpxvoy/GTXb+Oa7Jodl7uCHoH7xOrpjDLa3Q4=
github.com/adelowo/gulter v0.0.0-20250212151604-30b84bd42d8d/go.mod h1:emNdddTD8yk9NjprSHOXGqgMGk0Tj7j69gG8zyywv2M=
github.com/adelowo/gulter v0.0.0-20250212164855-be5012c5f635 h1:AMWTMYnpT/svarHQYlelgdHTYdN9pCkT6FwEflaNk60=
github.com/adelowo/gulter v0.0.0-20250212164855-be5012c5f635/go.mod h1:emNdddTD8yk9NjprSHOXGqgMGk0Tj7j69gG8zyywv2M=
github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
Expand Down Expand Up @@ -659,8 +655,6 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
16 changes: 16 additions & 0 deletions integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

var (
ErrWorkspaceIntegrationNotFound = MalakError("integration not found")
ErrChartNotFound = MalakError("chart not found")
)

// ENUM(oauth2,api_key)
Expand All @@ -22,6 +23,12 @@ type IntegrationProvider string
// ENUM(mercury_account,mercury_account_transaction,brex_account,brex_account_transaction)
type IntegrationChartInternalNameType string

// ENUM(bar,pie)
type IntegrationChartType string

// ENUM(daily,monthly)
type IntegrationChartFrequencyType uint8

type IntegrationMetadata struct {
Endpoint string `json:"endpoint,omitempty"`
}
Expand Down Expand Up @@ -107,6 +114,7 @@ type IntegrationChart struct {
UserFacingName string `json:"user_facing_name,omitempty"`
InternalName IntegrationChartInternalNameType `json:"internal_name,omitempty"`
Metadata IntegrationChartMetadata `json:"metadata,omitempty"`
ChartType IntegrationChartType `json:"chart_type,omitempty"`

CreatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp" json:"created_at,omitempty"`
UpdatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp" json:"updated_at,omitempty"`
Expand All @@ -131,6 +139,7 @@ type IntegrationChartValues struct {
InternalName IntegrationChartInternalNameType
UserFacingName string
ProviderID string
ChartType IntegrationChartType
}

type IntegrationFetchDataOptions struct {
Expand Down Expand Up @@ -161,6 +170,11 @@ type FindWorkspaceIntegrationOptions struct {
ID uuid.UUID
}

type FetchChartOptions struct {
WorkspaceID uuid.UUID
Reference Reference
}

type IntegrationRepository interface {
Create(context.Context, *Integration) error
System(context.Context) ([]Integration, error)
Expand All @@ -172,4 +186,6 @@ type IntegrationRepository interface {

CreateCharts(context.Context, *WorkspaceIntegration, []IntegrationChartValues) error
AddDataPoint(context.Context, *WorkspaceIntegration, []IntegrationDataValues) error
ListCharts(context.Context, uuid.UUID) ([]IntegrationChart, error)
GetChart(context.Context, FetchChartOptions) (IntegrationChart, error)
}
78 changes: 78 additions & 0 deletions integration_enum.go

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

Loading
Loading