- 
                Notifications
    You must be signed in to change notification settings 
- Fork 18
feat(screening_monitoring): add configuration part #1274
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
          
     Open
      
      
            OrriMandarin
  wants to merge
  11
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
leoji/mar-1325-create-monitoring-screening-configuration
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +1,390
        
        
          −101
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      efac852
              
                feat(screening_monitoring): add ftm and datamodel map
              
              
                OrriMandarin d51bff1
              
                remove some property and entity
              
              
                OrriMandarin 152164d
              
                fix: unit test
              
              
                OrriMandarin de91f71
              
                feat(screening_monitoring): Remove update constraint
              
              
                OrriMandarin 334054e
              
                feat(screening_monitoring): add configuration part
              
              
                OrriMandarin abb243b
              
                Update repositories/screening_monitoring_repository.go
              
              
                OrriMandarin 7534705
              
                Update repositories/screening_monitoring_repository.go
              
              
                OrriMandarin b9fcec1
              
                Update repositories/screening_monitoring_repository.go
              
              
                OrriMandarin 59f0b8d
              
                add missing validation on DTO
              
              
                OrriMandarin 1a4fa46
              
                Update dto/screening_monitoring_config.go
              
              
                OrriMandarin f0011f2
              
                chore: remove TODO comment
              
              
                OrriMandarin File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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,118 @@ | ||
