Code Monkey home page Code Monkey logo

moderan-springboot-api's Introduction

Moderan Home Task

A simple api task for moderan using Java Spring Boot

๐Ÿšฉ Table of Contents

Installation ๐Ÿ’ป

Follow these steps:

1. Clone the project

git clone [email protected]:ashfaqshuvo007/moderan-springboot-api.git

2. DB Setup (Postgres)

  • login to Postgres Open your terminal and type the following command
psql -d postgres -U postgres -W

Enter your password when prompted.

  • Create a new Database
CREATE DATABASE myDatabase WITH ENCODING 'UTF8' LC_COLLATE='English_United Kingdom' LC_CTYPE='English_United Kingdom';
  • Create a new User
CREATE USER user_name WITH ENCRYPTED PASSWORD 'mypassword';
  • Grant all privileges to the user for the new database
GRANT ALL PRIVILEGES on DATABASE myDatabase to user_name;

2.Application.Properties file

  • Copy the following into application.properties file

spring.sql.init.mode = always
spring.sql.init.platform = postgres
spring.datasource.url = jdbc:postgresql://localhost:5432/moderan
spring.datasource.username = moderan
spring.datasource.password = moderan
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
spring.jpa.defer-datasource-initialization = true
spring.jpa.show-sql=true

#server port
server.port=8888

# Banner
spring.banner.location=classpath:banner.txt

Usage

1.Build and Run the project

We have used gradle for this project.

gradle bootRun

It will start the server at port 8888 as mentioned in the application.properties file. If you want you can change it to your convinience. Also it will create necessary databases and Put One user inside users tables as admin.

This is just to handle some permissions for our main api routes.

For Person package

You can look at Person Folder

API routes

I have used thunder client of Vscode but you use your browser or POSTMAN to test the endpoints.

Authentication

For authentication, we have used a Basic Auth (username & password): localhost:8888/auth return a user json object with details. You are authenticated.

  • Auth route setup

Auth Setup

  • Response

Response

We have two main routes:

  1. To save a Person "/person" POST METHOD permitted only to users with role ADMIN
  • POST url and input body. It takes a json in the following format

Route url and input

  • Response: returns a new created Person Object with timestamp and id.

response

  1. To retrieve list of records matching a search string a Person "/person?search=John" GET METHOD permitted to ALL Let's say we want to retrieve all rows of data with 'John' in any column. We put a query parameter 'search' and its value as 'John'
  • GET url and input body. It takes a json in the following format

Search url and input

  • Response: returns a json list of all the records with 'John'

Response

Testing

I implemented a simple test which you can find here

Improvements:

  • I would have loved to have more tests(Unit and integration test with Mockito)
  • Error Handling can be much better with custom Error handlers
  • Implementing CORS for the endpoints

Author

Ashfaq Hussain Ahmed

License

MIT

moderan-springboot-api's People

Contributors

ashfaqshuvo007 avatar

Watchers

James Cloos avatar  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.