# All# python# wedfg# scope variable# interview# lexical environment# javascript# #algorithm# hoisting# good# print# java# coding shortcut# competitive coding# shorthand# loop tricks# sample# #c# gambling# primitives# algoritms# arrow-functions# javascriptintro# usefullinks# technical round# project# beetroot# reverse# array# copy# collection# test# i am printing hello world# #class# #js# #interview# map# lodash# scoping# async# prime numbers# python journey# weather app# easy way to remove duplicates# # #javascript# pho# possible ways of calculator app# var a = 10 function f(){ console.log(a) } f(); console.log(a);# gg# bank# as# palindrome# hello world basic intro# #python# pattern program# nodejs# key# concept of var, let and const# #helloworld# please give better ans# php# hello world# code review# string# d# javascript functions# php loop# s# fusionauth# c++# helloworld# hello, world# forloop# slice# adding two numbers# diamond# @python3# #python3# arraylistcourceimplemetnation# cpp# work# auto screenshot# #dsa# #recursion# #array# #java# bday# int number; : this line declares a variable to store the integer input the user# game# woocommerce# some testing publish# ios# test_idea# cliq# linkedlist# basic# typescript# image# tutorial to show some usage of the class arraylist# dart# test task# function# prints 'hello world in console# miu# final# python relationship between boolean and members ships operators# relationship between casesentive and indexing# wqdwef# f# sde# testing# week8# hi# game hangman java# wordpress# nginx# server# index.php# #loops #itreation # for #range #def# tmp# first# laravel# mysql# jquery# html# sockets# mutex# message# process# threads# c# os# system calls# kill# 19# reader writer# semaphores# mutual exclusion# concurrency# deadlock# phonepe# thread program# java-linked-list# loops# programming basics# functions# beginner coding# junit# hello world program# hangman# goldman# resolved class not found exception# kotlin# lld# asa# pyrhon recrusion# @hello# hash table# bank management system# firstoccurrence# python financial analysis finance profit calculation data analysis# asas# suggested tags javascript function console log hello world programming basics# python function loop hello world code basics# calculator# it is about cost price and selling price.# #profit# #hello# dvoen# rachana# simple_interest_calculator.py# god's plan# #new# javascript ,# pomgromming# beginner code# 5555# output# beginner friendly# school# console.# spring# review# boot# accounting test system glitch# #work# spring boot# rest api# backend development# web services

Latest from community today

