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
  • Loading branch information
michalkrzyz committed Sep 26, 2024
1 parent 419e412 commit 94c222f
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 6 deletions.
101 changes: 101 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.

6 changes: 3 additions & 3 deletions internal/api/graphql/graph/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,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
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/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 @@ -34,4 +35,4 @@ enum ActivityStatusValues {
open,
closed,
in_progress
}
}
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
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.Metadata.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
2 changes: 2 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

0 comments on commit 94c222f

Please sign in to comment.