Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkrzyz committed Nov 13, 2024
1 parent 62c85eb commit 5cf6406
Show file tree
Hide file tree
Showing 32 changed files with 35 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
totalCount
edges {
node {
id
primaryName
id
primaryName
type
description
description
metadata {
created_at
created_by
Expand Down
4 changes: 2 additions & 2 deletions internal/app/activity/activity_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (a *activityHandler) CreateActivity(activity *entity.Activity) (*entity.Act
})

var err error
activity.CreatedBy, err = common.GetUserId(a.database, "S0000000")
activity.CreatedBy, err = common.GetCurrentUserId(a.database)
if err != nil {
l.Error(err)
return nil, NewActivityHandlerError("Internal error while creating activity (GetUserId).")
Expand All @@ -165,7 +165,7 @@ func (a *activityHandler) UpdateActivity(activity *entity.Activity) (*entity.Act
})

var err error
activity.UpdatedBy, err = common.GetUserId(a.database, "S0000000")
activity.UpdatedBy, err = common.GetCurrentUserId(a.database)
if err != nil {
l.Error(err)
return nil, NewActivityHandlerError("Internal error while updating activity (GetUserId).")
Expand Down
6 changes: 5 additions & 1 deletion internal/app/common/user_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (
"github.com/cloudoperators/heureka/internal/entity"
)

func GetUserId(db database.Database, uniqueUserId string) (int64, error) {
func GetCurrentUserId(db database.Database) (int64, error) {
return getUserIdFromDb(db, "S0000000")
}

func getUserIdFromDb(db database.Database, uniqueUserId string) (int64, error) {
filter := &entity.UserFilter{UniqueUserID: []*string{&uniqueUserId}}
ids, err := db.GetAllUserIds(filter)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/app/component/component_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (cs *componentHandler) CreateComponent(component *entity.Component) (*entit
})

var err error
component.CreatedBy, err = common.GetUserId(cs.database, "S0000000")
component.CreatedBy, err = common.GetCurrentUserId(cs.database)
if err != nil {
l.Error(err)
return nil, NewUserHandlerError("Internal error while creating component (GetUserId).")
Expand Down Expand Up @@ -152,7 +152,7 @@ func (cs *componentHandler) UpdateComponent(component *entity.Component) (*entit
})

var err error
component.UpdatedBy, err = common.GetUserId(cs.database, "S0000000")
component.UpdatedBy, err = common.GetCurrentUserId(cs.database)
if err != nil {
l.Error(err)
return nil, NewUserHandlerError("Internal error while updating component (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/component_instance/component_instance_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (ci *componentInstanceHandler) CreateComponentInstance(componentInstance *e
})

var err error
componentInstance.CreatedBy, err = common.GetUserId(ci.database, "S0000000")
componentInstance.CreatedBy, err = common.GetCurrentUserId(ci.database)
if err != nil {
l.Error(err)
return nil, NewComponentInstanceHandlerError("Internal error while creating componentInstance (GetUserId).")
Expand All @@ -144,7 +144,7 @@ func (ci *componentInstanceHandler) UpdateComponentInstance(componentInstance *e
})

var err error
componentInstance.UpdatedBy, err = common.GetUserId(ci.database, "S0000000")
componentInstance.UpdatedBy, err = common.GetCurrentUserId(ci.database)
if err != nil {
l.Error(err)
return nil, NewComponentInstanceHandlerError("Internal error while updating componentInstance (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/component_version/component_version_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (cv *componentVersionHandler) CreateComponentVersion(componentVersion *enti
})

var err error
componentVersion.CreatedBy, err = common.GetUserId(cv.database, "S0000000")
componentVersion.CreatedBy, err = common.GetCurrentUserId(cv.database)
if err != nil {
l.Error(err)
return nil, NewComponentVersionHandlerError("Internal error while creating componentVersion (GetUserId).")
Expand Down Expand Up @@ -146,7 +146,7 @@ func (cv *componentVersionHandler) UpdateComponentVersion(componentVersion *enti
})

var err error
componentVersion.UpdatedBy, err = common.GetUserId(cv.database, "S0000000")
componentVersion.UpdatedBy, err = common.GetCurrentUserId(cv.database)
if err != nil {
l.Error(err)
return nil, NewComponentVersionHandlerError("Internal error while updating componentVersion (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/evidence/evidence_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (e *evidenceHandler) CreateEvidence(evidence *entity.Evidence) (*entity.Evi
})

var err error
evidence.CreatedBy, err = common.GetUserId(e.database, "S0000000")
evidence.CreatedBy, err = common.GetCurrentUserId(e.database)
if err != nil {
l.Error(err)
return nil, NewEvidenceHandlerError("Internal error while creating evidence (GetUserId).")
Expand All @@ -135,7 +135,7 @@ func (e *evidenceHandler) UpdateEvidence(evidence *entity.Evidence) (*entity.Evi
})

var err error
evidence.UpdatedBy, err = common.GetUserId(e.database, "S0000000")
evidence.UpdatedBy, err = common.GetCurrentUserId(e.database)
if err != nil {
l.Error(err)
return nil, NewEvidenceHandlerError("Internal error while updating evidence (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/issue/issue_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (is *issueHandler) CreateIssue(issue *entity.Issue) (*entity.Issue, error)
})

var err error
issue.CreatedBy, err = common.GetUserId(is.database, "S0000000")
issue.CreatedBy, err = common.GetCurrentUserId(is.database)
if err != nil {
l.Error(err)
return nil, NewIssueHandlerError("Internal error while creating issue (GetUserId).")
Expand Down Expand Up @@ -206,7 +206,7 @@ func (is *issueHandler) UpdateIssue(issue *entity.Issue) (*entity.Issue, error)
})

var err error
issue.UpdatedBy, err = common.GetUserId(is.database, "S0000000")
issue.UpdatedBy, err = common.GetCurrentUserId(is.database)
if err != nil {
l.Error(err)
return nil, NewIssueHandlerError("Internal error while updating issue (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/issue_match/issue_match_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (im *issueMatchHandler) CreateIssueMatch(issueMatch *entity.IssueMatch) (*e
})

var err error
issueMatch.CreatedBy, err = common.GetUserId(im.database, "S0000000")
issueMatch.CreatedBy, err = common.GetCurrentUserId(im.database)
if err != nil {
l.Error(err)
return nil, NewIssueMatchHandlerError("Internal error while retrieving effective severity (GetUserId).")
Expand Down Expand Up @@ -183,7 +183,7 @@ func (im *issueMatchHandler) UpdateIssueMatch(issueMatch *entity.IssueMatch) (*e
})

var err error
issueMatch.UpdatedBy, err = common.GetUserId(im.database, "S0000000")
issueMatch.UpdatedBy, err = common.GetCurrentUserId(im.database)
if err != nil {
l.Error(err)
return nil, NewIssueMatchHandlerError("Internal error while retrieving effective severity (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/issue_match_change/issue_match_change_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (imc *issueMatchChangeHandler) CreateIssueMatchChange(issueMatchChange *ent
})

var err error
issueMatchChange.CreatedBy, err = common.GetUserId(imc.database, "S0000000")
issueMatchChange.CreatedBy, err = common.GetCurrentUserId(imc.database)
if err != nil {
l.Error(err)
return nil, NewIssueMatchChangeHandlerError("Internal error while creating issueMatchChange (GetUserId).")
Expand All @@ -141,7 +141,7 @@ func (imc *issueMatchChangeHandler) UpdateIssueMatchChange(issueMatchChange *ent
})

var err error
issueMatchChange.UpdatedBy, err = common.GetUserId(imc.database, "S0000000")
issueMatchChange.UpdatedBy, err = common.GetCurrentUserId(imc.database)
if err != nil {
l.Error(err)
return nil, NewIssueMatchChangeHandlerError("Internal error while updating issueMatchChange (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/issue_repository/issue_repository_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (ir *issueRepositoryHandler) CreateIssueRepository(issueRepository *entity.
})

var err error
issueRepository.BaseIssueRepository.CreatedBy, err = common.GetUserId(ir.database, "S0000000")
issueRepository.BaseIssueRepository.CreatedBy, err = common.GetCurrentUserId(ir.database)
if err != nil {
l.Error(err)
return nil, NewIssueRepositoryHandlerError("Internal error while creating issueRepository (GetUserId).")
Expand Down Expand Up @@ -150,7 +150,7 @@ func (ir *issueRepositoryHandler) UpdateIssueRepository(issueRepository *entity.
})

var err error
issueRepository.BaseIssueRepository.UpdatedBy, err = common.GetUserId(ir.database, "S0000000")
issueRepository.BaseIssueRepository.UpdatedBy, err = common.GetCurrentUserId(ir.database)
if err != nil {
l.Error(err)
return nil, NewIssueRepositoryHandlerError("Internal error while updating issueRepository (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/issue_variant/issue_variant_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (iv *issueVariantHandler) CreateIssueVariant(issueVariant *entity.IssueVari
})

var err error
issueVariant.CreatedBy, err = common.GetUserId(iv.database, "S0000000")
issueVariant.CreatedBy, err = common.GetCurrentUserId(iv.database)
if err != nil {
l.Error(err)
return nil, NewIssueVariantHandlerError("Internal error while creating issueVariant (GetUserId).")
Expand Down Expand Up @@ -216,7 +216,7 @@ func (iv *issueVariantHandler) UpdateIssueVariant(issueVariant *entity.IssueVari
})

var err error
issueVariant.UpdatedBy, err = common.GetUserId(iv.database, "S0000000")
issueVariant.UpdatedBy, err = common.GetCurrentUserId(iv.database)
if err != nil {
l.Error(err)
return nil, NewIssueVariantHandlerError("Internal error while updating issueVariant (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/service/service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (s *serviceHandler) CreateService(service *entity.Service) (*entity.Service
})

var err error
service.BaseService.CreatedBy, err = common.GetUserId(s.database, "S0000000")
service.BaseService.CreatedBy, err = common.GetCurrentUserId(s.database)
if err != nil {
l.Error(err)
return nil, NewServiceHandlerError("Internal error while creating service (GetUserId).")
Expand Down Expand Up @@ -201,7 +201,7 @@ func (s *serviceHandler) UpdateService(service *entity.Service) (*entity.Service
})

var err error
service.BaseService.UpdatedBy, err = common.GetUserId(s.database, "S0000000")
service.BaseService.UpdatedBy, err = common.GetCurrentUserId(s.database)
if err != nil {
l.Error(err)
return nil, NewServiceHandlerError("Internal error while updating service (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/support_group/support_group_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (sg *supportGroupHandler) CreateSupportGroup(supportGroup *entity.SupportGr
}

var err error
supportGroup.CreatedBy, err = common.GetUserId(sg.database, "S0000000")
supportGroup.CreatedBy, err = common.GetCurrentUserId(sg.database)
if err != nil {
l.Error(err)
return nil, NewSupportGroupHandlerError("Internal error while creating supportGroup (GetUserId).")
Expand Down Expand Up @@ -181,7 +181,7 @@ func (sg *supportGroupHandler) UpdateSupportGroup(supportGroup *entity.SupportGr
})

var err error
supportGroup.UpdatedBy, err = common.GetUserId(sg.database, "S0000000")
supportGroup.UpdatedBy, err = common.GetCurrentUserId(sg.database)
if err != nil {
l.Error(err)
return nil, NewSupportGroupHandlerError("Internal error while updating supportGroup (GetUserId).")
Expand Down
4 changes: 2 additions & 2 deletions internal/app/user/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (u *userHandler) CreateUser(user *entity.User) (*entity.User, error) {
})

var err error
user.CreatedBy, err = common.GetUserId(u.database, "S0000000")
user.CreatedBy, err = common.GetCurrentUserId(u.database)
if err != nil {
l.Error(err)
return nil, NewUserHandlerError("Internal error while creating user (GetUserId).")
Expand Down Expand Up @@ -149,7 +149,7 @@ func (u *userHandler) UpdateUser(user *entity.User) (*entity.User, error) {
})

var err error
user.UpdatedBy, err = common.GetUserId(u.database, "S0000000")
user.UpdatedBy, err = common.GetCurrentUserId(u.database)
if err != nil {
l.Error(err)
return nil, NewUserHandlerError("Internal error while updating user (GetUserId).")
Expand Down
4 changes: 0 additions & 4 deletions internal/database/mariadb/entity.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// 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
2 changes: 1 addition & 1 deletion internal/database/mariadb/test/database_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (dbm *LocalTestDataBaseManager) NewTestSchema() *mariadb.SqlDatabase {
dbm.Schemas = append(dbm.Schemas, schemaName)
dbm.CurrentSchema = schemaName
dbm.Config.DBName = schemaName
dbm.Config.AuthType = "none" //TODO: move config stuff to e2e/common
dbm.Config.AuthType = "none"

err := dbm.dbClient.SetupSchema(dbm.Config.Config)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions internal/entity/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ type ActivityHasIssue struct {
}

type ActivityAggregations struct {
Metadata
}

type ActivityFilter struct {
Metadata
Paginated
Status []*string `json:"status"`
ServiceCCRN []*string `json:"service_ccrn"`
Expand Down
7 changes: 0 additions & 7 deletions internal/entity/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ type ResultList struct {
}

type ListOptions struct {
Metadata
ShowTotalCount bool `json:"show_total_count"`
ShowPageInfo bool `json:"show_page_info"`
IncludeAggregations bool `json:"include_aggregations"`
Expand All @@ -111,7 +110,6 @@ func NewListOptions() *ListOptions {
}

type PageInfo struct {
Metadata
HasNextPage *bool `json:"has_next_page,omitempty"`
HasPreviousPage *bool `json:"has_previous_page,omitempty"`
IsValidPage *bool `json:"is_valid_page,omitempty"`
Expand All @@ -123,7 +121,6 @@ type PageInfo struct {
}

type Page struct {
Metadata
After *string `json:"after,omitempty"`
PageNumber *int `json:"page_number,omitempty"`
IsCurrent bool `json:"is_current,omitempty"`
Expand All @@ -137,13 +134,11 @@ type List[T interface{}] struct {
}

type TimeFilter struct {
Metadata
After time.Time `json:"after"`
Before time.Time `json:"before"`
}

type Paginated struct {
Metadata
First *int `json:"first"`
After *int64 `json:"from"`
}
Expand All @@ -155,7 +150,6 @@ func MaxPaginated() Paginated {
}

type Severity struct {
Metadata
Value string
Score float64
Cvss Cvss
Expand Down Expand Up @@ -197,7 +191,6 @@ func NewSeverity(url string) Severity {
}

type Cvss struct {
Metadata
Vector string
Base *metric.Base
Temporal *metric.Temporal
Expand Down
2 changes: 0 additions & 2 deletions internal/entity/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ type ComponentResult struct {
}

type ComponentFilter struct {
Metadata
Paginated
CCRN []*string `json:"ccrn"`
Id []*int64 `json:"id"`
ComponentVersionId []*int64 `json:"component_version_id"`
}

type ComponentAggregations struct {
Metadata
}
2 changes: 0 additions & 2 deletions internal/entity/component_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package entity

type ComponentInstanceFilter struct {
Metadata
Paginated
IssueMatchId []*int64 `json:"issue_match_id"`
ServiceId []*int64 `json:"service_id"`
Expand All @@ -16,7 +15,6 @@ type ComponentInstanceFilter struct {
}

type ComponentInstanceAggregations struct {
Metadata
}

type ComponentInstanceResult struct {
Expand Down
2 changes: 0 additions & 2 deletions internal/entity/component_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package entity

type ComponentVersionFilter struct {
Metadata
Paginated
Id []*int64 `json:"id"`
IssueId []*int64 `json:"issue_id"`
Expand All @@ -14,7 +13,6 @@ type ComponentVersionFilter struct {
}

type ComponentVersionAggregations struct {
Metadata
}

type ComponentVersionResult struct {
Expand Down
Loading

0 comments on commit 5cf6406

Please sign in to comment.