| package api | ||
|  | ||
| import ( | ||
| "net/http" | ||
|  | ||
| "github.com/checkmarble/marble-backend/dto" | ||
| "github.com/checkmarble/marble-backend/models" | ||
| "github.com/checkmarble/marble-backend/pure_utils" | ||
| "github.com/checkmarble/marble-backend/usecases" | ||
| "github.com/checkmarble/marble-backend/utils" | ||
| "github.com/cockroachdb/errors" | ||
| "github.com/gin-gonic/gin" | ||
| "github.com/google/uuid" | ||
| ) | ||
|  | ||
| func handleGetScreeningMonitoringConfig(uc usecases.Usecases) func(c *gin.Context) { | ||
| return func(c *gin.Context) { | ||
| ctx := c.Request.Context() | ||
| configId, err := uuid.Parse(c.Param("config_id")) | ||
| if err != nil { | ||
| presentError(ctx, c, errors.Wrap(models.BadParameterError, err.Error())) | ||
| return | ||
| } | ||
|  | ||
| uc := usecasesWithCreds(ctx, uc).NewScreeningMonitoringUsecase() | ||
| screeningMonitoringConfig, err := uc.GetScreeningMonitoringConfig(ctx, configId) | ||
| if presentError(ctx, c, err) { | ||
| return | ||
| } | ||
|  | ||
| c.JSON(http.StatusOK, dto.AdaptScreeningMonitoringConfigDto(screeningMonitoringConfig)) | ||
| } | ||
| } | ||
|  | ||
| func handleListScreeningMonitoringConfigs(uc usecases.Usecases) func(c *gin.Context) { | ||
| return func(c *gin.Context) { | ||
| ctx := c.Request.Context() | ||
| organizationId, err := utils.OrganizationIdFromRequest(c.Request) | ||
| if presentError(ctx, c, err) { | ||
| return | ||
| } | ||
|  | ||
| uc := usecasesWithCreds(ctx, uc).NewScreeningMonitoringUsecase() | ||
| screeningMonitoringConfigs, err := uc.GetScreeningMonitoringConfigsByOrgId(ctx, organizationId) | ||
| if presentError(ctx, c, err) { | ||
| return | ||
| } | ||
|  | ||
| c.JSON(http.StatusOK, pure_utils.Map(screeningMonitoringConfigs, dto.AdaptScreeningMonitoringConfigDto)) | ||
| } | ||
| } | ||
|  | ||
| func handleCreateScreeningMonitoringConfig(uc usecases.Usecases) func(c *gin.Context) { | ||
| return func(c *gin.Context) { | ||
| ctx := c.Request.Context() | ||
| organizationId, err := utils.OrganizationIdFromRequest(c.Request) | ||
| if presentError(ctx, c, err) { | ||
| return | ||
| } | ||
|  | ||
| var input dto.CreateScreeningMonitoringConfigDto | ||
| if err := c.ShouldBindJSON(&input); err != nil { | ||
| presentError(ctx, c, errors.Wrap(models.BadParameterError, err.Error())) | ||
| return | ||
| } | ||
|  | ||
| if err := input.Validate(); err != nil { | ||
| presentError(ctx, c, errors.Wrap(models.BadParameterError, err.Error())) | ||
| return | ||
| } | ||
|  | ||
| createScreeningMonitoringConfigInput := | ||
| dto.AdaptCreateScreeningMonitoringConfigDtoToModel(input) | ||
| createScreeningMonitoringConfigInput.OrgId = organizationId | ||
|  | ||
| uc := usecasesWithCreds(ctx, uc).NewScreeningMonitoringUsecase() | ||
| screeningMonitoringConfig, err := uc.CreateScreeningMonitoringConfig(ctx, createScreeningMonitoringConfigInput) | ||
| if presentError(ctx, c, err) { | ||
| return | ||
| } | ||
|  | ||
| c.JSON(http.StatusCreated, dto.AdaptScreeningMonitoringConfigDto(screeningMonitoringConfig)) | ||
| } | ||
| } | ||
|  | ||
| func handleUpdateScreeningMonitoringConfig(uc usecases.Usecases) func(c *gin.Context) { | ||
| return func(c *gin.Context) { | ||
| ctx := c.Request.Context() | ||
|  | ||
| configId, err := uuid.Parse(c.Param("config_id")) | ||
| if err != nil { | ||
| presentError(ctx, c, errors.Wrap(models.BadParameterError, err.Error())) | ||
| return | ||
| } | ||
|  | ||
| var input dto.UpdateScreeningMonitoringConfigDto | ||
| if err := c.ShouldBindJSON(&input); err != nil { | ||
| presentError(ctx, c, errors.Wrap(models.BadParameterError, err.Error())) | ||
| return | ||
| } | ||
| if err := input.Validate(); err != nil { | ||
| presentError(ctx, c, errors.Wrap(models.BadParameterError, err.Error())) | ||
| return | ||
| } | ||
|  | ||
| uc := usecasesWithCreds(ctx, uc).NewScreeningMonitoringUsecase() | ||
| screeningMonitoringConfig, err := uc.UpdateScreeningMonitoringConfig( | ||
| ctx, | ||
| configId, | ||
| dto.AdaptUpdateScreeningMonitoringConfigDtoToModel(input), | ||
| ) | ||
| if presentError(ctx, c, err) { | ||
| return | ||
| } | ||
|  | ||
| c.JSON(http.StatusOK, dto.AdaptScreeningMonitoringConfigDto(screeningMonitoringConfig)) | ||
| } | ||
| } | 
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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,104 @@ | ||
| package dto | ||
|  | ||
| import ( | ||
| "time" | ||
|  | ||
| "github.com/checkmarble/marble-backend/models" | ||
| "github.com/cockroachdb/errors" | ||
| ) | ||
|  | ||
| type ScreeningMonitoringConfigDto struct { | ||
| Id string `json:"id"` | ||
| Name string `json:"name"` | ||
| Description *string `json:"description"` | ||
| Datasets []string `json:"datasets"` | ||
| MatchThreshold int `json:"match_threshold"` | ||
| MatchLimit int `json:"match_limit"` | ||
| Enabled bool `json:"enabled"` | ||
| CreatedAt time.Time `json:"created_at"` | ||
| UpdatedAt time.Time `json:"updated_at"` | ||
| } | ||
|  | ||
| func AdaptScreeningMonitoringConfigDto(config models.ScreeningMonitoringConfig) ScreeningMonitoringConfigDto { | ||
| return ScreeningMonitoringConfigDto{ | ||
| Id: config.Id.String(), | ||
| Name: config.Name, | ||
| Description: config.Description, | ||
| Datasets: config.Datasets, | ||
| MatchThreshold: config.MatchThreshold, | ||
| MatchLimit: config.MatchLimit, | ||
| Enabled: config.Enabled, | ||
| CreatedAt: config.CreatedAt, | ||
| UpdatedAt: config.UpdatedAt, | ||
| } | ||
| } | ||
|  | ||
| type CreateScreeningMonitoringConfigDto struct { | ||
| Name string `json:"name" binding:"required"` | ||
| Description *string `json:"description"` | ||
| Datasets []string `json:"datasets" binding:"required"` | ||
| MatchThreshold int `json:"match_threshold" binding:"required"` | ||
| MatchLimit int `json:"match_limit" binding:"required"` | ||
| } | ||
|  | ||
| func (dto CreateScreeningMonitoringConfigDto) Validate() error { | ||
| if len(dto.Datasets) == 0 { | ||
| return errors.New("datasets are required for screening monitoring config") | ||
| } | ||
|  | ||
| if dto.MatchThreshold < 0 || dto.MatchThreshold > 100 { | ||
| return errors.New("match threshold must be between 0 and 100") | ||
| } | ||
|  | ||
| if dto.MatchLimit < 1 { | ||
| return errors.New("match limit must be greater than or equal to 0") | ||
| } | ||
|  | ||
| return nil | ||
| } | ||
|  | ||
| func AdaptCreateScreeningMonitoringConfigDtoToModel(dto CreateScreeningMonitoringConfigDto) models.CreateScreeningMonitoringConfig { | ||
| return models.CreateScreeningMonitoringConfig{ | ||
| Name: dto.Name, | ||
| Description: dto.Description, | ||
| Datasets: dto.Datasets, | ||
| MatchThreshold: dto.MatchThreshold, | ||
| MatchLimit: dto.MatchLimit, | ||
| } | ||
| } | ||
|  | ||
| type UpdateScreeningMonitoringConfigDto struct { | ||
| Name *string `json:"name"` | ||
| Description *string `json:"description"` | ||
| Datasets *[]string `json:"datasets"` | ||
| MatchThreshold *int `json:"match_threshold"` | ||
| MatchLimit *int `json:"match_limit"` | ||
| Enabled *bool `json:"enabled"` | ||
| } | ||
|  | ||
| func (dto UpdateScreeningMonitoringConfigDto) Validate() error { | ||
| if dto.MatchThreshold != nil && (*dto.MatchThreshold < 0 || *dto.MatchThreshold > 100) { | ||
| return errors.New("match threshold must be between 0 and 100") | ||
| } | ||
|  | ||
| if dto.MatchLimit != nil && *dto.MatchLimit < 0 { | ||
| return errors.New("match limit must be greater than or equal to 0") | ||
| } | ||
|  | ||
| if dto.Datasets != nil && len(*dto.Datasets) == 0 { | ||
| return errors.New("datasets cannot be empty") | ||
| } | ||
|  | ||
| return nil | ||
| } | ||
|  | ||
| func AdaptUpdateScreeningMonitoringConfigDtoToModel(dto UpdateScreeningMonitoringConfigDto) models.UpdateScreeningMonitoringConfig { | ||
| return models.UpdateScreeningMonitoringConfig{ | ||
| Name: dto.Name, | ||
| Description: dto.Description, | ||
| Datasets: dto.Datasets, | ||
| MatchThreshold: dto.MatchThreshold, | ||
| MatchLimit: dto.MatchLimit, | ||
| Enabled: dto.Enabled, | ||
| } | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.