Changeset 7e3f2f7


Ignore:
Timestamp:
02/16/23 16:09:52 (21 months ago)
Author:
Filip Chorbeski <86695898+FilipChorbeski@…>
Branches:
main
Children:
d7eaf88
Parents:
6941fac
Message:

(temp) added listpets and Employee session request

(temp) added listpets and Employee session request to Post Controller

Location:
Prototype Application/Paw5/src/main
Files:
5 edited

Legend:

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

    r6941fac r7e3f2f7  
    33import finki.paw5.model.entities.Pet;
    44
     5import java.util.List;
     6
    57public interface PetService {
    68
    79    void save (Pet pet);
     10
     11    List<Pet> listpets();
    812}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/PostService.java

    r6941fac r7e3f2f7  
    22
    33import finki.paw5.model.entities.Post;
    4 import finki.paw5.model.enumerations.AgeGroup;
    5 import finki.paw5.model.enumerations.Gender;
    6 import finki.paw5.model.enumerations.Size;
    7 import finki.paw5.model.enumerations.Species;
    84
    95public interface PostService {
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/PetServiceImplementation.java

    r6941fac r7e3f2f7  
    55import finki.paw5.service.PetService;
    66import org.springframework.stereotype.Service;
     7
     8import java.util.List;
    79
    810@Service
     
    1921        this.petRepository.save(pet);
    2022    }
     23
     24    @Override
     25    public List<Pet> listpets() {return this.petRepository.findAll();}
    2126}
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java

    r6941fac r7e3f2f7  
    11package finki.paw5.web.controllers;
    22
     3import finki.paw5.model.entities.Employee;
    34import finki.paw5.model.entities.Pet;
    45import finki.paw5.model.entities.Post;
     6import finki.paw5.model.entities.User;
    57import finki.paw5.model.enumerations.AgeGroup;
    68import finki.paw5.model.enumerations.Gender;
     
    911import finki.paw5.service.PetService;
    1012import finki.paw5.service.PostService;
     13import jakarta.servlet.http.HttpServletRequest;
    1114import org.springframework.stereotype.Controller;
    1215import org.springframework.ui.Model;
     
    3033    @GetMapping("/create-post")
    3134    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        model.addAttribute("pets", this.petService.listpets());
    3536        return "create-post";
    3637    }
     
    4445                           @RequestParam(required = false) String breed,
    4546                           @RequestParam(required = false) String imageUrl,
    46                            @RequestParam(required = false) boolean canBeFostered) {
     47                           @RequestParam(required = false) boolean canBeFostered,
     48                           HttpServletRequest request) {
    4749
    48         Pet pet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, 1);
     50        Employee employee = (Employee) request.getSession().getAttribute("employee");
     51
     52        Pet pet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelterId());
    4953        this.petService.save(pet);
    5054
    51         Post post = new Post(LocalDate.now(), imageUrl, pet.getId(), null, 10);//TODO: employee id da se zeme preku session user getid
     55        Post post = new Post(LocalDate.now(), imageUrl, pet.getId() , null, employee.getId() );
    5256        this.postService.save(post);
    5357
  • Prototype Application/Paw5/src/main/resources/templates/create-post.html

    r6941fac r7e3f2f7  
    4444        <label for="pet">Selet pet:</label>
    4545        <select id="pet">
     46            <option
     47            th:each="pet :${pets}"
     48            th:text="${pet.getName()}">
     49            </option>
    4650        </select>
    4751    </div>
Note: See TracChangeset for help on using the changeset viewer.