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
Move 'CreatedAt', 'DeletedAt' and 'UpdatedAt' to common
entity.Info struct
Add 'CreatedBy' and 'UpdatedBy' to common entity.Info struct

Signed-off-by: Michal Krzyz <[email protected]>
  • Loading branch information
michalkrzyz committed Sep 17, 2024
1 parent 09986b7 commit cb2f9c1
Show file tree
Hide file tree
Showing 35 changed files with 275 additions and 214 deletions.
2 changes: 1 addition & 1 deletion internal/api/graphql/graph/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func NewIssueMatchEntity(im *IssueMatchInput) entity.IssueMatch {
IssueId: issueId,
ComponentInstanceId: ciId,
UserId: userId,
CreatedAt: createdAt,
Info: entity.Info{CreatedAt: createdAt},
}
}

Expand Down
162 changes: 100 additions & 62 deletions internal/database/mariadb/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ func (ir *IssueRow) AsIssue() entity.Issue {
IssueVariants: []entity.IssueVariant{},
IssueMatches: []entity.IssueMatch{},
Activity: []entity.Activity{},
CreatedAt: GetTimeValue(ir.CreatedAt),
DeletedAt: GetTimeValue(ir.DeletedAt),
UpdatedAt: GetTimeValue(ir.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(ir.CreatedAt),
DeletedAt: GetTimeValue(ir.DeletedAt),
UpdatedAt: GetTimeValue(ir.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -136,9 +138,11 @@ func (ibr *GetIssuesByRow) AsIssueWithAggregations() entity.IssueWithAggregation
IssueVariants: []entity.IssueVariant{},
IssueMatches: []entity.IssueMatch{},
Activity: []entity.Activity{},
CreatedAt: GetTimeValue(ibr.IssueRow.CreatedAt),
DeletedAt: GetTimeValue(ibr.IssueRow.DeletedAt),
UpdatedAt: GetTimeValue(ibr.IssueRow.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(ibr.IssueRow.CreatedAt),
DeletedAt: GetTimeValue(ibr.IssueRow.DeletedAt),
UpdatedAt: GetTimeValue(ibr.IssueRow.UpdatedAt),
},
},
}
}
Expand All @@ -152,9 +156,11 @@ func (ibr *GetIssuesByRow) AsIssue() entity.Issue {
IssueVariants: []entity.IssueVariant{},
IssueMatches: []entity.IssueMatch{},
Activity: []entity.Activity{},
CreatedAt: GetTimeValue(ibr.IssueRow.CreatedAt),
DeletedAt: GetTimeValue(ibr.IssueRow.DeletedAt),
UpdatedAt: GetTimeValue(ibr.IssueRow.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(ibr.IssueRow.CreatedAt),
DeletedAt: GetTimeValue(ibr.IssueRow.DeletedAt),
UpdatedAt: GetTimeValue(ibr.IssueRow.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -208,9 +214,11 @@ func (imr IssueMatchRow) AsIssueMatch() entity.IssueMatch {
RemediationDate: GetTimeValue(imr.RemediationDate),
TargetRemediationDate: GetTimeValue(imr.TargetRemediationDate),
Severity: entity.NewSeverity(GetStringValue(imr.Vector)),
CreatedAt: GetTimeValue(imr.CreatedAt),
DeletedAt: GetTimeValue(imr.DeletedAt),
UpdatedAt: GetTimeValue(imr.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(imr.CreatedAt),
DeletedAt: GetTimeValue(imr.DeletedAt),
UpdatedAt: GetTimeValue(imr.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -259,9 +267,11 @@ func (birr *BaseIssueRepositoryRow) AsBaseIssueRepository() entity.BaseIssueRepo
Url: GetStringValue(birr.Url),
IssueVariants: nil,
Services: nil,
CreatedAt: GetTimeValue(birr.CreatedAt),
DeletedAt: GetTimeValue(birr.DeletedAt),
UpdatedAt: GetTimeValue(birr.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(birr.CreatedAt),
DeletedAt: GetTimeValue(birr.DeletedAt),
UpdatedAt: GetTimeValue(birr.UpdatedAt),
},
}
}

Expand All @@ -273,9 +283,11 @@ func (barr *BaseIssueRepositoryRow) AsIssueRepository() entity.IssueRepository {
Url: GetStringValue(barr.Url),
IssueVariants: nil,
Services: nil,
CreatedAt: GetTimeValue(barr.CreatedAt),
DeletedAt: GetTimeValue(barr.DeletedAt),
UpdatedAt: GetTimeValue(barr.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(barr.CreatedAt),
DeletedAt: GetTimeValue(barr.DeletedAt),
UpdatedAt: GetTimeValue(barr.UpdatedAt),
},
},
}
}
Expand All @@ -288,9 +300,11 @@ func (irr *IssueRepositoryRow) AsIssueRepository() entity.IssueRepository {
Url: GetStringValue(irr.Url),
IssueVariants: nil,
Services: nil,
CreatedAt: GetTimeValue(irr.BaseIssueRepositoryRow.CreatedAt),
DeletedAt: GetTimeValue(irr.BaseIssueRepositoryRow.DeletedAt),
UpdatedAt: GetTimeValue(irr.BaseIssueRepositoryRow.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(irr.BaseIssueRepositoryRow.CreatedAt),
DeletedAt: GetTimeValue(irr.BaseIssueRepositoryRow.DeletedAt),
UpdatedAt: GetTimeValue(irr.BaseIssueRepositoryRow.UpdatedAt),
},
},
IssueRepositoryService: entity.IssueRepositoryService{
ServiceId: GetInt64Value(irr.ServiceId),
Expand Down Expand Up @@ -322,9 +336,11 @@ func (ivr *IssueVariantRow) AsIssueVariant(repository *entity.IssueRepository) e
Issue: nil,
Severity: entity.NewSeverity(GetStringValue(ivr.Vector)),
Description: GetStringValue(ivr.Description),
CreatedAt: GetTimeValue(ivr.CreatedAt),
DeletedAt: GetTimeValue(ivr.DeletedAt),
UpdatedAt: GetTimeValue(ivr.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(ivr.CreatedAt),
DeletedAt: GetTimeValue(ivr.DeletedAt),
UpdatedAt: GetTimeValue(ivr.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -357,9 +373,11 @@ func (ivwr *IssueVariantWithRepository) AsIssueVariantEntry() entity.IssueVarian
Issue: nil,
Severity: entity.NewSeverity(GetStringValue(ivwr.Vector)),
Description: GetStringValue(ivwr.Description),
CreatedAt: GetTimeValue(ivwr.IssueVariantRow.CreatedAt),
DeletedAt: GetTimeValue(ivwr.IssueVariantRow.DeletedAt),
UpdatedAt: GetTimeValue(ivwr.IssueVariantRow.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(ivwr.IssueVariantRow.CreatedAt),
DeletedAt: GetTimeValue(ivwr.IssueVariantRow.DeletedAt),
UpdatedAt: GetTimeValue(ivwr.IssueVariantRow.UpdatedAt),
},
}
}

Expand All @@ -374,12 +392,14 @@ type ComponentRow struct {

func (cr *ComponentRow) AsComponent() entity.Component {
return entity.Component{
Id: GetInt64Value(cr.Id),
Name: GetStringValue(cr.Name),
Type: GetStringValue(cr.Type),
CreatedAt: GetTimeValue(cr.CreatedAt),
DeletedAt: GetTimeValue(cr.DeletedAt),
UpdatedAt: GetTimeValue(cr.UpdatedAt),
Id: GetInt64Value(cr.Id),
Name: GetStringValue(cr.Name),
Type: GetStringValue(cr.Type),
Info: entity.Info{
CreatedAt: GetTimeValue(cr.CreatedAt),
DeletedAt: GetTimeValue(cr.DeletedAt),
UpdatedAt: GetTimeValue(cr.UpdatedAt),
},
}
}

Expand All @@ -406,9 +426,11 @@ func (cvr *ComponentVersionRow) AsComponentVersion() entity.ComponentVersion {
Id: GetInt64Value(cvr.Id),
Version: GetStringValue(cvr.Version),
ComponentId: GetInt64Value(cvr.ComponentId),
CreatedAt: GetTimeValue(cvr.CreatedAt),
DeletedAt: GetTimeValue(cvr.DeletedAt),
UpdatedAt: GetTimeValue(cvr.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(cvr.CreatedAt),
DeletedAt: GetTimeValue(cvr.DeletedAt),
UpdatedAt: GetTimeValue(cvr.UpdatedAt),
},
}
}

Expand All @@ -431,11 +453,13 @@ type SupportGroupRow struct {

func (sgr *SupportGroupRow) AsSupportGroup() entity.SupportGroup {
return entity.SupportGroup{
Id: GetInt64Value(sgr.Id),
Name: GetStringValue(sgr.Name),
CreatedAt: GetTimeValue(sgr.CreatedAt),
DeletedAt: GetTimeValue(sgr.DeletedAt),
UpdatedAt: GetTimeValue(sgr.UpdatedAt),
Id: GetInt64Value(sgr.Id),
Name: GetStringValue(sgr.Name),
Info: entity.Info{
CreatedAt: GetTimeValue(sgr.CreatedAt),
DeletedAt: GetTimeValue(sgr.DeletedAt),
UpdatedAt: GetTimeValue(sgr.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -466,9 +490,11 @@ func (bsr *BaseServiceRow) AsBaseService() entity.BaseService {
Name: GetStringValue(bsr.Name),
Owners: []entity.User{},
Activities: []entity.Activity{},
CreatedAt: GetTimeValue(bsr.CreatedAt),
DeletedAt: GetTimeValue(bsr.DeletedAt),
UpdatedAt: GetTimeValue(bsr.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(bsr.CreatedAt),
DeletedAt: GetTimeValue(bsr.DeletedAt),
UpdatedAt: GetTimeValue(bsr.UpdatedAt),
},
}
}

Expand All @@ -486,9 +512,11 @@ func (sr *ServiceRow) AsService() entity.Service {
Name: GetStringValue(sr.Name),
Owners: []entity.User{},
Activities: []entity.Activity{},
CreatedAt: GetTimeValue(sr.BaseServiceRow.CreatedAt),
DeletedAt: GetTimeValue(sr.BaseServiceRow.DeletedAt),
UpdatedAt: GetTimeValue(sr.BaseServiceRow.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(sr.BaseServiceRow.CreatedAt),
DeletedAt: GetTimeValue(sr.BaseServiceRow.DeletedAt),
UpdatedAt: GetTimeValue(sr.BaseServiceRow.UpdatedAt),
},
},
IssueRepositoryService: entity.IssueRepositoryService{
ServiceId: GetInt64Value(sr.ServiceId),
Expand Down Expand Up @@ -519,9 +547,11 @@ func (ar *ActivityRow) AsActivity() entity.Activity {
Status: entity.ActivityStatusValue(GetStringValue(ar.Status)),
Issues: []entity.Issue{},
Evidences: []entity.Evidence{},
CreatedAt: GetTimeValue(ar.CreatedAt),
DeletedAt: GetTimeValue(ar.DeletedAt),
UpdatedAt: GetTimeValue(ar.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(ar.CreatedAt),
DeletedAt: GetTimeValue(ar.DeletedAt),
UpdatedAt: GetTimeValue(ar.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -553,9 +583,11 @@ func (cir *ComponentInstanceRow) AsComponentInstance() entity.ComponentInstance
ComponentVersionId: GetInt64Value(cir.ComponentVersionId),
Service: nil,
ServiceId: GetInt64Value(cir.ServiceId),
CreatedAt: GetTimeValue(cir.CreatedAt),
DeletedAt: GetTimeValue(cir.DeletedAt),
UpdatedAt: GetTimeValue(cir.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(cir.CreatedAt),
DeletedAt: GetTimeValue(cir.DeletedAt),
UpdatedAt: GetTimeValue(cir.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -586,9 +618,11 @@ func (ur *UserRow) AsUser() entity.User {
Name: GetStringValue(ur.Name),
UniqueUserID: GetStringValue(ur.UniqueUserID),
Type: GetUserTypeValue(ur.Type),
CreatedAt: GetTimeValue(ur.CreatedAt),
DeletedAt: GetTimeValue(ur.DeletedAt),
UpdatedAt: GetTimeValue(ur.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(ur.CreatedAt),
DeletedAt: GetTimeValue(ur.DeletedAt),
UpdatedAt: GetTimeValue(ur.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -629,9 +663,11 @@ func (er *EvidenceRow) AsEvidence() entity.Evidence {
UserId: GetInt64Value(er.UserId),
Activity: nil,
ActivityId: GetInt64Value(er.ActivityId),
CreatedAt: GetTimeValue(er.CreatedAt),
DeletedAt: GetTimeValue(er.DeletedAt),
UpdatedAt: GetTimeValue(er.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(er.CreatedAt),
DeletedAt: GetTimeValue(er.DeletedAt),
UpdatedAt: GetTimeValue(er.UpdatedAt),
},
}
}

Expand Down Expand Up @@ -665,9 +701,11 @@ func (imcr *IssueMatchChangeRow) AsIssueMatchChange() entity.IssueMatchChange {
IssueMatchId: GetInt64Value(imcr.IssueMatchId),
ActivityId: GetInt64Value(imcr.ActivityId),
Action: GetStringValue(imcr.Action),
CreatedAt: GetTimeValue(imcr.CreatedAt),
DeletedAt: GetTimeValue(imcr.DeletedAt),
UpdatedAt: GetTimeValue(imcr.UpdatedAt),
Info: entity.Info{
CreatedAt: GetTimeValue(imcr.CreatedAt),
DeletedAt: GetTimeValue(imcr.DeletedAt),
UpdatedAt: GetTimeValue(imcr.UpdatedAt),
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/database/mariadb/internal/mocks/mock_Database.go

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

2 changes: 1 addition & 1 deletion internal/database/mariadb/internal/mocks/mock_Heureka.go

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

16 changes: 6 additions & 10 deletions internal/entity/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

package entity

import "time"

type ActivityStatusValue string

const (
Expand Down Expand Up @@ -36,32 +34,30 @@ var AllActivityStatusValues = []string{
}

type Activity struct {
Info
Id int64 `json:"id"`
Status ActivityStatusValue `json:"status"`
Service *Service `json:"service,omitempty"`
Issues []Issue `json:"issues,omitempty"`
Evidences []Evidence `json:"evidences,omitempty"`
CreatedAt time.Time `json:"created_at"`
DeletedAt time.Time `json:"deleted_at,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
}

func (a *Activity) GetId() int64 {
return a.Id
}

type ActivityHasIssue struct {
ActivityId int64 `json:"activity_id"`
IssueId int64 `json:"issue_id"`
CreatedAt time.Time `json:"created_at"`
DeletedAt time.Time `json:"deleted_at,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
Info
ActivityId int64 `json:"activity_id"`
IssueId int64 `json:"issue_id"`
}

type ActivityAggregations struct {
Info
}

type ActivityFilter struct {
Info
Paginated
Status []*string `json:"status"`
ServiceName []*string `json:"service_name"`
Expand Down
Loading

0 comments on commit cb2f9c1

Please sign in to comment.