source: Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java@ 04e4f54

main
Last change on this file since 04e4f54 was 04e4f54, checked in by SazdovaEkaterina <sazdovaekaterina@…>, 17 months ago

canBeFostered param default false when unchecked

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[738b31a]1package finki.paw5.web.controllers;
2
[468b7b6]3import finki.paw5.model.entities.Pet;
4import finki.paw5.model.entities.Post;
[738b31a]5import finki.paw5.model.enumerations.AgeGroup;
6import finki.paw5.model.enumerations.Gender;
7import finki.paw5.model.enumerations.Size;
8import finki.paw5.model.enumerations.Species;
[468b7b6]9import finki.paw5.service.PetService;
[738b31a]10import finki.paw5.service.PostService;
11import org.springframework.stereotype.Controller;
[468b7b6]12import org.springframework.ui.Model;
13import org.springframework.web.bind.annotation.GetMapping;
[738b31a]14import org.springframework.web.bind.annotation.PostMapping;
15import org.springframework.web.bind.annotation.RequestParam;
16
[468b7b6]17import java.time.LocalDate;
18
[738b31a]19@Controller
20public class PostController {
21
22 private final PostService postService;
[468b7b6]23 private final PetService petService;
[738b31a]24
[468b7b6]25 public PostController(PostService postService, PetService petService) {
[738b31a]26 this.postService = postService;
[468b7b6]27 this.petService = petService;
28 }
29
30 @GetMapping("create-post")
31 public String get(Model model) {
32 //TODO: vakvo ama za lista so pets
33 // List<Manufacturer> manufacturers = this.manufacturerService.findAll();
34 // model.addAttribute("manufacturers", manufacturers);
35 return "create-post";
[738b31a]36 }
37
[468b7b6]38 @PostMapping("submit-post")
39 public String savePost(@RequestParam(required = false) String name,
40 @RequestParam String gender,
41 @RequestParam String ageGroup,
42 @RequestParam String size,
43 @RequestParam String species,
44 @RequestParam(required = false) String breed,
45 @RequestParam(required = false) String imageUrl,
[04e4f54]46 @RequestParam(required = false) boolean canBeFostered) {
[468b7b6]47
48 Pet pet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, 1);
49 this.petService.save(pet);
[738b31a]50
[c37c953]51 Post post = new Post(LocalDate.now(), imageUrl, pet.getId(), null, 10);//TODO: employee id da se zeme preku session user getid
[468b7b6]52 this.postService.save(post);
[738b31a]53
[c37c953]54 return "redirect:/home";
[738b31a]55 }
56}
Note: See TracBrowser for help on using the repository browser.