Code Monkey home page Code Monkey logo

valee-challenge's Introduction

Rest API -SpringBoot-Kotlin πŸ‘₯

🌟This API was built using MySQL as the database, Springboot framework, JPA and kotlin. It provides functionality to create suppliers, load invitations from a CSV file, and retrieve a list of existing invitations πŸ—„οΈ.

Built With

  • Springboot
  • Kotlin
  • MySQL

Prerequisites πŸ“‹

Recommended Tools πŸ› οΈ

Getting Started πŸš€

  • To get a local copy up and running follow these steps.

Installation πŸ’»

Configure the Database Connection πŸ—„οΈ

Before running the server, you need to set up the database connection. Open the application.properties file in the resources folder and modify the following lines to connect to your MySQL database:

## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url = jdbc:mysql://spring.datasource.url?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
spring.datasource.username = your_username
spring.datasource.password = your_password
});

Replace "spring.datasource.url", "your_username" and "your_password" with your actual MySQL database credentials.

Create the supplier table:

 CREATE TABLE supplier (
  id bigint(20) NOT NULL AUTO_INCREMENT,
  name varchar(256) NOT NULL,
  code varchar(45) DEFAULT NULL,
  is_active bit(1) DEFAULT b'1',
  entry_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id)
);

Create the supplier_invitation table along with the foreign key reference to the supplier table:

CREATE TABLE supplier_invitation (
  id bigint(20) NOT NULL AUTO_INCREMENT,
  supplier_id bigint(20) DEFAULT NULL,
  commerce_cell_phone varchar(256) DEFAULT NULL,
  entry_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  FOREIGN KEY (supplier_id) REFERENCES supplier (id)
);

Running the app πŸš€

go to class VaalersApplication.kt an click on the run button

Use API Endpoints πŸ“πŸŒ

  • you can use postman to test the following enpoints:

βœ‰οΈπŸ“ Endpoint: POST /URL: http://localhost:3000/api/v1/invitations

Request Type: POST

Endpoint: /invitation/csv

Request Headers:

Content-Type: multipart/form-data

Accept: application/json

  • Request Body: File CSV: Upload a CSV file containing the invitations (prueba.csv).

  • Response: Status Code: 200 (OK)

  • Example Response:

{
  "code": 0,
  "message": "Invitations loaded successfully"
}

πŸ§‘β€πŸ’Ό Endpoint: POST /URL: http://localhost:3000/api/v1/suppliers:

Method: POST

Request Header:

Summary: Create a new supplier.

Description: This endpoint allows you to create a new supplier and store it in the database.

Parameters: JSON object containing supplier details (name, code).

Request Body:

{
  "name": "company2",
  "code": "PROV147"
}
  • Example Response: Status: 201 Created Body:
{
  "id": 1,
  "name": "company2",
  "code": "PROV147",
  "isActive": true,
  "entryDate": "2023-07-27T12:34:56.000Z"
}

πŸ—‚οΈπŸ“© Endpoint: GET /URL: http://localhost:3000/api/v1/invitations

Request Type: GET

Request Headers:

Accept: application/json

Status: 200 OK

Example Response:

{
  "apiResponse": {
    "code": 0,
    "message": "OK"
  },
  "list": [
    {
      "supplierId": 1,
      "supplierName": "company2",
      "commerceCellPhone": "+123456789012"
    }
    
  ]
}

πŸ•΅οΈβ€β™€οΈβœ… Testing

Unitary tests with Junit

./gradlew test

Contributing 🀝

Contributions are welcome! Please feel free to open a pull request.

valee-challenge's People

Contributors

pipe1098 avatar

Watchers

 avatar

Forkers

shirovox

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.