//user
                permissions.add(new Permission("Create a user", "/api/v1/users", "POST", "USERS"));
                permissions.add(new Permission("Update a user", "/api/v1/users/{id}", "PUT", "USERS"));
                permissions.add(new Permission("Delete a user", "/api/v1/users/{id}", "DELETE", "USERS"));
                permissions.add(new Permission("Get a user", "/api/v1/users/{id}", "GET", "USERS"));
                permissions.add(new Permission("Get all users", "/api/v1/users", "GET", "USERS"));
                //role
                permissions.add(new Permission("Create a role", "/api/v1/roles", "POST", "ROLES"));
                permissions.add(new Permission("Update a role", "/api/v1/roles/{id}", "PUT", "ROLES"));
                permissions.add(new Permission("Delete a role", "/api/v1/roles/{id}", "DELETE", "ROLES"));
                permissions.add(new Permission("Get a role", "/api/v1/roles/{id}", "GET", "ROLES"));
                permissions.add(new Permission("Get all roles", "/api/v1/roles", "GET", "ROLES"));
                // permission
                permissions.add(new Permission("Create a permission", "/api/v1/permissions", "POST", "PERMISSIONS"));
                permissions.add(new Permission("Update a permission", "/api/v1/permissions/{id}", "PUT", "PERMISSIONS"));
                permissions.add(new Permission("Delete a permission", "/api/v1/permissions/{id}", "DELETE", "PERMISSIONS"));
                permissions.add(new Permission("Get a permissions", "/api/v1/permissions/{id}", "GET", "PERMISSIONS"));
                permissions.add(new Permission("Get all permissions", "/api/v1/permissions", "GET", "PERMISSIONS"));
                // products
                permissions.add(new Permission("Create a product", "/api/v1/products", "POST", "PRODUCTS"));
                permissions.add(new Permission("Update a product", "/api/v1/products/{id}", "PUT", "PRODUCTS"));
                permissions.add(new Permission("Delete a product", "/api/v1/products/{id}", "DELETE", "PRODUCTS"));
                permissions.add(new Permission("Get a products", "/api/v1/products/{id}", "GET", "PRODUCTS"));
                permissions.add(new Permission("Get all products", "/api/v1/products", "GET", "PRODUCTS"));
                permissions.add(new Permission("Get a products by admin", "/api/v1/admin/products/{id}", "GET", "PRODUCTS"));
                permissions.add(new Permission("Get all products by admin", "/api/v1/admin/products", "GET", "PRODUCTS"));
                //category
                permissions.add(new Permission("Create a category", "/api/v1/categories", "POST", "CATEGORIES"));
                permissions.add(new Permission("Update a category", "/api/v1/categories/{id}", "PUT", "CATEGORIES"));
                permissions.add(new Permission("Delete a category", "/api/v1/categories/{id}", "DELETE", "CATEGORIES"));
                permissions.add(new Permission("Get a category", "/api/v1/categories/{id}", "GET", "CATEGORIES"));
                permissions.add(new Permission("Get all categories", "/api/v1/categories", "GET", "CATEGORIES"));
                permissions.add(new Permission("Get a category by admin", "/api/v1/admin/categories/{id}", "GET", "CATEGORIES"));
                permissions.add(new Permission("Get all categories by admin", "/api/v1/admin/categories", "GET", "CATEGORIES"));

                // address
                permissions.add(new Permission("Create a address", "/api/v1/addresses", "POST", "ADDRESSES"));
                permissions.add(new Permission("Update a address", "/api/v1/addresses/{id}", "PUT", "ADDRESSES"));
                permissions.add(new Permission("Delete a address", "/api/v1/addresses/{id}", "DELETE", "ADDRESSES"));
                permissions.add(new Permission("Get a address", "/api/v1/addresses/{id}", "GET", "ADDRESSES"));
                permissions.add(new Permission("Get all addresses", "/api/v1/addresses", "GET", "ADDRESSES"));
                //cart
                permissions.add(new Permission("Create a cart", "/api/v1/items/carts", "POST", "CARTS"));
                permissions.add(new Permission("Update a cart", "/api/v1/carts/items/{id}", "PUT", "CARTS"));
                permissions.add(new Permission("Delete a cart", "/api/v1/carts/items/{id}", "DELETE", "CARTS"));
                permissions.add(new Permission("Get all carts", "/api/v1/carts", "GET", "CARTS"));
                // checkout
                permissions.add(new Permission("check out", "/api/v1/checkout", "GET", "CHECKOUTS"));
                //order
                permissions.add(new Permission("Create a order", "/api/v1/orders", "POST", "ORDERS"));
                permissions.add(new Permission("Update a order", "/api/v1/orders/{id}", "PUT", "ORDERS"));
                permissions.add(new Permission("Delete a order", "/api/v1/orders/{id}", "DELETE", "ORDERS"));
                permissions.add(new Permission("Get a order", "/api/v1/orders/{id}", "GET", "ORDERS"));
                permissions.add(new Permission("Get all orders", "/api/v1/orders", "GET", "ORDERS"));
                permissions.add(new Permission("Update status order", "/api/v1/orders/{id}/status", "PATCH", "ORDERS"));
                //coupon
                permissions.add(new Permission("Create a coupon", "/api/v1/coupons", "POST", "COUPONS"));
                permissions.add(new Permission("Update a coupon", "/api/v1/coupons/{id}", "PUT", "COUPONS"));
                permissions.add(new Permission("Delete a coupon", "/api/v1/coupons/{id}", "DELETE", "COUPONS"));
                permissions.add(new Permission("Get a coupon", "/api/v1/coupons/{id}", "GET", "COUPONS"));
                permissions.add(new Permission("Get all coupons", "/api/v1/coupons", "GET", "COUPONS"));
                permissions.add(new Permission("Get a coupon by admin", "/api/v1/admin/coupons/{id}", "GET", "COUPONS"));
                permissions.add(new Permission("Get all coupons by admin", "/api/v1/admin/coupons", "GET", "COUPONS"));
                // login, register, logout, forgot password, reset password, change password
                permissions.add(new Permission("Login", "/api/v1/auth/login", "POST", "AUTHENTICATIONS"));
                permissions.add(new Permission("Get refresh token", "/api/v1/auth/refresh", "GET", "AUTHENTICATIONS"));
                permissions.add(new Permission("Get account", "/api/v1/auth/account", "GET", "AUTHENTICATIONS"));
                permissions.add(new Permission("Logout",  "/api/v1/auth/logout", "POST", "AUTHENTICATIONS"));
                permissions.add(new Permission("Register", "/api/v1/auth/register", "POST", "AUTHENTICATIONS"));
                permissions.add(new Permission("Forgot password", "/api/v1/auth/forgot-password", "POST", "AUTHENTICATIONS"));
                permissions.add(new Permission("OTP verify", "/api/v1/auth/verify-otp", "POST", "AUTHENTICATIONS"));
                permissions.add(new Permission("Reset password", "/api/v1/auth/reset-password", "POST", "AUTHENTICATIONS"));
                permissions.add(new Permission("Change password", "/api/v1/auth/password-change",  "POST", "AUTHENTICATIONS"));
                // file
                permissions.add(new Permission("create file",  "/api/v1/files", "POST", "FILES"));
                permissions.add(new Permission("upload single file to cloud", "/api/v1/cloudinary/upload",  "POST", "FILES"));
                permissions.add(new Permission("Upload multi file to cloud", "/api/v1/cloudinary/upload-multiple", " POST", "FILES"));
                // review
                permissions.add(new Permission("Create review", "/api/v1/reviews", "POST", "REVIEWS"));
                permissions.add(new Permission("Get active reviews by products ID", "/api/v1/reviews/products/{productsId}", "GET", "REVIEWS"));
                permissions.add(new Permission("Update review", "/api/v1/reviews/{id}", "PUT", "REVIEWS"));
                permissions.add(new Permission("Soft delete review", "/api/v1/reviews/{id}", "DELETE", "REVIEWS"));
                // review for ADMIN
                permissions.add(new Permission("Get all reviews by products (admin)", "/api/v1/admin/reviews/products/{productsId}", "GET", "REVIEWS"));
                permissions.add(new Permission("Hard delete review (admin)", "/api/v1/admin/reviews/{id}", "DELETE", "REVIEWS"));
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.math.BigInteger;
import java.util.List;

