Skip to content

Commit

Permalink
feat(authN): Add to all DB entries 'Modified_by'... (#81)
Browse files Browse the repository at this point in the history
Add metadata for component
  • Loading branch information
michalkrzyz committed Oct 1, 2024
1 parent abcd977 commit d6d5698
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 6 deletions.
91 changes: 91 additions & 0 deletions internal/api/graphql/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions internal/api/graphql/graph/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,10 @@ func NewEvidenceEntity(evidence *EvidenceInput) entity.Evidence {
func NewComponent(component *entity.Component) Component {
componentType, _ := ComponentTypeValue(component.Type)
return Component{
ID: fmt.Sprintf("%d", component.Id),
Name: &component.Name,
Type: &componentType,
ID: fmt.Sprintf("%d", component.Id),
Name: &component.Name,
Type: &componentType,
Metadata: getModelMetadata(component.Metadata),
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/api/graphql/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion internal/api/graphql/graph/schema/component.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Component implements Node {
name: String
type: ComponentTypeValues
componentVersions(filter: ComponentVersionFilter, first: Int, after: String): ComponentVersionConnection
metadata: Metadata
}

input ComponentInput {
Expand All @@ -32,4 +33,4 @@ type ComponentConnection implements Connection {
type ComponentEdge implements Edge {
node: Component!
cursor: String
}
}
2 changes: 2 additions & 0 deletions internal/app/component/component_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (cs *componentHandler) ListComponents(filter *entity.ComponentFilter, optio
}

func (cs *componentHandler) CreateComponent(component *entity.Component) (*entity.Component, error) {
component.CreatedBy = "Creator"
f := &entity.ComponentFilter{
Name: []*string{&component.Name},
}
Expand Down Expand Up @@ -139,6 +140,7 @@ func (cs *componentHandler) CreateComponent(component *entity.Component) (*entit
}

func (cs *componentHandler) UpdateComponent(component *entity.Component) (*entity.Component, error) {
component.UpdatedBy = "Updater"
l := logrus.WithFields(logrus.Fields{
"event": UpdateComponentEventName,
"object": component,
Expand Down
9 changes: 7 additions & 2 deletions internal/database/mariadb/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func (s *SqlDatabase) getComponentUpdateFields(component *entity.Component) stri
if component.Type != "" {
fl = append(fl, "component_type = :component_type")
}
if component.UpdatedBy != "" {
fl = append(fl, "component_updated_by = :component_updated_by")
}
return strings.Join(fl, ", ")
}

Expand Down Expand Up @@ -202,10 +205,12 @@ func (s *SqlDatabase) CreateComponent(component *entity.Component) (*entity.Comp
query := `
INSERT INTO Component (
component_name,
component_type
component_type,
component_created_by
) VALUES (
:component_name,
:component_type
:component_type,
:component_created_by
)
`

Expand Down
6 changes: 6 additions & 0 deletions internal/database/mariadb/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,10 @@ type ComponentRow struct {
Name sql.NullString `db:"component_name" json:"name"`
Type sql.NullString `db:"component_type" json:"type"`
CreatedAt sql.NullTime `db:"component_created_at" json:"created_at"`
CreatedBy sql.NullString `db:"component_created_by" json:"created_by"`
DeletedAt sql.NullTime `db:"component_deleted_at" json:"deleted_at,omitempty"`
UpdatedAt sql.NullTime `db:"component_updated_at" json:"updated_at"`
UpdatedBy sql.NullString `db:"component_updated_by" json:"updated_by"`
}

func (cr *ComponentRow) AsComponent() entity.Component {
Expand All @@ -420,8 +422,10 @@ func (cr *ComponentRow) AsComponent() entity.Component {
Type: GetStringValue(cr.Type),
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(cr.CreatedAt),
CreatedBy: GetStringValue(cr.CreatedBy),
DeletedAt: GetTimeValue(cr.DeletedAt),
UpdatedAt: GetTimeValue(cr.UpdatedAt),
UpdatedBy: GetStringValue(cr.UpdatedBy),
},
}
}
Expand All @@ -431,8 +435,10 @@ func (cr *ComponentRow) FromComponent(c *entity.Component) {
cr.Name = sql.NullString{String: c.Name, Valid: true}
cr.Type = sql.NullString{String: c.Type, Valid: true}
cr.CreatedAt = sql.NullTime{Time: c.CreatedAt, Valid: true}
cr.CreatedBy = sql.NullString{String: c.CreatedBy, Valid: true}
cr.DeletedAt = sql.NullTime{Time: c.DeletedAt, Valid: true}
cr.UpdatedAt = sql.NullTime{Time: c.UpdatedAt, Valid: true}
cr.UpdatedBy = sql.NullString{String: c.UpdatedBy, Valid: true}
}

type ComponentVersionRow struct {
Expand Down
2 changes: 2 additions & 0 deletions internal/database/mariadb/init/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ create table if not exists Component
component_name varchar(256) not null,
component_type varchar(256) not null,
component_created_at timestamp default current_timestamp() not null,
component_created_by varchar(256) null,
component_deleted_at timestamp null,
component_updated_at timestamp default current_timestamp() not null on update current_timestamp(),
component_updated_by varchar(256) null,
constraint id_UNIQUE
unique (component_id),
constraint name_UNIQUE
Expand Down

0 comments on commit d6d5698

Please sign in to comment.