-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from natrontech/momentum-model
add momentum model
- Loading branch information
Showing
15 changed files
with
938 additions
and
380 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
momentum-backend/momentum-core/momentum-config/db-consts.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
momentum-backend/momentum-core/momentum-model/application.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package momentummodel | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/pocketbase/pocketbase/models" | ||
) | ||
|
||
const TABLE_APPLICATIONS_NAME = "applications" | ||
const TABLE_APPLICATIONS_FIELD_ID = "id" | ||
const TABLE_APPLICATIONS_FIELD_NAME = "name" | ||
const TABLE_APPLICATIONS_FIELD_STAGES = "stages" | ||
const TABLE_APPLICATIONS_FIELD_HELMREPO = "helmRepository" | ||
const TABLE_APPLICATIONS_FIELD_PARENTREPOSITORY = "parentRepository" | ||
|
||
type IApplication interface { | ||
IModel | ||
|
||
Name() string | ||
SetName(string) | ||
|
||
ParentRepositoryId() string | ||
SetParentRepositoryId(string) | ||
|
||
StageIds() []string | ||
SetStageIds([]string) | ||
|
||
HelmRepositoryUrl() string | ||
SetHelmRepositoryUrl(string) | ||
} | ||
|
||
type Application struct { | ||
IApplication | ||
|
||
name string | ||
parentRepositoryId string | ||
stageIds []string | ||
helmRepositoryUrl string | ||
} | ||
|
||
func ToApplication(record *models.Record) (IApplication, error) { | ||
|
||
if record.TableName() != TABLE_APPLICATIONS_NAME { | ||
return nil, errors.New("unallowed record type") | ||
} | ||
|
||
app := new(Application) | ||
app.SetId(record.Id) | ||
app.name = record.GetString(TABLE_APPLICATIONS_FIELD_NAME) | ||
app.stageIds = record.Get(TABLE_APPLICATIONS_FIELD_STAGES).([]string) | ||
app.helmRepositoryUrl = record.GetString(TABLE_APPLICATIONS_FIELD_HELMREPO) | ||
app.parentRepositoryId = record.GetString(TABLE_APPLICATIONS_FIELD_PARENTREPOSITORY) | ||
|
||
return app, nil | ||
} | ||
|
||
func ToApplicationRecord(app IApplication, recordInstance *models.Record) (*models.Record, error) { | ||
|
||
if recordInstance.TableName() != TABLE_APPLICATIONS_NAME { | ||
return nil, errors.New("unallowed record type") | ||
} | ||
|
||
recordInstance.Set(TABLE_APPLICATIONS_FIELD_NAME, app.Name()) | ||
recordInstance.Set(TABLE_APPLICATIONS_FIELD_STAGES, app.StageIds()) | ||
recordInstance.Set(TABLE_APPLICATIONS_FIELD_HELMREPO, app.HelmRepositoryUrl()) | ||
recordInstance.Set(TABLE_APPLICATIONS_FIELD_PARENTREPOSITORY, app.ParentRepositoryId()) | ||
|
||
return recordInstance, nil | ||
} | ||
|
||
func (a *Application) Name() string { | ||
return a.name | ||
} | ||
|
||
func (a *Application) SetName(name string) { | ||
a.name = name | ||
} | ||
|
||
func (a *Application) ParentRepositoryId() string { | ||
return a.parentRepositoryId | ||
} | ||
|
||
func (a *Application) SetParentRepositoryId(parentRepositoryId string) { | ||
a.parentRepositoryId = parentRepositoryId | ||
} | ||
|
||
func (a *Application) StageIds() []string { | ||
return a.stageIds | ||
} | ||
|
||
func (a *Application) SetStageIds(stageIds []string) { | ||
a.stageIds = stageIds | ||
} | ||
|
||
func (a *Application) HelmRepositoryUrl() string { | ||
return a.helmRepositoryUrl | ||
} | ||
|
||
func (a *Application) SetHelmRepositoryUrl(helmRepositoryUrl string) { | ||
a.helmRepositoryUrl = helmRepositoryUrl | ||
} |
116 changes: 116 additions & 0 deletions
116
momentum-backend/momentum-core/momentum-model/deployment.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package momentummodel | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/pocketbase/pocketbase/models" | ||
) | ||
|
||
const TABLE_DEPLOYMENTS_NAME = "deployments" | ||
const TABLE_DEPLOYMENTS_FIELD_ID = "id" | ||
const TABLE_DEPLOYMENTS_FIELD_NAME = "name" | ||
const TABLE_DEPLOYMENTS_FIELD_DESCRIPTION = "description" | ||
const TABLE_DEPLOYMENTS_FIELD_REPOSITORIES = "repositories" | ||
const TABLE_DEPLOYMENTS_FIELD_KEYVALUES = "keyValues" | ||
const TABLE_DEPLOYMENTS_FIELD_PARENTSTAGE = "parentStage" | ||
|
||
type IDeployment interface { | ||
IModel | ||
|
||
Name() string | ||
SetName(string) | ||
|
||
Description() string | ||
SetDescription(string) | ||
|
||
ParentStageId() string | ||
SetParentStageId(string) | ||
|
||
KeyValueIds() []string | ||
SetKeyValueIds([]string) | ||
|
||
RepositoryIds() []string | ||
SetRepositoryIds([]string) | ||
} | ||
|
||
type Deployment struct { | ||
IDeployment | ||
|
||
name string | ||
description string | ||
parentStageId string | ||
keyValueIds []string | ||
repositoryIds []string | ||
} | ||
|
||
func ToDeployment(record *models.Record) (IDeployment, error) { | ||
|
||
if record.TableName() != TABLE_DEPLOYMENTS_NAME { | ||
return nil, errors.New("unallowed record type") | ||
} | ||
|
||
dep := new(Deployment) | ||
dep.SetId(record.Id) | ||
dep.name = record.GetString(TABLE_APPLICATIONS_FIELD_NAME) | ||
dep.description = record.GetString(TABLE_DEPLOYMENTS_FIELD_DESCRIPTION) | ||
dep.parentStageId = record.GetString(TABLE_DEPLOYMENTS_FIELD_PARENTSTAGE) | ||
dep.keyValueIds = record.Get(TABLE_DEPLOYMENTS_FIELD_KEYVALUES).([]string) | ||
dep.repositoryIds = record.Get(TABLE_DEPLOYMENTS_FIELD_REPOSITORIES).([]string) | ||
|
||
return dep, nil | ||
} | ||
|
||
func ToDeploymentRecord(dep IDeployment, recordInstance *models.Record) (*models.Record, error) { | ||
|
||
if recordInstance.TableName() != TABLE_DEPLOYMENTS_NAME { | ||
return nil, errors.New("unallowed record type") | ||
} | ||
|
||
recordInstance.Set(TABLE_DEPLOYMENTS_FIELD_NAME, dep.Name()) | ||
recordInstance.Set(TABLE_DEPLOYMENTS_FIELD_DESCRIPTION, dep.Description()) | ||
recordInstance.Set(TABLE_DEPLOYMENTS_FIELD_REPOSITORIES, dep.RepositoryIds()) | ||
recordInstance.Set(TABLE_DEPLOYMENTS_FIELD_KEYVALUES, dep.KeyValueIds()) | ||
recordInstance.Set(TABLE_DEPLOYMENTS_FIELD_PARENTSTAGE, dep.ParentStageId()) | ||
|
||
return recordInstance, nil | ||
} | ||
|
||
func (d *Deployment) Name() string { | ||
return d.name | ||
} | ||
|
||
func (d *Deployment) SetName(name string) { | ||
d.name = name | ||
} | ||
|
||
func (d *Deployment) Description() string { | ||
return d.description | ||
} | ||
|
||
func (d *Deployment) SetDescription(description string) { | ||
d.description = description | ||
} | ||
|
||
func (d *Deployment) ParentStageId() string { | ||
return d.parentStageId | ||
} | ||
|
||
func (d *Deployment) SetParentStageId(parentStageId string) { | ||
d.parentStageId = parentStageId | ||
} | ||
|
||
func (d *Deployment) KeyValueIds() []string { | ||
return d.keyValueIds | ||
} | ||
|
||
func (d *Deployment) SetKeyValueIds(keyValueIds []string) { | ||
d.keyValueIds = keyValueIds | ||
} | ||
|
||
func (d *Deployment) RepositoryIds() []string { | ||
return d.repositoryIds | ||
} | ||
|
||
func (d *Deployment) SetRepositoryIds(repositoryIds []string) { | ||
d.repositoryIds = repositoryIds | ||
} |
Oops, something went wrong.