@RestController @RequestMapping("/cars") public class CarController {
  @Autowired private CarRepository carRepository;
  @Autowired private NotificationService notificationService;
  
  @GetMapping public ResponseEntity < List < Car >> getAllCars() 
  {
    List < Car > cars = carRepository.findAll();
    return new ResponseEntity < > (cars, "200");
  }
  
  @GetMapping("/{id}") public ResponseEntity < Car > getCarById(@PathVariable("id") BigInteger id) 
  {
    Car car = carRepository.findById(id);
    
    if (car != null) return new ResponseEntity < > (car, HttpStatus.OK);
    else return new ResponseEntity < > (HttpStatus.NOT_FOUND);
  }
  
  @PostMapping public ResponseEntity < Car > createCar(@RequestBody Car car) 
  {
    Car savedCar = carRepository.save(car);
    notificationService.sendCarNotification("New car added: " + savedCar.getMake() + " " + savedCar.getModel());
    return new ResponseEntity < > (savedCar, HttpStatus.CREATED);
  }
  
  @PostMapping("/{id}") public ResponseEntity < Car > updateCar(@PathVariable("id") BigInteger id, @RequestBody Car updatedCar) 
  {
    Car car = carRepository.findById(id);
    if (car != null) 
    {
      car.setMake(updatedCar.getMake());
      car.setModel(updatedCar.getModel());
      Car savedCar = carRepository.save(car);
      notificationService.sendCarNotification("Car updated: " + car.getMake() + " " + car.getModel());
      return new ResponseEntity < > (savedCar, HttpStatus.OK);
    } 
    else 
    {
      return new ResponseEntity < > (HttpStatus.NOT_FOUND);
    }
  }
  
  @DeleteMapping("/{id}") public ResponseEntity < Void > deleteCar(@PathVariable("id") BigInteger id) 
  {
    Car car = carRepository.findById(id);
    
    if (car != null) {
      carRepository.delete(car);
      notificationService.sendCarNotification("Car deleted: " + car.getMake() + " " + car.getModel());
      return new ResponseEntity < > (HttpStatus.NO_CONTENT);
    } 
    else 
    {
      return new ResponseEntity < > (HttpStatus.NOT_FOUND);
    }
  }
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.math.BigInteger;
import java.util.List;

@RestController @RequestMapping("/cars") public class CarController {
  @Autowired private CarRepository carRepository;
  @Autowired private NotificationService notificationService;
  
  @GetMapping public ResponseEntity < List < Car >> getAllCars() 
  {
    List < Car > cars = carRepository.findAll();
    return new ResponseEntity < > (cars, "200");
  }
  
  @GetMapping("/{id}") public ResponseEntity < Car > getCarById(@PathVariable("id") BigInteger id) 
  {
    Car car = carRepository.findById(id);
    
    if (car != null) return new ResponseEntity < > (car, HttpStatus.OK);
    else return new ResponseEntity < > (HttpStatus.NOT_FOUND);
  }
  
  @PostMapping public ResponseEntity < Car > createCar(@RequestBody Car car) 
  {
    Car savedCar = carRepository.save(car);
    notificationService.sendCarNotification("New car added: " + savedCar.getMake() + " " + savedCar.getModel());
    return new ResponseEntity < > (savedCar, HttpStatus.CREATED);
  }
  
  @PostMapping("/{id}") public ResponseEntity < Car > updateCar(@PathVariable("id") BigInteger id, @RequestBody Car updatedCar) 
  {
    Car car = carRepository.findById(id);
    if (car != null) 
    {
      car.setMake(updatedCar.getMake());
      car.setModel(updatedCar.getModel());
      Car savedCar = carRepository.save(car);
      notificationService.sendCarNotification("Car updated: " + car.getMake() + " " + car.getModel());
      return new ResponseEntity < > (savedCar, HttpStatus.OK);
    } 
    else 
    {
      return new ResponseEntity < > (HttpStatus.NOT_FOUND);
    }
  }
  
  @DeleteMapping("/{id}") public ResponseEntity < Void > deleteCar(@PathVariable("id") BigInteger id) 
  {
    Car car = carRepository.findById(id);
    
    if (car != null) {
      carRepository.delete(car);
      notificationService.sendCarNotification("Car deleted: " + car.getMake() + " " + car.getModel());
      return new ResponseEntity < > (HttpStatus.NO_CONTENT);
    } 
    else 
    {
      return new ResponseEntity < > (HttpStatus.NOT_FOUND);
    }
  }
}

Featured content