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 activity and IssueVariant
  • Loading branch information
michalkrzyz committed Sep 26, 2024
1 parent 419e412 commit 2cdfe8c
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 239 deletions.
454 changes: 257 additions & 197 deletions internal/api/graphql/graph/generated.go

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions internal/api/graphql/graph/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ func NewIssueVariant(issueVariant *entity.IssueVariant) IssueVariant {
if issueVariant.IssueRepository != nil {
repo = NewIssueRepository(issueVariant.IssueRepository)
}
createdAt := issueVariant.CreatedAt.String()
updatedAt := issueVariant.UpdatedAt.String()
return IssueVariant{
ID: fmt.Sprintf("%d", issueVariant.Id),
SecondaryName: &issueVariant.SecondaryName,
Expand All @@ -296,20 +294,16 @@ func NewIssueVariant(issueVariant *entity.IssueVariant) IssueVariant {
IssueID: util.Ptr(fmt.Sprintf("%d", issueVariant.IssueId)),
IssueRepositoryID: util.Ptr(fmt.Sprintf("%d", issueVariant.IssueRepositoryId)),
IssueRepository: &repo,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Metadata: getModelMetadata(issueVariant.Metadata),
}
}

func NewIssueVariantEdge(issueVariant *entity.IssueVariant) IssueVariantEdge {
iv := NewIssueVariant(issueVariant)
edgeCreationDate := issueVariant.CreatedAt.String()
edgeUpdateDate := issueVariant.UpdatedAt.String()
issueVariantEdge := IssueVariantEdge{
Node: &iv,
Cursor: &iv.ID,
CreatedAt: &edgeCreationDate,
UpdatedAt: &edgeUpdateDate,
Metadata: getModelMetadata(issueVariant.Metadata),
}
return issueVariantEdge
}
Expand Down Expand Up @@ -375,9 +369,9 @@ func NewSupportGroupEntity(supportGroup *SupportGroupInput) entity.SupportGroup
func NewActivity(activity *entity.Activity) Activity {
status := ActivityStatusValues(activity.Status.String())
return Activity{
ID: fmt.Sprintf("%d", activity.Id),
Status: &status,
//Metadata: activity.getModelMetadata(activitiy),
ID: fmt.Sprintf("%d", activity.Id),
Status: &status,
Metadata: getModelMetadata(activity.Metadata),
}
}

Expand Down
16 changes: 8 additions & 8 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.

Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
updated_at
}
issueId
metadata {
created_at
updated_at
}
}
cursor
metadata {
created_at
updated_at
}
cursor
created_at
updated_at
}
pageInfo {
hasNextPage
Expand Down Expand Up @@ -98,4 +102,4 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ query ($filter: IssueRepositoryFilter, $first: Int, $after: String) {
description
issueRepositoryId
issueId
metadata {
created_at
updated_at
}
}
cursor
metadata {
created_at
updated_at
}
cursor
created_at
updated_at
}
pageInfo {
hasNextPage
Expand Down Expand Up @@ -71,4 +75,4 @@ query ($filter: IssueRepositoryFilter, $first: Int, $after: String) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ query ($filter: IssueVariantFilter, $first: Int, $after: String) {
id
lastModified
}
metadata {
created_at
updated_at
}
}
cursor
metadata {
created_at
updated_at
}
cursor
created_at
updated_at
}
pageInfo {
hasNextPage
Expand All @@ -52,4 +56,4 @@ query ($filter: IssueVariantFilter, $first: Int, $after: String) {
}
}
}
}
}
4 changes: 3 additions & 1 deletion internal/api/graphql/graph/schema/activity.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Activity implements Node {
issues(filter: IssueFilter, first: Int, after: String): IssueConnection
evidences(filter: EvidenceFilter, first: Int, after: String): EvidenceConnection
issueMatchChanges(filter: IssueMatchChangeFilter, first: Int, after: String): IssueMatchChangeConnection
metadata: Metadata
}

