# 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# firstoccurrence# python financial analysis finance profit calculation data analysis# 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# spring boot# rest api# backend development# web services

Latest from community today

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