Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.example.restaurantManager.controller;

import dev.example.restaurantManager.model.MenuItem.Dessert;
import dev.example.restaurantManager.service.DessertService;
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.util.List;

@RestController
@RequestMapping("/api/dessert")
public class DessertController {

@Autowired
private DessertService dessertService;

@GetMapping
public ResponseEntity<List<Dessert>> getAllDesserts() {
List<Dessert> desserts = dessertService.getAllDesserts();
return new ResponseEntity<>(desserts, HttpStatus.OK);
}

@GetMapping("/sugarfree")
public ResponseEntity<List<Dessert>> getAllSugarFreeDesserts() {
List<Dessert> desserts = dessertService.getAllSugarFreeDesserts();
return new ResponseEntity<>(desserts, HttpStatus.OK);
}

@PostMapping
public ResponseEntity<Dessert> createDessert(@RequestBody Dessert dessert) {
Dessert newDessert = dessertService.createDessert(dessert);
return new ResponseEntity<>(newDessert, HttpStatus.CREATED);
}

@GetMapping("/{id}")
public ResponseEntity<Dessert> getDessertById(@PathVariable String id) {
Dessert dessert = dessertService.getDessertById(id);
if (dessert != null) {
return new ResponseEntity<>(dessert, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

@PutMapping("/{id}")
public ResponseEntity<Dessert> updateDessert(@PathVariable String id, @RequestBody Dessert dessertDetails) {
Dessert updatedDessert = dessertService.updateDessert(id, dessertDetails);
if (updatedDessert != null) {
return new ResponseEntity<>(updatedDessert, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteDessert(@PathVariable String id) {
boolean deleted = dessertService.deleteDessert(id);
if (deleted) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

@GetMapping("/count")
public ResponseEntity<Long> countDesserts() {
long count = dessertService.countDesserts();
return new ResponseEntity<>(count, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.example.restaurantManager.controller;

import dev.example.restaurantManager.model.MenuItem.MainCourse;
import dev.example.restaurantManager.service.MainCourseService;
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.util.List;

@RestController
@RequestMapping("/api/maincourse")
public class MainCourseController {

@Autowired
private MainCourseService mainCourseService;

@GetMapping
public ResponseEntity<List<MainCourse>> getAllMainCourses() {
List<MainCourse> mainCourses = mainCourseService.getAllMainCourses();
return new ResponseEntity<>(mainCourses, HttpStatus.OK);
}

@GetMapping("/vegan")
public ResponseEntity<List<MainCourse>> getAllVeganMainCourses() {
List<MainCourse> mainCourses = mainCourseService.getAllVeganMainCourses();
return new ResponseEntity<>(mainCourses, HttpStatus.OK);
}

@PostMapping
public ResponseEntity<MainCourse> createMainCourse(@RequestBody MainCourse mainCourse) {
MainCourse newMainCourse = mainCourseService.createMainCourse(mainCourse);
return new ResponseEntity<>(newMainCourse, HttpStatus.CREATED);
}

@GetMapping("/{id}")
public ResponseEntity<MainCourse> getMainCourseById(@PathVariable String id) {
MainCourse mainCourse = mainCourseService.getMainCourseById(id);
if (mainCourse != null) {
return new ResponseEntity<>(mainCourse, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

@PutMapping("/{id}")
public ResponseEntity<MainCourse> updateMainCourse(@PathVariable String id, @RequestBody MainCourse mainCourseDetails) {
MainCourse updatedMainCourse = mainCourseService.updateMainCourse(id, mainCourseDetails);
if (updatedMainCourse != null) {
return new ResponseEntity<>(updatedMainCourse, HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteMainCourse(@PathVariable String id) {
boolean deleted = mainCourseService.deleteMainCourse(id);
if (deleted) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

@GetMapping("/count")
public ResponseEntity<Long> countMainCourses() {
long count = mainCourseService.countMainCourses();
return new ResponseEntity<>(count, HttpStatus.OK);
}
}

This file was deleted.

30 changes: 0 additions & 30 deletions src/main/java/dev/example/restaurantManager/model/MenuItem.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.example.restaurantManager.model.MenuItem;

import jakarta.persistence.Entity;


@Entity
public class Dessert extends MenuItem{

private boolean sugarFree;

public Dessert(){

}

public Dessert(String id, String name, String description, double price, boolean sugarFree) {
super(id,name,description,price);
this.sugarFree = sugarFree;
}

public boolean isSugarFree(){
return sugarFree;
}

public void setSugarFree(boolean sugarFree){
this.sugarFree = sugarFree;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.example.restaurantManager.model.MenuItem;

public interface IMenuItem {
String getId();
String getName();
String getDescription();
double getPrice();


void setId(String id);
void setName(String name);
void setDescription(String description);
void setPrice(double price);



// private String id;
// private String name;
// private String description;
// private double price;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.example.restaurantManager.model.MenuItem;

import jakarta.persistence.Entity;

@Entity
public class MainCourse extends MenuItem{

private boolean vegan;

public MainCourse(){

}

public MainCourse(String id, String name, String description, double price, boolean vegan) {
super(id,name,description,price);
this.vegan = vegan;
}

public boolean isVegan(){
return vegan;
}

public void setVegan(boolean vegan){
this.vegan = vegan;
}

}
Loading