Skip to content

Commit

Permalink
Merge pull request #1422 from Azanul/develop
Browse files Browse the repository at this point in the history
fix: uninitialized controller and repo
  • Loading branch information
Azanul authored May 16, 2024
2 parents b95420c + 25cb058 commit 5a75b9a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
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)
}

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

0 comments on commit 5a75b9a

Please sign in to comment.