Giter Site home page Giter Site logo

listing-manager's Introduction

Online Advertising Service - Listing Management REST Service

This project is a REST service for managing listings for an online advertising service. It provides endpoints to perform following operations on listings :

  • Create a listing
  • Update a listing
  • Get listings of a dealer with a given state
  • Publish a listing
  • Unpublish a listing

Technologies

Getting Started

Follow these instructions to get the project up and running on your local machine.

Prerequisites

  • Java JDK 11
  • Gradle 7.6 or higher
  • PostgreSQL Database installed and running

Database Setup

  1. Create a new database using pgAdmin gui or you can run the following SQL command in psql:
CREATE DATABASE "listing-manager"
   WITH
   OWNER = postgres
   ENCODING = 'UTF8'
   LC_COLLATE = 'fr_FR.UTF-8'
   LC_CTYPE = 'fr_FR.UTF-8'
   TABLESPACE = pg_default
   CONNECTION LIMIT = -1
   IS_TEMPLATE = False; 
  1. Create the necessary tables in the database following SQL command below :
CREATE TABLE IF NOT EXISTS public.dealer(
        id serial NOT NULL,
        name character varying(158) NOT NULL,
        CONSTRAINT dealer_pk PRIMARY KEY (id)
        );
		
		
CREATE TABLE IF NOT EXISTS public.tier_limit(
        dealer_id integer NOT NULL,
	    listing_limit integer NOT NULL,
        created_at timestamp(6) without time zone NOT NULL DEFAULT now(),
    CONSTRAINT tier_limit_pk PRIMARY KEY (dealer_id),
	CONSTRAINT tier_limit_fk FOREIGN KEY (dealer_id)
        REFERENCES dealer (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        );


CREATE TABLE IF NOT EXISTS public.listing(
	
        id serial NOT NULL,
        dealer_id integer NOT NULL,
	    vehicule character varying(255) NOT NULL,
        price bigint NOT NULL,
        created_at timestamp(6) without time zone NOT NULL DEFAULT now(),
        state character varying(158) NOT NULL,
        CONSTRAINT listing_pk PRIMARY KEY (id),
	CONSTRAINT listing_fk FOREIGN KEY (dealer_id)
        REFERENCES dealer (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        );
  1. Update the database configuration in the application.properties file located in the src/main/resources directory. Replace the placeholders with your database credentials:
spring.datasource.url=jdbc:postgresql://localhost:5433/listing-manager
spring.datasource.username=postgres
spring.datasource.password=postgres
  1. Update the database configuration in build.gradle for JOOQ sources generations:
        .withDriver("org.postgresql.Driver")
        .withUrl("jdbc:postgresql://localhost:5433/listing-manager")
        .withUser("postgres")
        .withPassword("postgres"))

Installation

  1. Clone the repository :
https://github.com/Mr-abdoulraouf/listing-manager.git
  1. Navigate to the project directory and build the project using Gradle:
cd listing-manager
gradle compileJava
  1. Generate jOOQ sources from the main jOOQ configuration in build.gradle
gradle generate

JOOQ sources code will be generated in src/main/java/com/agency36/listing/model 4. Run the application:

gradle bootRun

The REST service will be accessible at http://localhost:8080/api/. 5. The project includes unit tests to ensure the functionality of the REST service. You can run the tests by using the command below :

gradle test
  1. Build the application for production.
gradle build

The build jar will be located in build/libs/

Exception Handling

The REST service includes basic error handling. If an unexpected exception occurs, the service will return NOT_FOUND HTTP response with an error message.

Rest APIs Endpoints

The important APIs endpoints are as follows :

GET /api/listing/{dealerId}/{state} : Retrieves listings by dealer ID and state (draft or published).

POST /api/listing/save : Creates a new listing.

PUT /api/listing/update/{listingId} : Updates a listing by ID.

PUT /api/listing/publish/{listingId} : Publishes a listing by ID.

PUT /api/listing/unpublish/{listingId}: Unpublishes a listing by ID.

listing-manager's People

Contributors

mr-abdoulraouf 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.