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

fix: uninitialized controller and repo #1422

Merged
merged 3 commits into from
May 16, 2024
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
4 changes: 1 addition & 3 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package controller
import (
"context"
"database/sql"

"github.com/tailwarden/komiser/repository"
)

type totalOutput struct {
Expand Down Expand Up @@ -32,7 +30,7 @@ type accountOutput struct {
}

type Repository interface {
HandleQuery(context.Context, repository.QueryType, interface{}, [][3]string) (sql.Result, error)
HandleQuery(context.Context, string, interface{}, [][3]string) (sql.Result, error)
Azanul marked this conversation as resolved.
Show resolved Hide resolved
}

type Controller struct {
Expand Down
10 changes: 10 additions & 0 deletions handlers/resources_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/tailwarden/komiser/controller"
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/repository/postgres"
"github.com/tailwarden/komiser/repository/sqlite"
"github.com/tailwarden/komiser/utils"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect"
Expand All @@ -29,8 +31,16 @@ type ApiHandler struct {
}

func NewApiHandler(ctx context.Context, telemetry bool, analytics utils.Analytics, db *bun.DB, cfg models.Config, configPath string, accounts []models.Account) *ApiHandler {
var repo controller.Repository
if db.Dialect().Name() == dialect.SQLite {
repo = sqlite.NewRepository(db)
} else {
repo = postgres.NewRepository(db)
}

handler := ApiHandler{
db: db,
ctrl: controller.New(repo),
ctx: ctx,
telemetry: telemetry,
cfg: cfg,
Expand Down
7 changes: 4 additions & 3 deletions repository/postgres/postgres.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sql
package postgres

import (
"context"
Expand All @@ -9,11 +9,12 @@ import (
)

type Repository struct {
db *bun.DB
db *bun.DB
queries map[string]repository.Object
}

func NewRepository(db *bun.DB) *Repository {
return &Repository{db: db}
return &Repository{db: db, queries: Queries}
}

var Queries = map[string]repository.Object{
Expand Down
2 changes: 1 addition & 1 deletion repository/sqlite/sqlite.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sql
package sqlite

import (
"context"
Expand Down
Loading