Coder Social home page Coder Social logo

bishakhne0gi / spring-crud Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 9.0 1.13 MB

A beginner friendly CRUD application built on SpringBoot.

Home Page: https://spring-crud.vercel.app/

Java 46.40% JavaScript 32.73% HTML 0.22% CSS 19.59% Dockerfile 1.06%
apertre24

spring-crud's Introduction

logo
logo logo logo logo logo

What is CRUD?

CRUD stands for Create, Read, Update, and Delete, which are the basic operations that can be performed on data in a database or data storage system. This concept is fundamental to database management and is often used in the context of web development, software engineering, and data management.

logo

Source of this image

In this CRUD application, we are managing an employee list with fields such as firstname, lastname, and email.

Techstack Used

  • Backend:

    • Spring - A comprehensive framework for enterprise Java development.
  • Frontend:

    • React - A popular JavaScript library for building user interfaces.
    • Vite - A fast build tool for modern JavaScript projects.
  • Database:

    • MySQL - A relational database management system.
  • Container:

    • Docker - An open platform for developing, shipping, and running applications.

How does a Spring based CRUD operation works?

A Spring-based CRUD (Create, Read, Update, Delete) operation typically involves creating a web application that performs these basic database operations. Here, I'll provide a simple example using Spring Boot and Spring Data JPA for data persistence.

  1. Create a Spring Boot Project: You can use Spring Initializer (https://start.spring.io/) or your favorite IDE to create a new Spring Boot project. Include the dependencies for "Spring Web" and "Spring Data JPA."

  2. Define Entity Class: Define a class with @Entity to signify a JPA entity, encapsulating data to be stored. This class serves as a blueprint for objects persisted in a database in Spring applications.

@Entity
public class Item {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "email_id")
    private String emailId;
}
  1. Create Repository Interface: Create a repository interface extending JpaRepository for entity CRUD operations. JpaRepository provides pre-built methods for common database operations, simplifying data access code in Spring applications.
import org.springframework.data.jpa.repository.JpaRepository;

@Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
}
  1. Implement Service Layer: Develop a service class that communicates with the repository, encapsulating methods for Create, Read, Update, and Delete (CRUD) operations, providing a clean abstraction for data manipulation in a Spring application.
@Service
public class ItemService {
    private final ItemRepository itemRepository;

    @Autowired
    public ItemService(ItemRepository itemRepository) {
        this.itemRepository = itemRepository;
    }

    public List<Item> getAllItems() {
        return itemRepository.findAll();
    }

    public Optional<Item> getItemById(Long id) {
        return itemRepository.findById(id);
    }

    public Item saveItem(Item item) {
        return itemRepository.save(item);
    }

    public void deleteItem(Long id) {
        itemRepository.deleteById(id);
    }
}
  1. Create Controller: Create a controller class for handling HTTP requests and facilitating communication with the service layer, ensuring seamless interaction between the web interface and backend functionality.
@RestController
@RequestMapping("/items")
public class ItemController {
    private final ItemService itemService;

    @Autowired
    public ItemController(ItemService itemService) {
        this.itemService = itemService;
    }

    @GetMapping
    public List<Item> getAllItems() {
        return itemService.getAllItems();
    }

    @GetMapping("/{id}")
    public Optional<Item> getItemById(@PathVariable Long id) {
        return itemService.getItemById(id);
    }

    @PostMapping
    public Item addItem(@RequestBody Item item) {
        return itemService.saveItem(item);
    }

    @PutMapping("/{id}")
    public Item updateItem(@PathVariable Long id, @RequestBody Item item) {
        item.setId(id);
        return itemService.saveItem(item);
    }

    @DeleteMapping("/{id}")
    public void deleteItem(@PathVariable Long id) {
        itemService.deleteItem(id);
    }
}

This example demonstrates a basic Spring Boot application with CRUD operations using Spring Data JPA. Keep in mind that you may need to configure your database connection properties in the application.properties or application.yml file based on your database choice (e.g., MySQL, PostgreSQL, H2).

