Skip to content

Commit

Permalink
remove db-consts.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel-Haeberli committed Jun 20, 2023
1 parent b211dc0 commit d3c8c92
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 115 deletions.
51 changes: 0 additions & 51 deletions momentum-backend/momentum-core/momentum-config/db-consts.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
gitclient "momentum/git-client"
kustomizeclient "momentum/kustomize-client"
config "momentum/momentum-core/momentum-config"
model "momentum/momentum-core/momentum-model"
services "momentum/momentum-core/momentum-services"
tree "momentum/momentum-core/momentum-tree"
utils "momentum/momentum-core/momentum-utils"
Expand Down Expand Up @@ -47,8 +48,8 @@ func NewRepositoryController(

func (rc *RepositoryController) AddRepository(record *models.Record, conf *config.MomentumConfig) error {

repoName := record.GetString(config.TABLE_REPOSITORIES_FIELD_NAME)
repoUrl := record.GetString(config.TABLE_REPOSITORIES_FIELD_URL)
repoName := record.GetString(model.TABLE_REPOSITORIES_FIELD_NAME)
repoUrl := record.GetString(model.TABLE_REPOSITORIES_FIELD_URL)
path := utils.BuildPath(conf.DataDir(), strings.ReplaceAll(repoName, " ", ""))

fmt.Println("adding repo", repoName, ", located at", repoUrl, "and to be written to", path)
Expand Down
27 changes: 14 additions & 13 deletions momentum-backend/momentum-core/momentum-dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
kustomizeclient "momentum/kustomize-client"
conf "momentum/momentum-core/momentum-config"
controllers "momentum/momentum-core/momentum-controllers"
model "momentum/momentum-core/momentum-model"
services "momentum/momentum-core/momentum-services"

"github.com/pocketbase/pocketbase"
Expand Down Expand Up @@ -110,34 +111,34 @@ func (d *MomentumDispatcher) DispatchDelete(recordEvent *core.RecordDeleteEvent)

func (d *MomentumDispatcher) setupCreateRules() []*MomentumDispatcherRule {
return []*MomentumDispatcherRule{
{conf.TABLE_REPOSITORIES_NAME, d.RepositoryController.AddRepository},
{conf.TABLE_APPLICATIONS_NAME, d.ApplicationsController.AddApplication},
{conf.TABLE_STAGES_NAME, d.StagesController.AddStage},
{conf.TABLE_DEPLOYMENTS_NAME, d.DeploymentController.AddDeployment},
{model.TABLE_REPOSITORIES_NAME, d.RepositoryController.AddRepository},
{model.TABLE_APPLICATIONS_NAME, d.ApplicationsController.AddApplication},
{model.TABLE_STAGES_NAME, d.StagesController.AddStage},
{model.TABLE_DEPLOYMENTS_NAME, d.DeploymentController.AddDeployment},
}
}

func (d *MomentumDispatcher) setupUpdateRules() []*MomentumDispatcherRule {
return []*MomentumDispatcherRule{
{conf.TABLE_REPOSITORIES_NAME, d.RepositoryController.UpdateRepository},
{conf.TABLE_APPLICATIONS_NAME, d.ApplicationsController.UpdateApplication},
{conf.TABLE_STAGES_NAME, d.StagesController.UpdateStage},
{conf.TABLE_DEPLOYMENTS_NAME, d.DeploymentController.UpdateDeployment},
{model.TABLE_REPOSITORIES_NAME, d.RepositoryController.UpdateRepository},
{model.TABLE_APPLICATIONS_NAME, d.ApplicationsController.UpdateApplication},
{model.TABLE_STAGES_NAME, d.StagesController.UpdateStage},
{model.TABLE_DEPLOYMENTS_NAME, d.DeploymentController.UpdateDeployment},
}
}

func (d *MomentumDispatcher) setupDeleteRules() []*MomentumDispatcherRule {
return []*MomentumDispatcherRule{
{conf.TABLE_REPOSITORIES_NAME, d.RepositoryController.DeleteRepository},
{conf.TABLE_APPLICATIONS_NAME, d.ApplicationsController.DeleteApplication},
{conf.TABLE_STAGES_NAME, d.StagesController.DeleteStage},
{conf.TABLE_DEPLOYMENTS_NAME, d.DeploymentController.DeleteDeployment},
{model.TABLE_REPOSITORIES_NAME, d.RepositoryController.DeleteRepository},
{model.TABLE_APPLICATIONS_NAME, d.ApplicationsController.DeleteApplication},
{model.TABLE_STAGES_NAME, d.StagesController.DeleteStage},
{model.TABLE_DEPLOYMENTS_NAME, d.DeploymentController.DeleteDeployment},
}
}

func (d *MomentumDispatcher) setupRepositoryAddedEventChannelObserver() {

d.Pocketbase.OnRecordAfterCreateRequest(conf.TABLE_REPOSITORIES_NAME).Add(func(e *core.RecordCreateEvent) error {
d.Pocketbase.OnRecordAfterCreateRequest(model.TABLE_REPOSITORIES_NAME).Add(func(e *core.RecordCreateEvent) error {

event := <-REPOSITORY_ADDED_EVENT_CHANNEL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package momentumservices

import (
"errors"
consts "momentum/momentum-core/momentum-config"
model "momentum/momentum-core/momentum-model"

"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/models"
Expand All @@ -28,13 +28,13 @@ func NewApplicationService(dao *daos.Dao, stageService *StageService) *Applicati

func (as *ApplicationService) AddRepository(repositoryRecord *models.Record, applications []*models.Record) error {

if repositoryRecord.Collection().Name != consts.TABLE_REPOSITORIES_NAME {
if repositoryRecord.Collection().Name != model.TABLE_REPOSITORIES_NAME {
return errors.New("repositoryRecord is not record of repositories collection")
}

for _, app := range applications {

app.Set(consts.TABLE_APPLICATIONS_FIELD_PARENTREPOSITORY, repositoryRecord.Id)
app.Set(model.TABLE_APPLICATIONS_FIELD_PARENTREPOSITORY, repositoryRecord.Id)
err := as.saveWithoutEvent(app)
if err != nil {
return err
Expand All @@ -46,7 +46,7 @@ func (as *ApplicationService) AddRepository(repositoryRecord *models.Record, app

func (as *ApplicationService) GetApplicationCollection() (*models.Collection, error) {

return as.dao.FindCollectionByNameOrId(consts.TABLE_APPLICATIONS_NAME)
return as.dao.FindCollectionByNameOrId(model.TABLE_APPLICATIONS_NAME)
}

func (as *ApplicationService) createWithoutEvent(name string, stageIds []string) (*models.Record, error) {
Expand All @@ -57,8 +57,8 @@ func (as *ApplicationService) createWithoutEvent(name string, stageIds []string)
}

appRecord := models.NewRecord(appCollection)
appRecord.Set(consts.TABLE_APPLICATIONS_FIELD_NAME, name)
appRecord.Set(consts.TABLE_APPLICATIONS_FIELD_STAGES, stageIds)
appRecord.Set(model.TABLE_APPLICATIONS_FIELD_NAME, name)
appRecord.Set(model.TABLE_APPLICATIONS_FIELD_STAGES, stageIds)

return appRecord, as.saveWithoutEvent(appRecord)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package momentumservices

import (
"errors"
consts "momentum/momentum-core/momentum-config"
model "momentum/momentum-core/momentum-model"

"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/models"
Expand All @@ -29,12 +29,12 @@ func NewDeploymentService(dao *daos.Dao, keyValueService *KeyValueService) *Depl

func (ds *DeploymentService) AddParentStage(stage *models.Record, deployments []*models.Record) error {

if stage.Collection().Name != consts.TABLE_STAGES_NAME {
if stage.Collection().Name != model.TABLE_STAGES_NAME {
return errors.New("stage is not record of stages collection")
}

for _, deployment := range deployments {
deployment.Set(consts.TABLE_DEPLOYMENTS_FIELD_PARENTSTAGE, stage.Id)
deployment.Set(model.TABLE_DEPLOYMENTS_FIELD_PARENTSTAGE, stage.Id)
err := ds.saveWithoutEvent(deployment)
if err != nil {
return err
Expand All @@ -46,13 +46,13 @@ func (ds *DeploymentService) AddParentStage(stage *models.Record, deployments []

func (ds *DeploymentService) AddRepository(repositoryRecord *models.Record, deployments []*models.Record) error {

if repositoryRecord.Collection().Name != consts.TABLE_REPOSITORIES_NAME {
if repositoryRecord.Collection().Name != model.TABLE_REPOSITORIES_NAME {
return errors.New("repositoryRecord is not record of repositories collection")
}

for _, depl := range deployments {

depl.Set(consts.TABLE_DEPLOYMENTS_FIELD_REPOSITORIES, append(depl.Get(consts.TABLE_DEPLOYMENTS_FIELD_REPOSITORIES).([]string), repositoryRecord.Id))
depl.Set(model.TABLE_DEPLOYMENTS_FIELD_REPOSITORIES, append(depl.Get(model.TABLE_DEPLOYMENTS_FIELD_REPOSITORIES).([]string), repositoryRecord.Id))
err := ds.saveWithoutEvent(depl)
if err != nil {
return err
Expand All @@ -64,7 +64,7 @@ func (ds *DeploymentService) AddRepository(repositoryRecord *models.Record, depl

func (ds *DeploymentService) GetDeploymentsCollection() (*models.Collection, error) {

coll, err := ds.dao.FindCollectionByNameOrId(consts.TABLE_DEPLOYMENTS_NAME)
coll, err := ds.dao.FindCollectionByNameOrId(model.TABLE_DEPLOYMENTS_NAME)
if err != nil {
return nil, err
}
Expand All @@ -80,7 +80,7 @@ func (ds *DeploymentService) createWithoutEvent(name string) (*models.Record, er
}

deploymentRecord := models.NewRecord(deploymentCollection)
deploymentRecord.Set(consts.TABLE_DEPLOYMENTS_FIELD_NAME, name)
deploymentRecord.Set(model.TABLE_DEPLOYMENTS_FIELD_NAME, name)

err = ds.saveWithoutEvent(deploymentRecord)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package momentumservices

import (
consts "momentum/momentum-core/momentum-config"
model "momentum/momentum-core/momentum-model"

"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/models"
Expand All @@ -26,7 +26,7 @@ func NewKeyValueService(dao *daos.Dao) *KeyValueService {

func (kvs *KeyValueService) GetKeyValueCollection() (*models.Collection, error) {

coll, err := kvs.dao.FindCollectionByNameOrId(consts.TABLE_KEYVALUE_NAME)
coll, err := kvs.dao.FindCollectionByNameOrId(model.TABLE_KEYVALUE_NAME)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package momentumservices

import (
"fmt"
consts "momentum/momentum-core/momentum-config"
model "momentum/momentum-core/momentum-model"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
Expand Down Expand Up @@ -31,7 +31,7 @@ func NewRepositoryService(dao *daos.Dao, appService *ApplicationService) *Reposi

func (rs *RepositoryService) FindForName(name string) (*models.Record, error) {

recs, err := rs.dao.FindRecordsByExpr(consts.TABLE_REPOSITORIES_NAME, dbx.NewExp(consts.TABLE_REPOSITORIES_FIELD_NAME+" = {:"+consts.TABLE_REPOSITORIES_FIELD_NAME+"}", dbx.Params{consts.TABLE_REPOSITORIES_FIELD_NAME: name}))
recs, err := rs.dao.FindRecordsByExpr(model.TABLE_REPOSITORIES_NAME, dbx.NewExp(model.TABLE_REPOSITORIES_FIELD_NAME+" = {:"+model.TABLE_REPOSITORIES_FIELD_NAME+"}", dbx.Params{model.TABLE_REPOSITORIES_FIELD_NAME: name}))
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit d3c8c92

Please sign in to comment.