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

[#175441170] Add Organization and Service logo's upload #110

Merged
merged 10 commits into from
Nov 20, 2020

Conversation

infantesimone
Copy link
Contributor

@infantesimone infantesimone commented Nov 9, 2020

This PR introduces two new endpoints, according to the following definition:

/services/{service_id}/logo:
    parameters:
      - name: service_id
        in: path
        type: string
        required: true
        description: The ID of an existing Service.
    put:
      summary: Upload service logo.
      description: |
        Upsert a logo for an existing service.
      parameters:
        - name: body
          in: body
          required: true
          schema:
            $ref: "#/definitions/Logo"
          description: A base64 string representation of the service logo PNG image.
            It can be the service own logo or the organization logo.
      responses:
        "200":
          description: Logo uploaded.
        "400":
          description: Invalid payload.
        "401":
          description: Unauthorized.
        "403":
          description: Forbidden.
        "404":
          description: No service found for the provided ID.
        "500":
          description: The service logo cannot be uploaded.
/organizations/{organization_fiscal_code}/logo:
     - name: organization_fiscal_code
        in: path
        type: string
        required: true
        description: organization fiscal code.
    put:
      summary: Upload organization logo.
      description: |
        Upsert a logo for an Organization.
      parameters:
        - name: body
          in: body
          required: true
          schema:
            $ref: "#/definitions/Logo"
          description: A base64 string representation of the organization logo PNG image.
      responses:
        "202":
          description: Logo uploaded.
        "400":
          description: Invalid payload
        "401":
          description: Unauthorized.
        "403":
          description: Forbidden.
        "429":
          description: Too many requests.
        "500":
          description: The organization logo cannot be uploaded.
  Logo:
    type: object
    properties:
      logo:
        type: string
        format: byte
        minLength: 1
    required:
      - logo

@pagopa-github-bot
Copy link
Contributor

pagopa-github-bot commented Nov 9, 2020

Affected stories

  • 🌟 #175441170: Come ADM, vorrei poter caricare i loghi di servizi e organizzazioni, in modo autonomo, dal developer portal

New dependencies added: @types/jest, jest and ts-jest.

@types/jest

Author: Unknown

Description: TypeScript definitions for Jest

Homepage: http://npmjs.com/package/@types/jest

Createdover 4 years ago
Last Updated3 days ago
LicenseMIT
Maintainers1
Releases143
Direct Dependenciesjest-diff and pretty-format
README

Installation

npm install --save @types/jest

Summary

This package contains type definitions for Jest (https://jestjs.io/).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest.

Additional Details

  • Last updated: Tue, 20 Oct 2020 07:15:43 GMT
  • Dependencies: @types/jest-diff, @types/pretty-format
  • Global values: afterAll, afterEach, beforeAll, beforeEach, describe, expect, fail, fdescribe, fit, it, jasmine, jest, pending, spyOn, test, xdescribe, xit, xtest

Credits

These definitions were written by Asana (https://asana.com)
// Ivo Stratev
, jwbay, Alexey Svetliakov, Alex Jover Morales, Allan Lukwago, Ika, Waseem Dahman, Jamie Mason, Douglas Duteil, Ahn, Josh Goldberg, Jeff Lau, Andrew Makarov, Martin Hochel, Sebastian Sebald, Andy, Antoine Brault, Gregor Stamać, ExE Boss, Alex Bolenok, Mario Beltrán Alarcón, Tony Hallett, Jason Yu, Devansh Jethmalani, Pawel Fajfer, and Regev Brody.

jest

Author: Unknown

Description: Delightful JavaScript Testing.

Homepage: https://jestjs.io/

Createdover 8 years ago
Last Updated15 days ago
LicenseMIT
Maintainers8
Releases261
Direct Dependencies@jest/core, import-local and jest-cli
Keywordsava, babel, coverage, easy, expect, facebook, immersive, instant, jasmine, jest, jsdom, mocha, mocking, painless, qunit, runner, sandboxed, snapshot, tap, tape, test, testing, typescript and watch
README

Jest

🃏 Delightful JavaScript Testing

  • 👩🏻‍💻 Developer Ready: Complete and ready to set-up JavaScript testing solution. Works out of the box for any React project.

  • 🏃🏽 Instant Feedback: Failed tests run first. Fast interactive mode can switch between running all tests or only test files related to changed files.

  • 📸 Snapshot Testing: Jest can capture snapshots of React trees or other serializable values to simplify UI testing.

Read More: https://jestjs.io/

ts-jest

Author: Kulshekhar Kabra

Description: A preprocessor with source maps support to help use TypeScript with Jest

Homepage: https://kulshekhar.github.io/ts-jest

Createdabout 4 years ago
Last Updated8 days ago
LicenseMIT
Maintainers3
Releases133
Direct Dependencies@types/jest, bs-logger, buffer-from, fast-json-stable-stringify, jest-util, json5, lodash.memoize, make-error, mkdirp, semver and yargs-parser
Keywordsjest, typescript, sourcemap, react and testing

Generated by 🚫 dangerJS

src/app.ts Outdated
withRequestMiddlewares(
getApiClientMiddleware(),
getUserFromRequestMiddleware(),
RequiredParamMiddleware("serviceId", NonEmptyString),
Copy link

Choose a reason for hiding this comment

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

Can we use ServiceId as type instead of NonEmptyString ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

src/app.ts Outdated
withRequestMiddlewares(
getApiClientMiddleware(),
getUserFromRequestMiddleware(),
RequiredParamMiddleware("organizationFiscalCode", NonEmptyString),
Copy link

Choose a reason for hiding this comment

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

Can we use ÒrganizationFiscalCode as type ?

Comment on lines 247 to 252
.chain(user =>
checkAdminTask(user).chain(() =>
uploadOrganizationLogoTask(organizationFiscalCode, serviceLogo).map(
result => result
)
)
Copy link

Choose a reason for hiding this comment

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

Can we flat this chain's pipeline ? i.e:

Suggested change
.chain(user =>
checkAdminTask(user).chain(() =>
uploadOrganizationLogoTask(organizationFiscalCode, serviceLogo).map(
result => result
)
)
.chain(user =>
checkAdminTask(user)
).chain(() =>
uploadOrganizationLogoTask(organizationFiscalCode, serviceLogo)
)

return getApimUserTask(apiClient, authenticatedUser)
.chain(user =>
checkAdminTask(user).chain(() =>
uploadOrganizationLogoTask(organizationFiscalCode, serviceLogo).map(
Copy link

Choose a reason for hiding this comment

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

Why map without change right's value?

Comment on lines 45 to 52
response.isSome()
? taskEither.of(response.value)
: fromLeft(
ResponseErrorNotFound(
"API user not found",
"Cannot find a user in the API management with the provided email address"
)
)
Copy link

Choose a reason for hiding this comment

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

Since response is an option we should name it as maybeResponse. Aside can we use fold?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks,
fold is better.

).foldTaskEither(
error => fromLeft(error),
errorOrResponse =>
errorOrResponse && errorOrResponse.status === 201
Copy link

Choose a reason for hiding this comment

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

Could errorOrResponse be undefined ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, can be undefined according to uploadServiceLogo defined in api_client.ts.

Copy link

Choose a reason for hiding this comment

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

Ok so if it can ben undefined, maybe we can wrap it into an option with fromNullable :)

Copy link

Choose a reason for hiding this comment

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

That's something that does not sound good to me. I think that the response body could be undefined, so the entire either errorOrResponse could not imho.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The methods defined in api-client.ts return :

  • Promise<IResponseType<404, Error, never> | ... 4 more ... | undefined>
    so the entire errorOrResponse can be undefined.
    The code to avoid undefined could impact all methods of api-client.ts (maybe we could do it in a dedicated PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To use this definition I have to change apiResponseDecodeer, or maybe I create one to use only for new methods ?

Copy link

Choose a reason for hiding this comment

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

The first one :). Let's keep in mind that probably we should use io-utils to generate clients in this project cc @balanza @gunzip

Copy link
Contributor Author

@infantesimone infantesimone Nov 11, 2020

Choose a reason for hiding this comment

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

In this project there is already a client that is not generated with io-utils. I added the service to this but the problem is that in case of 400, the body is decoded as Error while in the model generated with io-utils is decoded as ProblemJson.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However undefined depends on how the client is defined in this project, there is a utility method that does a similar thing:

export function toEither<T>(

Copy link

Choose a reason for hiding this comment

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

Ok, for the moment let's use the utility to avoid directly check undefined response. Btw, when it's possible, we have to do another PR with io-utils upgrade 👍

).foldTaskEither(
err => fromLeft(err),
errorOrResponse =>
errorOrResponse && errorOrResponse.status === 201
Copy link

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, (as for uploadServiceLogo) can be undefined according to uploadOrganizationLogo defined in api_client.ts.

Copy link

Choose a reason for hiding this comment

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

ditto

@AleDore
Copy link

AleDore commented Nov 11, 2020

ping :)

@balanza
Copy link
Contributor

balanza commented Nov 19, 2020

ping :)

👆

@infantesimone
Copy link
Contributor Author

if it's ok as I used fromnullable, the pr is done

@gunzip
Copy link
Contributor

gunzip commented Nov 19, 2020

needs rebasing (see conflicts)

Copy link

@AleDore AleDore left a comment

Choose a reason for hiding this comment

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

LGTM, fromNullable it's ok for now.

@gunzip gunzip merged commit 4e2dc01 into master Nov 20, 2020
@gunzip gunzip deleted the 175441170-upload-logo branch November 20, 2020 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants