Ignore:
Timestamp:
03/04/23 19:55:18 (16 months ago)
Author:
SazdovaEkaterina <sazdovaekaterina@…>
Branches:
main
Children:
33b9f30
Parents:
3c7bf5b (diff), f194b4e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge main into adopting-a-pet

Location:
Prototype Application/Paw5/src/main/java/finki/paw5
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/PetService.java

    r3c7bf5b reac569a  
    22
    33import finki.paw5.model.entities.Pet;
    4 import finki.paw5.web.controllers.PostController;
    54
    65import java.util.List;
    7 import java.util.Optional;
    86
    97public interface PetService {
     
    119    void save (Pet pet);
    1210
    13     List<Pet> findAll();
     11    List<Pet> listpets();
    1412
    15     Optional<Pet> findById(Integer petId);
     13    Pet findById(Integer id);
    1614}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/PostService.java

    r3c7bf5b reac569a  
    22
    33import finki.paw5.model.entities.Post;
    4 
    54import java.util.List;
    65import java.util.Optional;
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PetServiceImplementation.java

    r3c7bf5b reac569a  
    77
    88import java.util.List;
    9 import java.util.Optional;
    109
    1110@Service
     
    2322    }
    2423
    25     @Override
    26     public List<Pet> findAll() {
    27         return this.petRepository.findAll();
    28     }
     24    public List<Pet> listpets() {return this.petRepository.findAll();}
    2925
    3026    @Override
    31     public Optional<Pet> findById(Integer petId) {
    32         return this.petRepository.findById(petId);
     27    public Pet findById(Integer id) {
     28        return this.petRepository.findById(id).get();
    3329    }
    3430}
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/HomeController.java

    r3c7bf5b reac569a  
    11package finki.paw5.web.controllers;
    22
     3import jakarta.servlet.http.HttpServletRequest;
    34import org.springframework.stereotype.Controller;
    45import org.springframework.web.bind.annotation.GetMapping;
     
    1011
    1112    @GetMapping
    12     public String getHomePage(){
     13    public String getHomePage(HttpServletRequest request) {
     14        if(request.getSession().getAttribute("user")==null){
     15            return "redirect:/login";
     16        }
    1317        return "home";
    1418    }
     19
    1520    @GetMapping("/aboutUs")
    16     public String getSuccessPage(){
     21    public String getSuccessPage() {
    1722        return "/aboutUs";
    1823    }
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java

    r3c7bf5b reac569a  
    2828    public String saveAdoption(@PathVariable Integer id, HttpServletRequest request) {
    2929
    30         Pet pet = this.petService.findById(id).orElseThrow(InvalidPetIdException::new);
     30        Pet pet = this.petService.findById(id);
    3131       
    3232        User user = (User) request.getSession().getAttribute("user");
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java

    r3c7bf5b reac569a  
    11package finki.paw5.web.controllers;
    2 
    3 import finki.paw5.model.entities.PersonalProfile;
    42import finki.paw5.model.entities.Pet;
    53import finki.paw5.model.entities.Post;
    6 import finki.paw5.model.entities.Shelter;
     4import finki.paw5.model.entities.Employee;
    75import finki.paw5.model.enumerations.AgeGroup;
    86import finki.paw5.model.enumerations.Gender;
     
    3735    }
    3836
    39     @GetMapping("create-post")
     37    @GetMapping("/create-post")
    4038    public String get(Model model) {
    41         //TODO: vakvo ama za lista so pets
    42         //        List<Manufacturer> manufacturers = this.manufacturerService.findAll();
    43         //        model.addAttribute("manufacturers", manufacturers);
     39        model.addAttribute("pets", this.petService.listpets());
    4440        return "create-post";
    4541    }
    4642
    47     @PostMapping("submit-post")
    48     public String savePost(@RequestParam(required = false) String name,
    49                            @RequestParam String gender,
    50                            @RequestParam String ageGroup,
    51                            @RequestParam String size,
    52                            @RequestParam String species,
     43    @PostMapping("/submit-post")
     44    public String savePost(@RequestParam(required = false) Integer petId,
     45                           @RequestParam(required = false) boolean newPetCheckbox,
     46                           @RequestParam(required = false) String name,
     47                           @RequestParam(required = false) String gender,
     48                           @RequestParam(required = false) String ageGroup,
     49                           @RequestParam(required = false) String size,
     50                           @RequestParam(required = false) String species,
    5351                           @RequestParam(required = false) String breed,
    5452                           @RequestParam(required = false) String imageUrl,
    55                            @RequestParam(required = false) boolean canBeFostered) {
     53                           @RequestParam(required = false) boolean canBeFostered,
     54                           HttpServletRequest request) {
    5655
    57         Pet pet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, 1);
    58         this.petService.save(pet);
     56        Employee employee = (Employee) request.getSession().getAttribute("user");
    5957
    60         Post post = new Post(LocalDate.now(), imageUrl, pet.getId(), null, 10);//TODO: employee id da se zeme preku session user getid
    61         this.postService.save(post);
     58        if(newPetCheckbox == true){
     59
     60            Pet newPet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelterId());
     61            this.petService.save(newPet);
     62
     63            Post post = new Post(LocalDate.now(), imageUrl, newPet.getId(), null, employee.getId());
     64            this.postService.save(post);
     65
     66        } else{
     67
     68            Pet selectedPet = this.petService.findById(petId);
     69
     70            Post post = new Post(LocalDate.now(), imageUrl, selectedPet.getId(), null, employee.getId());
     71            this.postService.save(post);
     72
     73        }
    6274
    6375        return "redirect:/home";
     
    6880
    6981        List<Post> posts = this.postService.findAll();
    70         List<Pet> pets = this.petService.findAll();
     82        List<Pet> pets = this.petService.listpets();
    7183        //model.addAttribute("posts", posts);
    7284        //model.addAttribute("pets",pets);
     
    8193
    8294        Post post = this.postService.findById(id).get();
    83         Pet pet = this.petService.findById(post.getPetId()).get();
     95        Pet pet = this.petService.findById(post.getPetId());
    8496
    8597        //model.addAttribute("pet", pet);
Note: See TracChangeset for help on using the changeset viewer.