-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Antoine Popineau
committed
Jan 16, 2025
1 parent
9f2e035
commit 8bc794e
Showing
8 changed files
with
206 additions
and
46 deletions.
There are no files selected for viewing
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
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,27 @@ | ||
package dbmodels | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/checkmarble/marble-backend/models" | ||
"github.com/checkmarble/marble-backend/utils" | ||
) | ||
|
||
const TABLE_SANCTION_CHECK_CONFIGS = "sanction_check_configs" | ||
|
||
type DBSanctionCheckConfigs struct { | ||
Id string `db:"id"` | ||
ScenarioIterationId string `db:"scenario_iteration_id"` | ||
Enabled bool `db:"enabled"` | ||
UpdatedAt time.Time `db:"updated_at"` | ||
} | ||
|
||
var SanctionCheckConfigColumnList = utils.ColumnList[DBSanctionCheckConfigs]() | ||
|
||
func AdaptSanctionCheckConfig(db DBSanctionCheckConfigs) (models.SanctionCheckConfig, error) { | ||
scc := models.SanctionCheckConfig{ | ||
Enabled: db.Enabled, | ||
} | ||
|
||
return scc, nil | ||
} |
22 changes: 22 additions & 0 deletions
22
repositories/migrations/20250115140500_add_sanction_check_config.sql
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,22 @@ | ||
-- +goose Up | ||
-- +goose StatementBegin | ||
|
||
create table sanction_check_configs ( | ||
id uuid primary key default uuid_generate_v4(), | ||
scenario_iteration_id uuid unique, | ||
enabled boolean, | ||
updated_at timestamp with time zone not null default CURRENT_TIMESTAMP, | ||
|
||
constraint fk_scneario_iteration | ||
foreign key (scenario_iteration_id) | ||
references scenario_iterations (id) | ||
); | ||
|
||
-- +goose StatementEnd | ||
|
||
-- +goose Down | ||
-- +goose StatementBegin | ||
|
||
drop table sanction_check_configs; | ||
|
||
-- +goose StatementEnd |
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,35 @@ | ||
package repositories | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/Masterminds/squirrel" | ||
"github.com/checkmarble/marble-backend/models" | ||
"github.com/checkmarble/marble-backend/repositories/dbmodels" | ||
) | ||
|
||
func (repo *MarbleDbRepository) GetSanctionCheckConfig(ctx context.Context, exec Executor, | ||
scenarioIterationId string, | ||
) (models.SanctionCheckConfig, error) { | ||
sql := NewQueryBuilder(). | ||
Select("*").From(dbmodels.TABLE_SANCTION_CHECK_CONFIGS). | ||
Where(squirrel.Eq{"scenario_iteration_id": scenarioIterationId}) | ||
|
||
return SqlToModel(ctx, exec, sql, dbmodels.AdaptSanctionCheckConfig) | ||
} | ||
|
||
func (repo *MarbleDbRepository) UpdateSanctionCheckConfig(ctx context.Context, exec Executor, | ||
scenarioIterationId string, sanctionCheckConfig models.SanctionCheckConfig, | ||
) (models.SanctionCheckConfig, error) { | ||
sql := NewQueryBuilder(). | ||
Insert(dbmodels.TABLE_SANCTION_CHECK_CONFIGS). | ||
Columns("scenario_iteration_id", "enabled"). | ||
Values(scenarioIterationId, sanctionCheckConfig.Enabled). | ||
Suffix("ON CONFLICT (scenario_iteration_id) DO UPDATE"). | ||
Suffix("SET enabled = EXCLUDED.enabled, updated_at = NOW()"). | ||
Suffix(fmt.Sprintf("RETURNING %s", strings.Join(dbmodels.SanctionCheckConfigColumnList, ","))) | ||
|
||
return SqlToModel(ctx, exec, sql, dbmodels.AdaptSanctionCheckConfig) | ||
} |
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,16 @@ | ||
package usecases | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/checkmarble/marble-backend/models" | ||
"github.com/checkmarble/marble-backend/repositories" | ||
) | ||
|
||
type SanctionCheckConfigRepository interface { | ||
GetSanctionCheckConfig(ctx context.Context, exec repositories.Executor, scenarioIterationId string) (models.SanctionCheckConfig, error) | ||
UpdateSanctionCheckConfig(ctx context.Context, exec repositories.Executor, | ||
scenarioIterationId string, sanctionCheckConfig models.SanctionCheckConfig) (models.SanctionCheckConfig, error) | ||
} | ||
|
||
// TODO: Will we have a usecase for sanction checks? |
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