Skip to content

Commit

Permalink
feat(issueMatchChange): add mutations create, update and delete (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
MR2011 authored Jul 8, 2024
1 parent 2d9256c commit 33dc423
Show file tree
Hide file tree
Showing 22 changed files with 1,381 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func IssueMatchChangeBaseResolver(app app.Heureka, ctx context.Context, filter *

edges := []*model.IssueMatchChangeEdge{}
for _, result := range issueMatchChanges.Elements {
imc := model.NewIssueMatchChange(&result)
imc := model.NewIssueMatchChange(result.IssueMatchChange)
edge := model.IssueMatchChangeEdge{
Node: &imc,
Cursor: result.Cursor(),
Expand Down
361 changes: 361 additions & 0 deletions internal/api/graphql/graph/generated.go

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion internal/api/graphql/graph/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func NewIssueMatchEntity(im *IssueMatchInput) entity.IssueMatch {
}
}

func NewIssueMatchChange(imc *entity.IssueMatchChangeResult) IssueMatchChange {
func NewIssueMatchChange(imc *entity.IssueMatchChange) IssueMatchChange {
action := IssueMatchChangeAction(imc.Action)
return IssueMatchChange{
ID: fmt.Sprintf("%d", imc.Id),
Expand All @@ -235,6 +235,17 @@ func NewIssueMatchChange(imc *entity.IssueMatchChangeResult) IssueMatchChange {
}
}

func NewIssueMatchChangeEntity(imc *IssueMatchChangeInput) entity.IssueMatchChange {
action := entity.IssueMatchChangeAction(lo.FromPtr(imc.Action))
issueMatchId, _ := strconv.ParseInt(lo.FromPtr(imc.IssueMatchID), 10, 64)
activityId, _ := strconv.ParseInt(lo.FromPtr(imc.ActivityID), 10, 64)
return entity.IssueMatchChange{
Action: action.String(),
IssueMatchId: issueMatchId,
ActivityId: activityId,
}
}

func NewIssueRepository(repo *entity.IssueRepository) IssueRepository {
createdAt := repo.BaseIssueRepository.CreatedAt.String()
updatedAt := repo.BaseIssueRepository.UpdatedAt.String()
Expand Down
6 changes: 6 additions & 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

mutation ($input: IssueMatchChangeInput!) {
createIssueMatchChange (
input: $input
) {
id
action
issueMatchId
activityId
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

mutation ($id: ID!) {
deleteIssueMatchChange (
id: $id
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

mutation ($id: ID!, $input: IssueMatchChangeInput!) {
updateIssueMatchChange (
id: $id,
input: $input
) {
id
action
issueMatchId
activityId
}
}
40 changes: 40 additions & 0 deletions internal/api/graphql/graph/resolver/mutation.go

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

6 changes: 6 additions & 0 deletions internal/api/graphql/graph/schema/issue_match_change.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ type IssueMatchChange implements Node {
activity: Activity!
}

input IssueMatchChangeInput {
action: IssueMatchChangeActions
issueMatchId: String
activityId: String
}

input IssueMatchChangeFilter {
action: [IssueMatchChangeActions]
}
Expand Down
4 changes: 4 additions & 0 deletions internal/api/graphql/graph/schema/mutation.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type Mutation {
updateIssueMatch(id: ID!, input: IssueMatchInput!): IssueMatch!
deleteIssueMatch(id: ID!): String!

createIssueMatchChange(input: IssueMatchChangeInput!): IssueMatchChange!
updateIssueMatchChange(id: ID!, input: IssueMatchChangeInput!): IssueMatchChange!
deleteIssueMatchChange(id: ID!): String!

createActivity(input: ActivityInput!): Activity!
updateActivity(id: ID!, input: ActivityInput!): Activity!
deleteActivity(id: ID!): String!
Expand Down
3 changes: 3 additions & 0 deletions internal/app/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type Heureka interface {
DeleteIssueMatch(int64) error

ListIssueMatchChanges(filter *entity.IssueMatchChangeFilter, options *entity.ListOptions) (*entity.List[entity.IssueMatchChangeResult], error)
CreateIssueMatchChange(*entity.IssueMatchChange) (*entity.IssueMatchChange, error)
UpdateIssueMatchChange(*entity.IssueMatchChange) (*entity.IssueMatchChange, error)
DeleteIssueMatchChange(int64) error

ListServices(*entity.ServiceFilter, *entity.ListOptions) (*entity.List[entity.ServiceResult], error)
CreateService(*entity.Service) (*entity.Service, error)
Expand Down
60 changes: 60 additions & 0 deletions internal/app/issue_match_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,63 @@ func (h *HeurekaApp) ListIssueMatchChanges(filter *entity.IssueMatchChangeFilter
Elements: res,
}, nil
}

func (h *HeurekaApp) CreateIssueMatchChange(issueMatchChange *entity.IssueMatchChange) (*entity.IssueMatchChange, error) {
l := logrus.WithFields(logrus.Fields{
"event": "app.CreateIssueMatchChange",
"object": issueMatchChange,
})

newIssueMatchChange, err := h.database.CreateIssueMatchChange(issueMatchChange)

if err != nil {
l.Error(err)
return nil, heurekaError("Internal error while creating issueMatchChange.")
}

return newIssueMatchChange, nil
}

func (h *HeurekaApp) UpdateIssueMatchChange(issueMatchChange *entity.IssueMatchChange) (*entity.IssueMatchChange, error) {
l := logrus.WithFields(logrus.Fields{
"event": "app.UpdateIssueMatchChange",
"object": issueMatchChange,
})

err := h.database.UpdateIssueMatchChange(issueMatchChange)

if err != nil {
l.Error(err)
return nil, heurekaError("Internal error while updating issueMatchChange.")
}

imcResult, err := h.ListIssueMatchChanges(&entity.IssueMatchChangeFilter{Id: []*int64{&issueMatchChange.Id}}, &entity.ListOptions{})

if err != nil {
l.Error(err)
return nil, heurekaError("Internal error while retrieving updated issueMatchChange.")
}

if len(imcResult.Elements) != 1 {
l.Error(err)
return nil, heurekaError("Multiple issueMatchChanges found.")
}

return imcResult.Elements[0].IssueMatchChange, nil
}

func (h *HeurekaApp) DeleteIssueMatchChange(id int64) error {
l := logrus.WithFields(logrus.Fields{
"event": "app.DeleteIssueMatchChange",
"id": id,
})

err := h.database.DeleteIssueMatchChange(id)

if err != nil {
l.Error(err)
return heurekaError("Internal error while deleting issueMatchChange.")
}

return nil
}
100 changes: 100 additions & 0 deletions internal/app/issue_match_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,103 @@ var _ = Describe("When listing IssueMatchChanges", Label("app", "ListIssueMatchC
)
})
})

var _ = Describe("When creating IssueMatchChange", Label("app", "CreateIssueMatchChange"), func() {
var (
db *mocks.MockDatabase
heureka app.Heureka
issueMatchChange entity.IssueMatchChange
)

BeforeEach(func() {
db = mocks.NewMockDatabase(GinkgoT())
issueMatchChange = test.NewFakeIssueMatchChange()
})

It("creates issueMatchChange", func() {
db.On("CreateIssueMatchChange", &issueMatchChange).Return(&issueMatchChange, nil)
heureka = app.NewHeurekaApp(db)
newIssueMatchChange, err := heureka.CreateIssueMatchChange(&issueMatchChange)
Expect(err).To(BeNil(), "no error should be thrown")
Expect(newIssueMatchChange.Id).NotTo(BeEquivalentTo(0))
By("setting fields", func() {
Expect(newIssueMatchChange.Action).To(BeEquivalentTo(issueMatchChange.Action))
})
})
})

var _ = Describe("When updating IssueMatchChange", Label("app", "UpdateIssueMatchChange"), func() {
var (
db *mocks.MockDatabase
heureka app.Heureka
issueMatchChange entity.IssueMatchChange
filter *entity.IssueMatchChangeFilter
)

BeforeEach(func() {
db = mocks.NewMockDatabase(GinkgoT())
issueMatchChange = test.NewFakeIssueMatchChange()
first := 10
var after int64
after = 0
filter = &entity.IssueMatchChangeFilter{
Paginated: entity.Paginated{
First: &first,
After: &after,
},
}
})

It("updates issueMatchChange", func() {
db.On("UpdateIssueMatchChange", &issueMatchChange).Return(nil)
heureka = app.NewHeurekaApp(db)
if issueMatchChange.Action == entity.IssueMatchChangeActionAdd.String() {
issueMatchChange.Action = entity.IssueMatchChangeActionRemove.String()
} else {
issueMatchChange.Action = entity.IssueMatchChangeActionAdd.String()
}
filter.Id = []*int64{&issueMatchChange.Id}
db.On("GetIssueMatchChanges", filter).Return([]entity.IssueMatchChange{issueMatchChange}, nil)
updatedIssueMatchChange, err := heureka.UpdateIssueMatchChange(&issueMatchChange)
Expect(err).To(BeNil(), "no error should be thrown")
By("setting fields", func() {
Expect(updatedIssueMatchChange.Action).To(BeEquivalentTo(issueMatchChange.Action))
})
})
})

var _ = Describe("When deleting IssueMatchChange", Label("app", "DeleteIssueMatchChange"), func() {
var (
db *mocks.MockDatabase
heureka app.Heureka
id int64
filter *entity.IssueMatchChangeFilter
)

BeforeEach(func() {
db = mocks.NewMockDatabase(GinkgoT())
id = 1
first := 10
var after int64
after = 0
filter = &entity.IssueMatchChangeFilter{
Paginated: entity.Paginated{
First: &first,
After: &after,
},
}
})

It("deletes issueMatchChange", func() {
db.On("DeleteIssueMatchChange", id).Return(nil)
heureka = app.NewHeurekaApp(db)
db.On("GetIssueMatchChanges", filter).Return([]entity.IssueMatchChange{}, nil)
err := heureka.DeleteIssueMatchChange(id)
Expect(err).To(BeNil(), "no error should be thrown")

filter.Id = []*int64{&id}
issueMatchChanges, err := heureka.ListIssueMatchChanges(filter, &entity.ListOptions{})
Expect(err).To(BeNil(), "no error should be thrown")
Expect(issueMatchChanges.Elements).To(BeEmpty(), "no error should be thrown")
})
})
3 changes: 3 additions & 0 deletions internal/database/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type Database interface {
GetIssueMatchChanges(*entity.IssueMatchChangeFilter) ([]entity.IssueMatchChange, error)
GetAllIssueMatchChangeIds(*entity.IssueMatchChangeFilter) ([]int64, error)
CountIssueMatchChanges(filter *entity.IssueMatchChangeFilter) (int64, error)
CreateIssueMatchChange(*entity.IssueMatchChange) (*entity.IssueMatchChange, error)
UpdateIssueMatchChange(*entity.IssueMatchChange) error
DeleteIssueMatchChange(int64) error

GetServices(*entity.ServiceFilter) ([]entity.Service, error)
GetAllServiceIds(*entity.ServiceFilter) ([]int64, error)
Expand Down
10 changes: 10 additions & 0 deletions internal/database/mariadb/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,16 @@ func (imcr *IssueMatchChangeRow) AsIssueMatchChange() entity.IssueMatchChange {
}
}

func (imcr *IssueMatchChangeRow) FromIssueMatchChange(imc *entity.IssueMatchChange) {
imcr.Id = sql.NullInt64{Int64: imc.Id, Valid: true}
imcr.IssueMatchId = sql.NullInt64{Int64: imc.IssueMatchId, Valid: true}
imcr.ActivityId = sql.NullInt64{Int64: imc.ActivityId, Valid: true}
imcr.Action = sql.NullString{String: imc.Action, Valid: true}
imcr.CreatedAt = sql.NullTime{Time: imc.CreatedAt, Valid: true}
imcr.DeletedAt = sql.NullTime{Time: imc.DeletedAt, Valid: true}
imcr.UpdatedAt = sql.NullTime{Time: imc.UpdatedAt, Valid: true}
}

type OwnerRow struct {
ServiceId sql.NullInt64 `db:"owner_service_id" json:"service_id"`
UserId sql.NullInt64 `db:"owner_user_id" json:"user_id"`
Expand Down
Loading

0 comments on commit 33dc423

Please sign in to comment.