Ignore:
Timestamp:
02/12/23 22:54:47 (17 months ago)
Author:
Filip Chorbeski <86695898+FilipChorbeski@…>
Branches:
main
Children:
325a55d
Parents:
988f3fa
Message:

create post form (initial version)

successfully communicates with database and adds pet and post (will be worked upon more)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java

    r988f3fa r468b7b6  
    11package finki.paw5.web.controllers;
    22
     3import finki.paw5.model.entities.Pet;
     4import finki.paw5.model.entities.Post;
    35import finki.paw5.model.enumerations.AgeGroup;
    46import finki.paw5.model.enumerations.Gender;
    57import finki.paw5.model.enumerations.Size;
    68import finki.paw5.model.enumerations.Species;
     9import finki.paw5.service.PetService;
    710import finki.paw5.service.PostService;
    811import org.springframework.stereotype.Controller;
     12import org.springframework.ui.Model;
     13import org.springframework.web.bind.annotation.GetMapping;
    914import org.springframework.web.bind.annotation.PostMapping;
    10 import org.springframework.web.bind.annotation.RequestMapping;
    1115import org.springframework.web.bind.annotation.RequestParam;
    1216
     17import java.time.LocalDate;
     18
    1319@Controller
    14 @RequestMapping("/CreatePost")
    1520public class PostController {
    1621
    1722    private final PostService postService;
     23    private final PetService petService;
    1824
    19     public PostController(PostService postService) {
     25    public PostController(PostService postService, PetService petService) {
    2026        this.postService = postService;
     27        this.petService = petService;
    2128    }
    2229
    23     @PostMapping
    24     public String submit(@RequestParam String name,
    25                          @RequestParam Gender gender,
    26                          @RequestParam AgeGroup ageGroup,
    27                          @RequestParam Size size,
    28                          @RequestParam Species species,
    29                          @RequestParam String breed,
    30                          @RequestParam String urlimage) {
     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";
     36    }
    3137
    32         this.postService.submit(name, gender, ageGroup, size, species, breed, urlimage);
     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,
     46                           @RequestParam boolean canBeFostered) {
     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);
     50
     51        Post post = new Post(LocalDate.now(), imageUrl, pet.getId(), null, 10);
     52        this.postService.save(post);
    3353
    3454        return null;
Note: See TracChangeset for help on using the changeset viewer.