Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 143: Remove null fields from api responses #86

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ linters:
- gofmt
- whitespace
- govet
issues:
exclude:
- composite
15 changes: 15 additions & 0 deletions docs/openapi/Models/api.RepositoryResponseJSON.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# api.RepositoryResponseJSON
## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
| **account\_id** | **String** | Account ID of the owner | [optional] [default to null] |
| **distribution\_arch** | **String** | Architecture to restrict client usage to | [optional] [default to null] |
| **distribution\_versions** | **List** | Versions to restrict client usage to | [optional] [default to null] |
| **name** | **String** | Name of the remote yum repository | [optional] [default to null] |
| **org\_id** | **String** | Organization ID of the owner | [optional] [default to null] |
| **url** | **String** | URL of the remote yum repository | [optional] [default to null] |
| **uuid** | **String** | UUID of the object | [optional] [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

2 changes: 1 addition & 1 deletion pkg/api/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type RepositoryRequest struct {
}

type RepositoryBulkCreateResponse struct {
ErrorMsg *string `json:"error"` // Error during creation
ErrorMsg string `json:"error"` // Error during creation
Repository *RepositoryResponse `json:"repository"` // Repository object information
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/dao/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r repositoryDaoImpl) bulkCreate(tx *gorm.DB, newRepositories []api.Reposit
dbErr = DBErrorToApi(err)
errMsg := dbErr.Error()
result[i] = api.RepositoryBulkCreateResponse{
ErrorMsg: &errMsg,
ErrorMsg: errMsg,
Repository: nil,
}
tx.RollbackTo("beforecreate")
Expand All @@ -117,7 +117,7 @@ func (r repositoryDaoImpl) bulkCreate(tx *gorm.DB, newRepositories []api.Reposit
dbErr = DBErrorToApi(err)
errMsg := dbErr.Error()
result[i] = api.RepositoryBulkCreateResponse{
ErrorMsg: &errMsg,
ErrorMsg: errMsg,
Repository: nil,
}
tx.RollbackTo("beforecreate")
Expand All @@ -128,7 +128,7 @@ func (r repositoryDaoImpl) bulkCreate(tx *gorm.DB, newRepositories []api.Reposit
response.URL = newRepos[i].URL
if dbErr == nil {
result[i] = api.RepositoryBulkCreateResponse{
ErrorMsg: nil,
ErrorMsg: "",
Repository: &response,
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/repository_rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (rh *RepositoryRpmHandler) searchRpmPreprocessInput(input *api.SearchRpmReq
// @Produce json
// @Param uuid path string true "Identifier of the Repository"
// @Success 200 {object} api.RepositoryRpmCollectionResponse
// @Router /repositories/:uuid/rpms [get]
// @Router /repositories/{uuid}/rpms [get]
func (rh *RepositoryRpmHandler) listRepositoriesRpm(c echo.Context) error {
// Read input information
var rpmInput RepositoryRpmRequest
Expand Down
21 changes: 13 additions & 8 deletions pkg/handler/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/content-services/content-sources-backend/pkg/dao"
"github.com/content-services/content-sources-backend/pkg/db"
"github.com/labstack/echo/v4"
"github.com/openlyinc/pointy"
"github.com/redhatinsights/platform-go-middlewares/identity"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -494,12 +493,18 @@ func (suite *ReposSuite) TestBulkCreate() {

expected := []api.RepositoryBulkCreateResponse{
{
ErrorMsg: nil,
Repository: &api.RepositoryResponse{Name: "repo_1", URL: "https://example1.com"},
ErrorMsg: "",
Repository: &api.RepositoryResponse{
Name: "repo_1",
URL: "https://example1.com",
},
},
{
ErrorMsg: nil,
Repository: &api.RepositoryResponse{Name: "repo_2", URL: "https://example2.com"},
ErrorMsg: "",
Repository: &api.RepositoryResponse{
Name: "repo_2",
URL: "https://example2.com",
},
},
}

Expand Down Expand Up @@ -543,11 +548,11 @@ func (suite *ReposSuite) TestBulkCreateOneFails() {

expected := []api.RepositoryBulkCreateResponse{
{
ErrorMsg: nil,
ErrorMsg: "",
Repository: nil,
},
{
ErrorMsg: pointy.String("Bad validation"),
ErrorMsg: "Bad validation",
Repository: nil,
},
}
Expand Down Expand Up @@ -576,7 +581,7 @@ func (suite *ReposSuite) TestBulkCreateOneFails() {
var response []api.RepositoryBulkCreateResponse
err = json.Unmarshal(body, &response)
assert.Nil(t, err)
assert.Nil(t, response[0].ErrorMsg)
assert.Equal(t, "", response[0].ErrorMsg)
assert.Nil(t, response[0].Repository)
assert.NotNil(t, response[1].ErrorMsg)
assert.Nil(t, response[1].Repository)
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/repository_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (rc *RepositoryConfiguration) BeforeUpdate(tx *gorm.DB) error {

func (rc *RepositoryConfiguration) DedupeVersions(tx *gorm.DB) error {
var versionMap = make(map[string]bool)
var unique pq.StringArray
var unique = make(pq.StringArray, 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this prevents distribution versions from returning null

for i := 0; i < len(rc.Versions); i++ {
if _, found := versionMap[rc.Versions[i]]; !found {
versionMap[rc.Versions[i]] = true
Expand Down