Skip to content
Draft
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
6 changes: 3 additions & 3 deletions cmd/internal-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func main() {

defer temporalClient.Close()

usersHandler := handler.NewUsers(temporalClient, *cfg)
temporalHandler := handler.SetupOnboardingTemporal(temporalClient, *cfg)

r.Route("/tenant", func(r chi.Router) {
if os.Getenv("ENABLE_JWT_AUTH") == "true" {
Expand All @@ -147,8 +147,8 @@ func main() {
r.Post("/teams", handler.CreateTeam)
r.Post("/teams/{team_id}/members/{member_id}", handler.AddMemberToTeam)
r.Post("/members", handler.CreateMember)
r.Get("/provision-github-installations/{installation_id}", temporalHandler.ProvisionGithubInstallationData)
})

r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`OK`))
})
Expand All @@ -157,7 +157,7 @@ func main() {
w.Write([]byte(`OK`))
})

r.Get("/users-count", usersHandler.UsersCount)
r.Get("/users-count", temporalHandler.UsersCount)

go func() {
log.Printf("Listening on %s\n", srv.Addr)
Expand Down
18 changes: 18 additions & 0 deletions cmd/onboarding-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ func main() {
log.Fatalln("Failed to load configuration:", err)
}

githubConfig, err := activities.LoadGithubConfig()

if err != nil {
log.Fatalln("Failed to load github configuration:", err)
}

temporalClient, err := client.Dial(client.Options{
HostPort: cfg.TemporalHostPort,
Namespace: cfg.TemporalOnboardingNamespace,
Expand All @@ -26,12 +32,19 @@ func main() {
}
defer temporalClient.Close()

err = activities.InitAppClient()

if err != nil {
log.Fatalf("Unable to init app client: %v", err)
}

err = onboarding.RegisterNamespace(
context.Background(),
cfg.TemporalHostPort,
cfg.TemporalOnboardingNamespace,
30,
)

if err != nil {
log.Fatalln("Failed to register Temporal namespace:", err)
}
Expand All @@ -41,9 +54,14 @@ func main() {
userActivities := activities.NewUserActivites(
*cfg,
)
githubActivities := activities.InitGHActivities(*githubConfig)
dbActivities := activities.InitDBActivities()

w.RegisterWorkflow(workflows.CountUsers)
w.RegisterWorkflow(workflows.ProvisionGithubInstallationData)
w.RegisterActivity(userActivities)
w.RegisterActivity(githubActivities)
w.RegisterActivity(dbActivities)

if err := w.Run(worker.InterruptCh()); err != nil {
log.Fatalln("Worker failed to start", err)
Expand Down
8 changes: 4 additions & 4 deletions db/migrations/tenant/migrations/1750420632_init.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CREATE TABLE "teams" (
"created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
"updated_at" DATETIME NOT NULL DEFAULT (datetime('now')),
"deleted_at" DATETIME DEFAULT NULL,
FOREIGN KEY ("organization_id") references "organizations" ("id")
FOREIGN KEY ("organization_id") REFERENCES "organizations" ("id")
);

CREATE TABLE "members" (
Expand All @@ -49,7 +49,7 @@ CREATE TABLE "teams__members" (

CREATE TABLE "github_organizations" (
"id" INTEGER PRIMARY KEY NOT NULL,
"external_id" INTEGER NOT NULL,
"external_id" INTEGER NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"github_app_installation_id" INTEGER NOT NULL,
"created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
Expand All @@ -69,7 +69,7 @@ CREATE TABLE "organizations__github_organizations" (

CREATE TABLE "github_members" (
"id" INTEGER PRIMARY KEY NOT NULL,
"external_id" INTEGER NOT NULL,
"external_id" INTEGER NOT NULL UNIQUE,
"username" TEXT NOT NULL,
"email" TEXT DEFAULT NULL,
"member_id" INTEGER NULL,
Expand All @@ -81,7 +81,7 @@ CREATE TABLE "github_members" (

CREATE TABLE "github_teams" (
"id" INTEGER PRIMARY KEY NOT NULL,
"external_id" INTEGER NOT NULL,
"external_id" INTEGER NOT NULL UNIQUE,
"name" TEXT NOT NULL,
"github_organization_id" INTEGER NOT NULL,
"created_at" DATETIME NOT NULL DEFAULT (datetime('now')),
Expand Down
6 changes: 3 additions & 3 deletions db/migrations/tenant/migrations/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ CREATE TABLE "organizations" ("id" INTEGER PRIMARY KEY NOT NULL, "name" TEXT NOT
CREATE TABLE "teams" ("id" INTEGER PRIMARY KEY NOT NULL, "name" TEXT NOT NULL, "organization_id" INTEGER NOT NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "updated_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "deleted_at" DATETIME DEFAULT NULL, FOREIGN KEY ("organization_id") REFERENCES "organizations" ("id"));
CREATE TABLE "members" ("id" INTEGER PRIMARY KEY NOT NULL, "name" TEXT NOT NULL, "email" TEXT DEFAULT NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "updated_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "deleted_at" DATETIME DEFAULT NULL);
CREATE TABLE "teams__members" ("team_id" INTEGER NOT NULL, "member_id" INTEGER NOT NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), PRIMARY KEY ("team_id", "member_id"), FOREIGN KEY ("team_id") REFERENCES "teams" ("id"), FOREIGN KEY ("member_id") REFERENCES "members" ("id"));
CREATE TABLE "github_organizations" ("id" INTEGER PRIMARY KEY NOT NULL, "external_id" INTEGER NOT NULL, "name" TEXT NOT NULL, "github_app_installation_id" INTEGER NOT NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "updated_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "deleted_at" DATETIME DEFAULT NULL);
CREATE TABLE "github_organizations" ("id" INTEGER PRIMARY KEY NOT NULL, "external_id" INTEGER NOT NULL UNIQUE, "name" TEXT NOT NULL, "github_app_installation_id" INTEGER NOT NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "updated_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "deleted_at" DATETIME DEFAULT NULL);
CREATE TABLE "organizations__github_organizations" ("organization_id" INTEGER NOT NULL, "github_organization_id" INTEGER NOT NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), PRIMARY KEY ("organization_id", "github_organization_id"), FOREIGN KEY ("organization_id") REFERENCES "organizations" ("id"), FOREIGN KEY ("github_organization_id") REFERENCES "github_organizations" ("id"));
CREATE TABLE "github_members" ("id" INTEGER PRIMARY KEY NOT NULL, "external_id" INTEGER NOT NULL, "username" TEXT NOT NULL, "email" TEXT DEFAULT NULL, "member_id" INTEGER NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "updated_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "deleted_at" DATETIME DEFAULT NULL, FOREIGN KEY ("member_id") REFERENCES "members" ("id"));
CREATE TABLE "github_teams" ("id" INTEGER PRIMARY KEY NOT NULL, "external_id" INTEGER NOT NULL, "name" TEXT NOT NULL, "github_organization_id" INTEGER NOT NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "updated_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "deleted_at" DATETIME DEFAULT NULL, FOREIGN KEY ("github_organization_id") REFERENCES "github_organizations" ("id"));
CREATE TABLE "github_members" ("id" INTEGER PRIMARY KEY NOT NULL, "external_id" INTEGER NOT NULL UNIQUE, "username" TEXT NOT NULL, "email" TEXT DEFAULT NULL, "member_id" INTEGER NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "updated_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "deleted_at" DATETIME DEFAULT NULL, FOREIGN KEY ("member_id") REFERENCES "members" ("id"));
CREATE TABLE "github_teams" ("id" INTEGER PRIMARY KEY NOT NULL, "external_id" INTEGER NOT NULL UNIQUE, "name" TEXT NOT NULL, "github_organization_id" INTEGER NOT NULL, "created_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "updated_at" DATETIME NOT NULL DEFAULT (datetime ('now')), "deleted_at" DATETIME DEFAULT NULL, FOREIGN KEY ("github_organization_id") REFERENCES "github_organizations" ("id"));
CREATE TABLE "github_teams__github_members" ("github_team_id" INTEGER NOT NULL, "github_member_id" INTEGER NOT NULL, PRIMARY KEY ("github_team_id", "github_member_id"), FOREIGN KEY ("github_team_id") REFERENCES "github_teams" ("id"), FOREIGN KEY ("github_member_id") REFERENCES "github_members" ("id"));
CREATE TRIGGER "settings_set_updated_at" AFTER UPDATE ON "settings" FOR EACH ROW BEGIN
UPDATE "settings" SET updated_at = datetime ('now') WHERE id = OLD.id;
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (

require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 // indirect
github.com/bradleyfalzon/ghinstallation/v2 v2.16.0 // indirect
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
Expand All @@ -28,8 +29,12 @@ require (
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gofri/go-github-ratelimit/v2 v2.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/go-github/v72 v72.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 // indirect
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/XSAM/otelsql v0.39.0/go.mod h1:uMOXLUX+wkuAuP0AR3B45NXX7E9lJS2mERa8gq
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 h1:goHVqTbFX3AIo0tzGr14pgfAW2ZfPChKO21Z9MGf/gk=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/bradleyfalzon/ghinstallation/v2 v2.16.0 h1:B91r9bHtXp/+XRgS5aZm6ZzTdz3ahgJYmkt4xZkgDz8=
github.com/bradleyfalzon/ghinstallation/v2 v2.16.0/go.mod h1:OeVe5ggFzoBnmgitZe/A+BqGOnv1DvU/0uiLQi1wutM=
github.com/cenkalti/backoff/v5 v5.0.2 h1:rIfFVxEf1QsI7E1ZHfp/B4DF/6QBAUhmgkxc0H7Zss8=
github.com/cenkalti/backoff/v5 v5.0.2/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -54,8 +56,12 @@ github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/gofri/go-github-ratelimit/v2 v2.0.2 h1:gS8wAS1jTmlWGdTjAM7KIpsLjwY1S0S/gKK5hthfSXM=
github.com/gofri/go-github-ratelimit/v2 v2.0.2/go.mod h1:YBQt4gTbdcbMjJFT05YFEaECwH78P5b0IwrnbLiHGdE=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
Expand All @@ -68,9 +74,14 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-github/v72 v72.0.0 h1:FcIO37BLoVPBO9igQQ6tStsv2asG4IPcYFi655PPvBM=
github.com/google/go-github/v72 v72.0.0/go.mod h1:WWtw8GMRiL62mvIquf1kO3onRHeWWKmK01qdCY8c5fg=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down
7 changes: 6 additions & 1 deletion internal/internal-api/data/tenantDB.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package data

import (
"context"
"database/sql"
"fmt"
"os"
Expand All @@ -12,7 +13,7 @@ type TenantDB struct {
DB *sql.DB
}

func NewTenantDB(dbUrl string) (TenantDB, error) {
func NewTenantDB(dbUrl string, ctx context.Context) (TenantDB, error) {
driverName := otel.GetDriverName()
devToken := os.Getenv("DXTA_DEV_GROUP_TOKEN")

Expand All @@ -30,6 +31,10 @@ func NewTenantDB(dbUrl string) (TenantDB, error) {
return TenantDB{}, err
}

if err := tenantDB.PingContext(ctx); err != nil {
return TenantDB{}, err
}

return TenantDB{
DB: tenantDB,
}, nil
Expand Down
9 changes: 8 additions & 1 deletion internal/internal-api/handler/add_member_to_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ type AddMemberToTeamResponse struct {
func AddMemberToTeam(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

apiState := ctx.Value(util.ApiStateCtxKey).(api.State)
authId := ctx.Value(util.AuthIdCtxKey).(string)

apiState, err := api.InternalApiState(authId, ctx)

if err != nil {
util.JSONError(w, util.ErrorParam{Error: "Internal Server Error"}, http.StatusInternalServerError)
return
}

teamId, err := strconv.ParseInt(chi.URLParam(r, "team_id"), 10, 64)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion internal/internal-api/handler/create_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ func CreateMember(w http.ResponseWriter, r *http.Request) {
util.JSONError(w, util.ErrorParam{Error: "Bad Request"}, http.StatusBadRequest)
}

apiState := ctx.Value(util.ApiStateCtxKey).(api.State)
authId := ctx.Value(util.AuthIdCtxKey).(string)

apiState, err := api.InternalApiState(authId, ctx)

if err != nil {
util.JSONError(w, util.ErrorParam{Error: "Internal Server Error"}, http.StatusInternalServerError)
return
}

newMemberRes, err := apiState.DB.CreateMember(body.Name, body.Email, ctx)

Expand Down
26 changes: 17 additions & 9 deletions internal/internal-api/handler/create_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,26 @@ func CreateTeam(w http.ResponseWriter, r *http.Request) {
return
}

organizationId := ctx.Value(util.OrganizationIdCtxKey).(int64)

if organizationId == 0 || body.TeamName == "" {
fmt.Printf(
"No organization id or team name provided. Organization id: %d Team name: %s",
organizationId,
body.TeamName,
)
if body.TeamName == "" {
fmt.Printf("No team name provided. Team name: %s", body.TeamName)
util.JSONError(w, util.ErrorParam{Error: "Bad Request"}, http.StatusBadRequest)
}

apiState := ctx.Value(util.ApiStateCtxKey).(api.State)
authId := ctx.Value(util.AuthIdCtxKey).(string)

apiState, err := api.InternalApiState(authId, ctx)

if err != nil {
util.JSONError(w, util.ErrorParam{Error: "Internal Server Error"}, http.StatusInternalServerError)
return
}

organizationId, err := apiState.DB.GetOrganizationIdByAuthId(authId, ctx)

if err != nil {
util.JSONError(w, util.ErrorParam{Error: "Bad request"}, http.StatusBadRequest)
return
}

newTeamRes, err := apiState.DB.CreateTeam(body.TeamName, organizationId, ctx)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package handler

import (
"encoding/json"
"fmt"
"net/http"
"strconv"

api "github.com/dxta-dev/app/internal/internal-api"
"github.com/dxta-dev/app/internal/onboarding/workflows"
"github.com/dxta-dev/app/internal/util"
"github.com/go-chi/chi/v5"
)

type ProvisionGithubInstallationDataResponse struct {
Message string `json:"message"`
}

func (t *OnboardingTemporal) ProvisionGithubInstallationData(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

installationId, err := strconv.ParseInt(chi.URLParam(r, "installation_id"), 10, 64)

if err != nil {
fmt.Printf("Issue while parsing installation id URL param. Error: %s", err.Error())
util.JSONError(w, util.ErrorParam{Error: "Bad Request"}, http.StatusBadRequest)
return
}

authId := ctx.Value(util.AuthIdCtxKey).(string)

tenantData, err := api.GetTenantDBUrlByAuthId(ctx, authId)

if err != nil {
util.JSONError(w, util.ErrorParam{Error: "Internal Server Error"}, http.StatusInternalServerError)
return
}

workflows.ExecuteGithubInstallationDataProvision(
ctx,
t.temporalClient,
workflows.ExecuteGithubInstallationDataProvisionParams{
TemporalOnboardingQueueName: t.config.TemporalOnboardingNamespace,
InstallationId: installationId,
AuthId: authId,
DBUrl: tenantData.DBUrl,
})

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

if err := json.NewEncoder(w).Encode(ProvisionGithubInstallationDataResponse{Message: "Success"}); err != nil {
fmt.Printf("Issue while formatting response. Error: %s", err.Error())
util.JSONError(
w,
util.ErrorParam{Error: "Internal Server Error"},
http.StatusInternalServerError,
)
return
}
}
18 changes: 18 additions & 0 deletions internal/internal-api/handler/temporal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package handler

import (
"github.com/dxta-dev/app/internal/onboarding"
"go.temporal.io/sdk/client"
)

type OnboardingTemporal struct {
temporalClient client.Client
config onboarding.Config
}

func SetupOnboardingTemporal(temporalClient client.Client, config onboarding.Config) *OnboardingTemporal {
return &OnboardingTemporal{
temporalClient: temporalClient,
config: config,
}
}
18 changes: 2 additions & 16 deletions internal/internal-api/handler/users_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,16 @@ import (
"log"
"net/http"

"github.com/dxta-dev/app/internal/onboarding"
"github.com/dxta-dev/app/internal/onboarding/workflows"
"github.com/dxta-dev/app/internal/util"
"go.temporal.io/sdk/client"
)

type UsersCountResponse struct {
Count int `json:"count"`
}

type Users struct {
temporalClient client.Client
config onboarding.Config
}

func NewUsers(temporalClient client.Client, config onboarding.Config) *Users {
return &Users{
temporalClient: temporalClient,
config: config,
}
}

func (u *Users) UsersCount(w http.ResponseWriter, r *http.Request) {
out, err := workflows.ExecuteCountUsersWorkflow(r.Context(), u.temporalClient, u.config)
func (t OnboardingTemporal) UsersCount(w http.ResponseWriter, r *http.Request) {
out, err := workflows.ExecuteCountUsersWorkflow(r.Context(), t.temporalClient, t.config)
if err != nil {
log.Fatal(errors.Unwrap(err))
}
Expand Down
Loading