-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRecipeController.java
74 lines (59 loc) · 2.58 KB
/
RecipeController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.cha0stig3r.recipe.server.controller;
import com.cha0stig3r.recipe.server.model.RecipeDto;
import com.cha0stig3r.recipe.server.model.RequestDto;
import com.cha0stig3r.recipe.server.model.RequestUpdate;
import com.cha0stig3r.recipe.server.service.RecipeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Optional;
@CrossOrigin(origins = "*")
@RestController
public class RecipeController {
@Autowired
private RecipeService service;
@PostMapping(value = "/add-recipe", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String addRecipe(RequestDto request) throws Exception {
return service.addRecipe(request);
}
@PostMapping(value = "/update-recipe/img/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String updateRecipe(@PathVariable Long id, RequestDto request) throws Exception {
return service.updateRecipe(id, request);
}
@PostMapping(value = "/update-recipe/{id}")
public String updateRecipe(@PathVariable Long id, RequestUpdate request){
return service.updateRecipe(id, request);
}
@DeleteMapping("/delete-recipe/{id}")
public String deleteRecipe(@PathVariable Long id) throws URISyntaxException {
return service.deleteRecipe(id);
}
@GetMapping(value = "/url/{url}", produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public ByteArrayResource getImg(@PathVariable String url){
return service.getImage(url);
}
@GetMapping("/get-recipe/{id}")
public RecipeDto getRecipe(@PathVariable Long id){
return service.getRecipeById(id);
}
@GetMapping("/search-recipe")
public List<RecipeDto> getSearched(@RequestParam String query){
return service.getSearchedName(query);
}
@GetMapping("/get-recipes/All")
public List<RecipeDto> getRecipes(){
return service.getRecipes();
}
@GetMapping(value = {"/get-recipes/recent/{type}", "/get-recipes/recent/{type}/{amount}"})
public List<RecipeDto> getRecentType(@PathVariable String type, @PathVariable(required = false) Optional<Integer> amount){
return amount.map(integer -> service.getRecentType(type).subList(0, integer)).orElseGet(() -> service.getRecentType(type));
}
@GetMapping("/get-recipes/{type}")
public List<RecipeDto> getTypes(@PathVariable String type){
return service.getType(type);
}
}