Skip to content

Commit

Permalink
feat: implement from and get in get publishers
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-introini committed Oct 20, 2023
1 parent e496d98 commit 1580b13
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
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",

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))
},
},
{
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

0 comments on commit 1580b13

Please sign in to comment.