input ActivityInput {
Expand All @@ -23,6 +24,7 @@ type ActivityConnection implements Connection {
type ActivityEdge implements Edge {
node: Activity!
cursor: String
metadata: Metadata
}

input ActivityFilter {
Expand All @@ -34,4 +36,4 @@ enum ActivityStatusValues {
open,
closed,
in_progress
}
}
8 changes: 3 additions & 5 deletions internal/api/graphql/graph/schema/issue_variant.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ type IssueVariant implements Node {
issueRepository: IssueRepository
issueId: String
issue: Issue
created_at: DateTime
updated_at: DateTime
metadata: Metadata
}

input IssueVariantInput {
Expand All @@ -31,10 +30,9 @@ type IssueVariantConnection implements Connection {
type IssueVariantEdge implements Edge {
node: IssueVariant!
cursor: String
created_at: DateTime
updated_at: DateTime
metadata: Metadata
}

input IssueVariantFilter {
secondaryName: [String]
}
}
2 changes: 2 additions & 0 deletions internal/app/activity/activity_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func (a *activityHandler) ListActivities(filter *entity.ActivityFilter, options
}

func (a *activityHandler) CreateActivity(activity *entity.Activity) (*entity.Activity, error) {
activity.CreatedBy = "Creator"
l := logrus.WithFields(logrus.Fields{
"event": ActivityCreateEventName,
"object": activity,
Expand All @@ -152,6 +153,7 @@ func (a *activityHandler) CreateActivity(activity *entity.Activity) (*entity.Act
}

func (a *activityHandler) UpdateActivity(activity *entity.Activity) (*entity.Activity, error) {
activity.UpdatedBy = "Updater"
l := logrus.WithFields(logrus.Fields{
"event": ActivityUpdateEventName,
"object": activity,
Expand Down
2 changes: 2 additions & 0 deletions internal/app/issue_variant/issue_variant_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (iv *issueVariantHandler) ListEffectiveIssueVariants(filter *entity.IssueVa
}

func (iv *issueVariantHandler) CreateIssueVariant(issueVariant *entity.IssueVariant) (*entity.IssueVariant, error) {
issueVariant.CreatedBy = "Creator"
f := &entity.IssueVariantFilter{
SecondaryName: []*string{&issueVariant.SecondaryName},
}
Expand Down Expand Up @@ -203,6 +204,7 @@ func (iv *issueVariantHandler) CreateIssueVariant(issueVariant *entity.IssueVari
}

func (iv *issueVariantHandler) UpdateIssueVariant(issueVariant *entity.IssueVariant) (*entity.IssueVariant, error) {
issueVariant.UpdatedBy = "Updater"
l := logrus.WithFields(logrus.Fields{
"event": UpdateIssueVariantEventName,
"object": issueVariant,
Expand Down
9 changes: 7 additions & 2 deletions internal/database/mariadb/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (s *SqlDatabase) getActivityUpdateFields(activity *entity.Activity) string
if activity.Status != "" {
fl = append(fl, "activity_status = :activity_status")
}
if activity.UpdatedBy != "" {
fl = append(fl, "activity_updated_by = :activity_updated_by")
}
return strings.Join(fl, ", ")
}

Expand Down Expand Up @@ -208,9 +211,11 @@ func (s *SqlDatabase) CreateActivity(activity *entity.Activity) (*entity.Activit

query := `
INSERT INTO Activity (
activity_status
activity_status,
activity_created_by
) VALUES (
:activity_status
:activity_status,
:activity_created_by
)
`

Expand Down
16 changes: 16 additions & 0 deletions internal/database/mariadb/entity.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
// SPDX-License-Identifier: Apache-2.0

//TODO: add Metadata type for mariadb package
//TODO: add Metadata converter mariadb - entity
//TODO: add Metadata converter entity - mariadb

package mariadb

import (
Expand Down Expand Up @@ -322,8 +326,10 @@ type IssueVariantRow struct {
Rating sql.NullString `db:"issuevariant_rating" json:"rating"`
Description sql.NullString `db:"issuevariant_description" json:"description"`
CreatedAt sql.NullTime `db:"issuevariant_created_at" json:"created_at"`
CreatedBy sql.NullString `db:"issuevariant_created_by" json:"created_by"`
DeletedAt sql.NullTime `db:"issuevariant_deleted_at" json:"deleted_at,omitempty"`
UpdatedAt sql.NullTime `db:"issuevariant_updated_at" json:"updated_at"`
UpdatedBy sql.NullString `db:"issuevariant_updated_by" json:"updated_by"`
}

func (ivr *IssueVariantRow) AsIssueVariant(repository *entity.IssueRepository) entity.IssueVariant {
Expand All @@ -338,8 +344,10 @@ func (ivr *IssueVariantRow) AsIssueVariant(repository *entity.IssueRepository) e
Description: GetStringValue(ivr.Description),
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(ivr.CreatedAt),
CreatedBy: GetStringValue(ivr.CreatedBy),
DeletedAt: GetTimeValue(ivr.DeletedAt),
UpdatedAt: GetTimeValue(ivr.UpdatedAt),
UpdatedBy: GetStringValue(ivr.UpdatedBy),
},
}
}
Expand All @@ -353,8 +361,10 @@ func (ivr *IssueVariantRow) FromIssueVariant(iv *entity.IssueVariant) {
ivr.Rating = sql.NullString{String: iv.Severity.Value, Valid: true}
ivr.Description = sql.NullString{String: iv.Description, Valid: true}
ivr.CreatedAt = sql.NullTime{Time: iv.CreatedAt, Valid: true}
ivr.CreatedBy = sql.NullString{String: iv.CreatedBy, Valid: true}
ivr.DeletedAt = sql.NullTime{Time: iv.DeletedAt, Valid: true}
ivr.UpdatedAt = sql.NullTime{Time: iv.UpdatedAt, Valid: true}
ivr.UpdatedBy = sql.NullString{String: iv.UpdatedBy, Valid: true}
}

type IssueVariantWithRepository struct {
Expand Down Expand Up @@ -537,8 +547,10 @@ type ActivityRow struct {
Id sql.NullInt64 `db:"activity_id" json:"id"`
Status sql.NullString `db:"activity_status" json:"status"`
CreatedAt sql.NullTime `db:"activity_created_at" json:"created_at"`
CreatedBy sql.NullString `db:"activity_created_by" json:"created_by"`
DeletedAt sql.NullTime `db:"activity_deleted_at" json:"deleted_at,omitempty"`
UpdatedAt sql.NullTime `db:"activity_updated_at" json:"updated_at"`
UpdatedBy sql.NullString `db:"activity_updated_by" json:"updated_by"`
}

func (ar *ActivityRow) AsActivity() entity.Activity {
Expand All @@ -549,8 +561,10 @@ func (ar *ActivityRow) AsActivity() entity.Activity {
Evidences: []entity.Evidence{},
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(ar.CreatedAt),
CreatedBy: GetStringValue(ar.CreatedBy),
DeletedAt: GetTimeValue(ar.DeletedAt),
UpdatedAt: GetTimeValue(ar.UpdatedAt),
UpdatedBy: GetStringValue(ar.UpdatedBy),
},
}
}
Expand All @@ -559,8 +573,10 @@ func (ar *ActivityRow) FromActivity(a *entity.Activity) {
ar.Id = sql.NullInt64{Int64: a.Id, Valid: true}
ar.Status = sql.NullString{String: a.Status.String(), Valid: true}
ar.CreatedAt = sql.NullTime{Time: a.CreatedAt, Valid: true}
ar.CreatedBy = sql.NullString{String: a.CreatedBy, Valid: true}
ar.DeletedAt = sql.NullTime{Time: a.DeletedAt, Valid: true}
ar.UpdatedAt = sql.NullTime{Time: a.UpdatedAt, Valid: true}
ar.UpdatedBy = sql.NullString{String: a.UpdatedBy, Valid: true}
}

type ComponentInstanceRow struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/database/mariadb/init/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ create table if not exists Activity
primary key,
activity_status enum('open','closed','in_progress') not null,
activity_created_at timestamp default current_timestamp() not null,
activity_created_by varchar(256) null,
activity_deleted_at timestamp null,
activity_updated_at timestamp default current_timestamp() not null on update current_timestamp(),
activity_updated_by varchar(256) null,
constraint id_UNIQUE
unique (activity_id)
);
Expand Down Expand Up @@ -237,8 +239,10 @@ create table if not exists IssueVariant
issuevariant_secondary_name varchar(256) not null,
issuevariant_description longtext not null,
issuevariant_created_at timestamp default current_timestamp() not null,
issuevariant_created_by varchar(256) null,
issuevariant_deleted_at timestamp null,
issuevariant_updated_at timestamp default current_timestamp() not null on update current_timestamp(),
issuevariant_updated_by varchar(256) null,
constraint id_UNIQUE
unique (issuevariant_id),
constraint name_UNIQUE
Expand Down
Loading

0 comments on commit 2cdfe8c

Please sign in to comment.