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

Implement from and get in get publishers #216

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions developers-italia.oas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,20 @@ paths:
in: query
name: 'page[after]'
description: Only results after this cursor
- schema:
type: string
format: date-time
example: '2022-06-07T09:56:23Z'
in: query
name: from
description: Only publishers created after this time (RFC 3339 datetime)
- schema:
type: string
format: date-time
example: '2022-06-07T14:56:23Z'
in: query
name: to
description: Only publishers created before this time (RFC 3339 datetime)
post:
summary: Create a new Publisher
description: Create a new Publisher
Expand Down
9 changes: 9 additions & 0 deletions internal/handlers/publishers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ func (p *Publisher) GetPublishers(ctx *fiber.Ctx) error {

stmt := p.db.Preload("CodeHosting")

stmt, err := general.Clauses(ctx, stmt, "")
if err != nil {
return common.Error(
fiber.StatusUnprocessableEntity,
"can't get Publishers",
err.Error(),
)
}

if all := ctx.QueryBool("all", false); !all {
stmt = stmt.Scopes(models.Active)
}
Expand Down
47 changes: 47 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,53 @@ func TestPublishersEndpoints(t *testing.T) {
assert.Equal(t, "wrong cursor format in page[after] or page[before]", response["detail"])
},
},
{
description: `GET with "from" query param`,
query: "GET /v1/publishers?from=2018-11-26T00:56:23Z",
bfabio marked this conversation as resolved.
Show resolved Hide resolved

expectedCode: 200,
expectedContentType: "application/json",
validateFunc: func(t *testing.T, response map[string]interface{}) {
assert.IsType(t, []interface{}{}, response["data"])
data := response["data"].([]interface{})

assert.Equal(t, 13, len(data))
bfabio marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
description: `GET with invalid "from" query param`,
query: "GET /v1/publishers?from=3",

expectedCode: 422,
expectedContentType: "application/problem+json",
validateFunc: func(t *testing.T, response map[string]interface{}) {
assert.Equal(t, `can't get Publishers`, response["title"])
assert.Equal(t, "invalid date time format (RFC 3339 needed)", response["detail"])
},
},
{
description: `GET with "to" query param`,
query: "GET /v1/publishers?to=2018-11-01T09:56:23Z",

expectedCode: 200,
expectedContentType: "application/json",
validateFunc: func(t *testing.T, response map[string]interface{}) {
data := response["data"].([]interface{})

assert.Equal(t, 13, len(data))
},
},
{
description: `GET with invalid "to" query param`,
query: "GET /v1/publishers?to=3",

expectedCode: 422,
expectedContentType: "application/problem+json",
validateFunc: func(t *testing.T, response map[string]interface{}) {
assert.Equal(t, `can't get Publishers`, response["title"])
assert.Equal(t, "invalid date time format (RFC 3339 needed)", response["detail"])
},
},

// GET /publishers/:id
{
Expand Down
Loading