ScreenShots of the Application

logo
logo
logo

How to Set Up Locally

  1. Clone the Repository:

    git clone https://github.com/bishakhne0gi/Spring-Crud.git
  2. Setup:

    • Follow these steps to install Docker
    • Open a Terminal inside the root of this repository you just cloned
    • Run docker compose up

    Wait for a few minutes for the Docker Container to build and the application will start automatically.

  3. Access the Application:

    Open your browser and go to http://localhost:5173 to access the CRUD application frontend.

License

This project is licensed under the MIT License.

Conclusion

You have successfully set up the CRUD application locally. Feel free to explore, modify, and enhance the code to suit your needs. If you encounter any issues or have suggestions, please open an issue or create a pull request.

spring-crud's People

Contributors

bishakhne0gi avatar debarshee2004 avatar itsyourap avatar

Watchers

 avatar

spring-crud's Issues

[feat] [backend] Office Inventory

  • An inventory item can have an owner who is an employee
  • An employee can be the owner of multiple inventory items

I would like to implement this feature

[DOCS]: Lack of a README file.

Issue Summary

I noticed that the repository Spring-Crud currently lacks a README.md file. A README file is crucial for providing essential information about the project, its purpose, and how to get started with it. Having a well-documented README.md file is not only helpful for contributors but also for users who come across the repository.

Solution

Writing a proper README.md file which would include:

  • Information about the Project
  • Basic understanding on how it works
  • How to setup the project

I @debarshee2004 would like to take the responsibility of this ISSUE.
Thank you.

Fix Frontend Components Folder Structure

The Frontend Components are haphazardly spread over the component directory. Related components should be placed in their respective directories like:

- component
  └── task
      ├── addTask
      ├── updateTask
      └── taskList

I would like to fix this

feat: [Backend] Employee Attendance

Every company should have an attendance register for their employees to keep track of them. I believe this project should have the feature.

I would like to work on this issue for the back-end!

Kindly please assign me this issue

feat: Tasks assigned to employees

Every company has tasks that are assigned to one or many employees. This project should have the feature.

I would like to work on this feature for the back-end!

Kindly please assign me this issue!

Add new feature : API boxes

Describe the feature you are requesting

Hello Sir,
I want to add some cool badges in this repo like

  • open issues
  • contributor
  • open PR
  • last commites
    this type of cool API badges
    It will be very helpful to showcase the stats of your Repo as well as will attract more contributors.
    Additional context(if any)

image

Are you contributing under any open-source program ?

APERTRE'24

[feat] [backend] Office Events

An office can celebrate different events and this app should keep a log for this.

I would like to implement this feature.

[feat] [backend] Employee Meetings

I would like to add a feature which allows employees to create meetings among themselves.
The meetings will allow only selected employees

[FEAT]: Making the Landing page more better

Description: The current landing page only has a text and a button
Current
scwa-home

Solution: By adding some documentation, explanation, contributors section, footer and some feature it can pop up.

[FEAT]: Adding more information of the employee.

Description: Currently this application only stores the first name, last name and email of the employee which which does not provide enough data to the management.

Proposal: Addition of extra parameters:

  • position of Job
  • DOB and age of the employee
  • which team they are working for
  • how many hours they have worked for.

The idea of the issue is to have enough parameters for the HR or the management team so that they have a proper analysis of the employee.

With the permission of the project admin I @debarshee2004 would like to take responsibility of this Feature(which will include work in the frontend and backend).
Thank You.

Containerize the Whole Application

Setting up this application takes many steps which are overwhelming for beginners.
The best solution to this problem would be to containerize this application using Docker.

I would like to work on this issue.

frontend feature: Tasks assigned to employees

This application does have APIs for CRUD operations of Tasks and assigning Tasks to employees and removing them from tasks but this application lacks the frontend capabilities to do so.

I would like to work on this issue and create a frontend component for adding and managing tasks.

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.