Skip to content

Fadhellya/springboot-postgresql-sample

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Employee Management REST API

Overview

This project provides a simple Employee Management REST API built using Spring Boot and Java 8. The API allows you to perform CRUD (Create, Read, Update, Delete) operations on Employee data.

Prerequisites

  • Java 8
  • Spring Boot
  • PostgreSQL
  • Maven

Environment Variables

Ensure the following environment variables are set before running the application:

DB_HOST=your-database-host
DB_PORT=5432
DB_NAME=your-db-name
SPRING_DATASOURCE_USERNAME=your-db-username
SPRING_DATASOURCE_PASSWORD=your-db-password

Database Configuration (Spring Data Source)

spring.datasource.url=jdbc:${DB_PLATFORM}://${DB_HOST}:${DB_PORT}/${DB_NAME}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
spring.jpa.show-sql=true

## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update

API Endpoints

Get All Employees

Request:

GET /api/v1/employees

Response:

[
  {
    "id": 1,
    "firstName": "John",
    "lastName": "Doe",
    "emailId": "john.doe@example.com"
  }
]

Get Employee by ID

Request:

GET /api/v1/employees/{id}

Response:

{
  "id": 1,
  "firstName": "John",
  "lastName": "Doe",
  "emailId": "john.doe@example.com"
}

Create Employee

Request:

POST /api/v1/employees
Content-Type: application/json

Body:

{
  "firstName": "Jane",
  "lastName": "Smith",
  "emailId": "jane.smith@example.com"
}

Response:

{
  "id": 2,
  "firstName": "Jane",
  "lastName": "Smith",
  "emailId": "jane.smith@example.com"
}

Update Employee

Request:

PUT /api/v1/employees/{id}
Content-Type: application/json

Body:

{
  "firstName": "Jane",
  "lastName": "Doe",
  "emailId": "jane.doe@example.com"
}

Response:

{
  "id": 2,
  "firstName": "Jane",
  "lastName": "Doe",
  "emailId": "jane.doe@example.com"
}

Delete Employee

Request:

DELETE /api/v1/employees/{id}

Response:

{
  "deleted": true
}

For any issues, feel free to open an issue or contribute to the project!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy