GithubHelp home page GithubHelp logo

danvinicius / simplified-picpay-challenge Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 85 KB

API built using Java and Spring Boot for the Simplified PicPay Backend Challenge

Java 100.00%
java picpay spring-boot hibernate jpa junit mockito

simplified-picpay-challenge's Introduction

About

API built using Java and Java Spring for the Simplified PicPay Backend Challenge.
The aim of this project is to practice Java and Spring Framework.

Java Spring

Simplified PicPay challenge

๐Ÿšง Under development ๐Ÿšง


Installation

  1. Clone the repository:
git clone https://github.com/danvinicius/simplified-picpay-challenge.git
  1. Install dependencies with Maven

  2. Update application.properties puting your H2 credentials and endpoints offered by PicPay for mocking transactions authorization and notification:

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true

picpay.authorizerService.url=https://run.mocky.io/v3/5794d450-d2e2-4412-8131-73d0293ac1cc
picpay.notificationService.url=https://run.mocky.io/v3/54dc2cf1-3add-45b5-b5a9-6bf7e7f1f4a6

Usage

  1. Start the application with Maven
  2. The API will be accessible at http://localhost:8080

Endpoints

1. Creates an user

Endpoint: POST /api/user

Request:

POST /api/user
Content-Type: application/json

{
    "email": "[email protected]",
    "firstName": "first name",
    "lastName": "last name",
    "document": "123456789-0",
    "password": "1234",
    "type": "COMMON/MERCHANT",
    "balance": 50000
}

Response:

200 OK
Content-Type: application/json

{
    "id": 1,
    "email": "[email protected]",
    "firstName": "first name",
    "lastName": "last name",
    "document": "123456789-0",
    "password": "1234",
    "type": "COMMON/MERCHANT",
    "balance": 500000
}

Error:

An error may occur user's e-mail or document are already registered.

Response:

400 BAD REQUEST
Content-Type: application/json

{
    "message": "User already exists",
    "statusCode": 400
}

2. Lists all users

Endpoint: GET /api/user

Request:

GET /api/user
Content-Type: application/json

Response:

200 OK
Content-Type: application/json

[
  {
    "id": 1,
    "email": "[email protected]",
    "firstName": "first name",
    "lastName": "last name",
    "document": "123456789-0",
    "password": "1234",
    "type": "COMMON/MERCHANT",
    "balance": 500000
  },
  ...
]

3. Creates an transaction

Endpoint: POST /api/transaction

Request:

POST /api/transaction
Content-Type: application/json

{
    "receiverId": 1,
    "senderId": 2,
    "amount": 10000
}

Response:

200 OK
Content-Type: application/json

{
    "id": 1,
    "receiverId": 1,
    "senderId": 2,
    "amount": 10000,
    "sender": {
      "id": 1,
      "email": "[email protected]",
      "firstName": "first name",
      "lastName": "last name",
      "document": "123456789-0",
      "password": "1234",
      "type": "COMMON",
      "balance": 490000
    },
    "receiver": {
      "id": 1,
      "email": "[email protected]",
      "firstName": "first name",
      "lastName": "last name",
      "document": "123456789-0",
      "password": "1234",
      "type": "COMMON/MERCHANT",
      "balance": 510000
    }
}

Errors:

An error may occur if sender or receiver users are not found

Response:

404 NOT FOUND
Content-Type: application/json

{
    "message": "User not found",
    "statusCode": 404
}

An error may occur if sender is an merchant user

Response:

401 UNAUTHORIZED
Content-Type: application/json

{
    "message": "Merchant user cannot make transactions",
    "statusCode": 401
}

An error may occur if sender has isufficient balance

Response:

401 UNAUTHORIZED
Content-Type: application/json

{
    "message": "Insufficient balance",
    "statusCode": 401
}

An error may occur if external PicPay authorization service returns false

Response:

401 UNAUTHORIZED
Content-Type: application/json

{
    "message": "Unauthorized transaction",
    "statusCode": 401
}

Install GIT and Java on your computer.

simplified-picpay-challenge's People

Contributors

danvinicius avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.