Changeset 087ce2b for cimeri-main


Ignore:
Timestamp:
07/10/23 17:50:01 (16 months ago)
Author:
blagojanikoloski <blagojanikoloski1@…>
Branches:
master
Parents:
bc30bce
Message:

First Change

Location:
cimeri-main
Files:
39 edited

Legend:

Unmodified
Added
Removed
  • cimeri-main/.idea/vcs.xml

    rbc30bce r087ce2b  
    22<project version="4">
    33  <component name="VcsDirectoryMappings">
     4    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
    45    <mapping directory="$PROJECT_DIR$/cimeri" vcs="Git" />
    56  </component>
  • cimeri-main/src/main/java/com/example/cimeri/model/Apartment.java

    rbc30bce r087ce2b  
    1616    private Long buildingid;
    1717    private Long ownerid;
    18     private String apartment_adress;
    19     private int apartment_size;
     18    private String apartmentfloorandroomnumber;
     19    private int apartmentsize;
    2020
    2121    public Apartment() {
     
    2525        this.buildingid=buildingid;
    2626        this.ownerid=ownerid;
    27         this.apartment_adress=apartment_adress;
    28         this.apartment_size=apartment_size;
     27        this.apartmentfloorandroomnumber =apartment_adress;
     28        this.apartmentsize =apartment_size;
    2929    }
    3030}
  • cimeri-main/src/main/java/com/example/cimeri/model/Building.java

    rbc30bce r087ce2b  
    1414    private Long buildingid;
    1515
    16     private String cityname;
    17     private String building_adress;
     16    private Long cityid;
     17    private String buildingaddress;
    1818
    1919    public Building() {
    2020    }
    2121
    22     public Building(String cityname, String building_adress) {
    23         this.cityname=cityname;
    24         this.building_adress=building_adress;
     22    public Building(Long cityid, String building_adress) {
     23        this.cityid=cityid;
     24        this.buildingaddress =building_adress;
    2525    }
    2626}
  • cimeri-main/src/main/java/com/example/cimeri/model/City.java

    rbc30bce r087ce2b  
    1010public class City {
    1111    @Id
     12    @GeneratedValue(strategy = GenerationType.IDENTITY)
     13    private Long cityid;
     14
    1215    private String cityname;
    1316
  • cimeri-main/src/main/java/com/example/cimeri/model/Faculty.java

    rbc30bce r087ce2b  
    1515
    1616    private String facultyname;
    17     private String cityname;
     17    private Long cityid;
    1818
    1919    public Faculty() {
    2020    }
    2121
    22     public Faculty(Long facultyid, String facultyname, String cityname) {
     22    public Faculty(Long facultyid, String facultyname, Long cityid) {
    2323        this.facultyid=facultyid;
    2424        this.facultyname=facultyname;
    25         this.cityname=cityname;
     25        this.cityid=cityid;
    2626    }
    2727}
  • cimeri-main/src/main/java/com/example/cimeri/model/OwnerPost.java

    rbc30bce r087ce2b  
    33import jakarta.persistence.*;
    44import lombok.Data;
    5 
    6 import java.time.LocalDateTime;
    75
    86
     
    1210public class OwnerPost {
    1311    @Id
    14     private Long owner_postid;
     12    private Long ownerpostid;
    1513    private Long apartmentid;
    1614    private Long ownerid;
     
    2321
    2422    public OwnerPost(Long owner_postid,Long apartmentid,Long ownerid) {
    25         this.owner_postid=owner_postid;
     23        this.ownerpostid =owner_postid;
    2624        this.apartmentid=apartmentid;
    2725        this.ownerid=ownerid;
  • cimeri-main/src/main/java/com/example/cimeri/model/Post.java

    rbc30bce r087ce2b  
    1414    @GeneratedValue(strategy = GenerationType.IDENTITY)
    1515    private Long postid;
    16     private String cityname;
    17     private int number_of_roommates;
     16    private Long cityid;
     17    private int numberofroommates;
    1818    private int price;
    19     private LocalDateTime date_posted;
     19    private LocalDateTime dateposted;
    2020    private String description;
    2121
     
    2424    }
    2525
    26     public Post(String cityname, int number_of_roommates, int price, LocalDateTime date_posted, String description) {
    27         this.cityname=cityname;
    28         this.number_of_roommates=number_of_roommates;
     26    public Post(Long cityid, int number_of_roommates, int price, LocalDateTime date_posted, String description) {
     27        this.cityid=cityid;
     28        this.numberofroommates =number_of_roommates;
    2929        this.price=price;
    30         this.date_posted=date_posted;
     30        this.dateposted =date_posted;
    3131        this.description=description;
    3232    }
  • cimeri-main/src/main/java/com/example/cimeri/model/StudentPost.java

    rbc30bce r087ce2b  
    33import jakarta.persistence.*;
    44import lombok.Data;
    5 
    6 import java.time.LocalDateTime;
    75
    86
     
    1210public class StudentPost {
    1311    @Id
    14     private Long student_postid;
     12    private Long studentpostid;
    1513    private Long studentid;
    1614
     
    2119
    2220    public StudentPost(Long student_postid,Long studentid) {
    23         this.student_postid=student_postid;
     21        this.studentpostid =student_postid;
    2422        this.studentid=studentid;
    2523
  • cimeri-main/src/main/java/com/example/cimeri/repository/ApartmentRepository.java

    rbc30bce r087ce2b  
    2020
    2121
    22     @Query("select u.ime,u.prezime,u.phone_number,u.email_address,a.apartment_size,a.apartment_adress,b.building_adress,p.price,photos.photosurl from Building b,User u, Apartment a,Post p,OwnerPost op, Owner o, Photos photos WHERE u.userid=a.ownerid and op.owner_postid=p.postid and op.ownerid=u.userid and o.ownerid=u.userid and o.ownerid=a.ownerid and b.buildingid=a.buildingid and a.apartmentid=op.apartmentid and photos.postid=p.postid and photos.postid=op.owner_postid and p.number_of_roommates=:number_of_roommates and p.price<=:budget and p.cityname=:cityname")
    23     List filteredapartments(@Param("cityname")String cityname, @Param("number_of_roommates") int number_of_roommates, @Param("budget") int budget);
     22    @Query("select u.ime,u.prezime,u.phone_number,u.email_address,a.apartmentsize,a.apartmentfloorandroomnumber,b.buildingaddress,p.price,photos.photosurl from Building b,User u, Apartment a,Post p,OwnerPost op, Owner o, Photos photos WHERE u.userid=a.ownerid and op.ownerpostid=p.postid and op.ownerid=u.userid and o.ownerid=u.userid and o.ownerid=a.ownerid and b.buildingid=a.buildingid and a.apartmentid=op.apartmentid and photos.postid=p.postid and photos.postid=op.ownerpostid and p.numberofroommates=:number_of_roommates and p.price<=:budget and p.cityid=:cityid")
     23    List filteredapartments(@Param("cityid")Long cityid, @Param("number_of_roommates") int number_of_roommates, @Param("budget") int budget);
    2424
    25     @Query("select u.ime,u.prezime,u.phone_number,u.email_address,a.apartment_size,a.apartment_adress,b.building_adress,p.price,photos.photosurl from Building b,User u, Apartment a,Post p,OwnerPost op, Owner o, Photos photos WHERE u.userid=a.ownerid and op.owner_postid=p.postid and op.ownerid=u.userid and o.ownerid=u.userid and o.ownerid=a.ownerid and b.buildingid=a.buildingid and a.apartmentid=op.apartmentid and photos.postid=p.postid and photos.postid=op.owner_postid")
     25    @Query("select u.ime,u.prezime,u.phone_number,u.email_address,a.apartmentsize,a.apartmentfloorandroomnumber,b.buildingaddress,p.price,photos.photosurl from Building b,User u, Apartment a,Post p,OwnerPost op, Owner o, Photos photos WHERE u.userid=a.ownerid and op.ownerpostid=p.postid and op.ownerid=u.userid and o.ownerid=u.userid and o.ownerid=a.ownerid and b.buildingid=a.buildingid and a.apartmentid=op.apartmentid and photos.postid=p.postid and photos.postid=op.ownerpostid")
    2626    List allapartments();
    2727}
  • cimeri-main/src/main/java/com/example/cimeri/repository/CityRepository.java

    rbc30bce r087ce2b  
    22
    33import com.example.cimeri.model.City;
     4import com.example.cimeri.model.User;
    45import org.springframework.data.jpa.repository.JpaRepository;
    56import org.springframework.data.jpa.repository.Query;
     7import org.springframework.data.repository.query.Param;
    68import org.springframework.stereotype.Repository;
    79
     
    1315
    1416
    15 
     17    @Query("select c.cityname from City c WHERE c.cityid=:cityid")
     18    String findCityByCityId(@Param("cityid")Long cityid);
    1619}
  • cimeri-main/src/main/java/com/example/cimeri/repository/OwnerPostRepository.java

    rbc30bce r087ce2b  
    1515public interface OwnerPostRepository extends JpaRepository<OwnerPost,Long> {
    1616
    17     @Query("select Max(owner_postid) from OwnerPost")
     17    @Query("select Max(ownerpostid) from OwnerPost")
    1818    Long findMaxOwnerPostID();
    1919
  • cimeri-main/src/main/java/com/example/cimeri/repository/UserRepository.java

    rbc30bce r087ce2b  
    2222
    2323
    24     @Query("select u from User u,Student s,StudentPost sp,Post p WHERE u.userid=s.studentid and u.userid=sp.studentid and sp.student_postid=p.postid and p.number_of_roommates=:number_of_roommates and p.price<=:budget and p.cityname=:cityname and s.studentid!=:currentid")
    25     List<User> findAllStudentsThatHavePosted(@Param("cityname")String cityname, @Param("number_of_roommates") int number_of_roommates, @Param("budget") int budget, @Param("currentid") Long currentid);
     24    @Query("select u from User u,Student s,StudentPost sp,Post p WHERE u.userid=s.studentid and u.userid=sp.studentid and sp.studentpostid=p.postid and p.numberofroommates=:number_of_roommates and p.price<=:budget and p.cityid=:cityid and s.studentid!=:currentid")
     25    List<User> findAllStudentsThatHavePosted(@Param("cityid")Long cityid, @Param("number_of_roommates") int number_of_roommates, @Param("budget") int budget, @Param("currentid") Long currentid);
    2626
    2727
  • cimeri-main/src/main/java/com/example/cimeri/service/Implementation/UserServiceImplementation.java

    rbc30bce r087ce2b  
    2727
    2828    @Override
    29     public List<User> filteredUsers(String cityname, int budget, int number_of_roommates, Long currentid) {
    30         List<User> users=userRepository.findAllStudentsThatHavePosted(cityname,budget,number_of_roommates,currentid);
     29    public List<User> filteredUsers(Long cityid, int budget, int number_of_roommates, Long currentid) {
     30        List<User> users=userRepository.findAllStudentsThatHavePosted(cityid,budget,number_of_roommates,currentid);
    3131
    3232
  • cimeri-main/src/main/java/com/example/cimeri/service/UserService.java

    rbc30bce r087ce2b  
    11package com.example.cimeri.service;
    22
    3 import com.example.cimeri.model.Faculty;
    43import com.example.cimeri.model.User;
    54
     
    98    Long findMaxUserID();
    109    List<User> listAll();
    11     List<User> filteredUsers(String cityname, int budget, int number_of_roommates,Long currentid);
     10    List<User> filteredUsers(Long cityname, int budget, int number_of_roommates, Long currentid);
    1211
    1312
  • cimeri-main/src/main/java/com/example/cimeri/web/controller/ListApartmentsController.java

    rbc30bce r087ce2b  
    11package com.example.cimeri.web.controller;
    22
    3 import com.example.cimeri.model.User;
    43import com.example.cimeri.repository.ApartmentRepository;
     4import com.example.cimeri.repository.CityRepository;
    55import jakarta.servlet.http.HttpSession;
    66import org.springframework.stereotype.Controller;
     
    2020
    2121    private final ApartmentRepository apartmentRepository;
     22    private final CityRepository cityRepository;
    2223
    23     public ListApartmentsController(ApartmentRepository apartmentRepository) {
     24    public ListApartmentsController(ApartmentRepository apartmentRepository, CityRepository cityRepository) {
    2425        this.apartmentRepository = apartmentRepository;
     26        this.cityRepository = cityRepository;
    2527    }
    2628
     
    3234        int number_of_roommates= (int) httpSession.getAttribute("number_of_roommates");
    3335        int budget= (int) httpSession.getAttribute("budget");
     36        Long cityid= (Long) httpSession.getAttribute("cityid");
    3437
    3538
     
    3740        httpSession.removeAttribute("number_of_roommates");
    3841        httpSession.removeAttribute("budget");
     42        httpSession.removeAttribute("cityid");
    3943
    40         List filteredapartments=apartmentRepository.filteredapartments(cityname,number_of_roommates,budget);
     44        List filteredapartments=apartmentRepository.filteredapartments(cityid,number_of_roommates,budget);
    4145        model.addAttribute("filteredapartments",filteredapartments);
    4246
     
    4549
    4650    @PostMapping
    47     public String listneededapartments(@RequestParam int number_of_roommates, @RequestParam String cityname, @RequestParam int budget
     51    public String listneededapartments(@RequestParam int number_of_roommates, @RequestParam Long cityid, @RequestParam int budget
    4852            , HttpSession httpSession, Model model)
    4953    {
    5054
     55        String cityname= cityRepository.findCityByCityId(cityid);
    5156        httpSession.setAttribute("number_of_roommates",number_of_roommates);
    5257        httpSession.setAttribute("cityname",cityname);
     58        httpSession.setAttribute("cityid",cityid);
    5359        httpSession.setAttribute("budget",budget);
    5460
  • cimeri-main/src/main/java/com/example/cimeri/web/controller/ListStudentsController.java

    rbc30bce r087ce2b  
    44import com.example.cimeri.model.StudentPost;
    55import com.example.cimeri.model.User;
     6import com.example.cimeri.repository.CityRepository;
    67import com.example.cimeri.repository.PostRepository;
    78import com.example.cimeri.repository.StudentPostRepository;
     
    3132    private final FacultyService facultyService;
    3233    private final UserService userService;
     34    private final CityRepository cityRepository;
    3335
    34     public ListStudentsController(PostRepository postRepository, StudentPostRepository studentPostRepository, UserRepository userRepository, FacultyService facultyService, UserService userService) {
     36    public ListStudentsController(PostRepository postRepository, StudentPostRepository studentPostRepository, UserRepository userRepository, FacultyService facultyService, UserService userService, CityRepository cityRepository) {
    3537        this.postRepository = postRepository;
    3638        this.studentPostRepository = studentPostRepository;
     
    3840        this.facultyService = facultyService;
    3941        this.userService = userService;
     42        this.cityRepository = cityRepository;
    4043    }
    4144
     
    4346    public String getPage(HttpSession httpSession,Model model) throws IOException {
    4447
    45         String cityname= (String) httpSession.getAttribute("cityname");
     48
    4649        int number_of_roommates= (int) httpSession.getAttribute("number_of_roommates");
    4750        int budget= (int) httpSession.getAttribute("budget");
    4851        Long currentid= (Long) httpSession.getAttribute("currentid");
     52        Long cityid= (Long) httpSession.getAttribute("cityid");
     53        String cityname= (String) httpSession.getAttribute("cityname");
    4954
    5055        httpSession.removeAttribute("cityname");
     56        httpSession.removeAttribute("cityid");
    5157        httpSession.removeAttribute("number_of_roommates");
    5258        httpSession.removeAttribute("budget");
    5359        httpSession.removeAttribute("currentid");
    5460
    55         List<User> similarusers=userService.filteredUsers(cityname,number_of_roommates,budget,currentid);
     61        List<User> similarusers=userService.filteredUsers(cityid,number_of_roommates,budget,currentid);
    5662        model.addAttribute("similarusers",similarusers);
    5763        return "liststudents";
     
    6066
    6167    @PostMapping(value = "/createpost")
    62     public String createpost(@RequestParam int number_of_roommates, @RequestParam String cityname, @RequestParam int budget
     68    public String createpost(@RequestParam int number_of_roommates, @RequestParam Long cityid, @RequestParam int budget
    6369            , HttpSession httpSession, Model model)
    6470    {
    65             Post post=new Post(cityname,number_of_roommates,budget, LocalDateTime.now(), "baram cimeri");
     71            Post post=new Post(cityid,number_of_roommates,budget, LocalDateTime.now(), "baram cimeri");
    6672            postRepository.save(post);
    6773            Long maxPostID=postRepository.findMaxPostID();
     
    7379            //do ovde se kreira studentpost
    7480
     81
     82            String cityname= cityRepository.findCityByCityId(cityid);
    7583            httpSession.setAttribute("number_of_roommates",number_of_roommates);
    7684            httpSession.setAttribute("cityname",cityname);
    7785            httpSession.setAttribute("budget",budget);
     86            httpSession.setAttribute("cityid",cityid);
    7887
    7988
  • cimeri-main/src/main/java/com/example/cimeri/web/controller/PostApartmentController.java

    rbc30bce r087ce2b  
    4646
    4747    @PostMapping(value = "/createpost")
    48     public String createpost(@RequestParam int number_of_roommates, @RequestParam String cityname, @RequestParam int price
     48    public String createpost(@RequestParam int number_of_roommates, @RequestParam Long cityid, @RequestParam int price
    4949            , HttpSession httpSession, @RequestParam String building_adress, @RequestParam String apartment_adress, @RequestParam int apartment_size,
    5050                             @RequestParam String photosurl, Model model)
    5151    {
    52         Post post=new Post(cityname,number_of_roommates,price, LocalDateTime.now(), "izdavam stan");
     52
     53
     54        Post post=new Post(cityid,number_of_roommates,price, LocalDateTime.now(), "izdavam stan");
    5355        postRepository.save(post);
    5456        Long maxPostID=postRepository.findMaxPostID();
     
    5759        httpSession.setAttribute("currentid",ownerID);
    5860
    59         Building building=new Building(cityname,building_adress);
     61
     62        Building building=new Building(cityid,building_adress);
    6063        buildingRepository.save(building);
    6164        Long maxBuildingID=buildingRepository.findMaxBuildingID();
  • cimeri-main/src/main/resources/templates/findapartments.html

    rbc30bce r087ce2b  
    6161        <span class="findapartments-text06">CITY</span>
    6262
    63         <select class="findapartments-textinput1 input" name="cityname" id="cityname">
    64         <option th:each="city : ${cities}" th:value="${city.cityname}" th:name="city" th:text="${city.cityname}">
     63        <select class="findapartments-textinput1 input" name="cityid" id="cityid">
     64        <option th:each="city : ${cities}" th:value="${city.cityid}" th:name="city" th:text="${city.cityname}">
    6565        </option>
    6666        </select>
  • cimeri-main/src/main/resources/templates/findroommates.html

    rbc30bce r087ce2b  
    6161        <span class="findroommates-text06">CITY</span>
    6262
    63         <select class="findroommates-textinput1 input" name="cityname" id="cityname">
    64         <option th:each="city : ${cities}" th:value="${city.cityname}" th:name="city" th:text="${city.cityname}">
     63        <select class="findroommates-textinput1 input" name="cityid" id="cityid">
     64        <option th:each="city : ${cities}" th:value="${city.cityid}" th:name="city" th:text="${city.cityname}">
    6565        </option>
    6666        </select>
  • cimeri-main/src/main/resources/templates/postapartment.html

    rbc30bce r087ce2b  
    9999                <br />
    100100              </span>
    101               <select class="postapartment-textinput2 input" name="cityname" id="cityname">
    102                 <option th:each="city : ${cities}" th:value="${city.cityname}" th:name="city" th:text="${city.cityname}">
     101              <select class="postapartment-textinput2 input" name="cityid" id="cityid">
     102                <option th:each="city : ${cities}" th:value="${city.cityid}" th:name="city" th:text="${city.cityname}">
    103103                </option>
    104104              </select>
  • cimeri-main/target/classes/templates/findapartments.html

    rbc30bce r087ce2b  
    6161        <span class="findapartments-text06">CITY</span>
    6262
    63         <select class="findapartments-textinput1 input" name="cityname" id="cityname">
    64         <option th:each="city : ${cities}" th:value="${city.cityname}" th:name="city" th:text="${city.cityname}">
     63        <select class="findapartments-textinput1 input" name="cityid" id="cityid">
     64        <option th:each="city : ${cities}" th:value="${city.cityid}" th:name="city" th:text="${city.cityname}">
    6565        </option>
    6666        </select>
  • cimeri-main/target/classes/templates/findroommates.html

    rbc30bce r087ce2b  
    6161        <span class="findroommates-text06">CITY</span>
    6262
    63         <select class="findroommates-textinput1 input" name="cityname" id="cityname">
    64         <option th:each="city : ${cities}" th:value="${city.cityname}" th:name="city" th:text="${city.cityname}">
     63        <select class="findroommates-textinput1 input" name="cityid" id="cityid">
     64        <option th:each="city : ${cities}" th:value="${city.cityid}" th:name="city" th:text="${city.cityname}">
    6565        </option>
    6666        </select>
  • cimeri-main/target/classes/templates/postapartment.html

    rbc30bce r087ce2b  
    9999                <br />
    100100              </span>
    101               <select class="postapartment-textinput2 input" name="cityname" id="cityname">
    102                 <option th:each="city : ${cities}" th:value="${city.cityname}" th:name="city" th:text="${city.cityname}">
     101              <select class="postapartment-textinput2 input" name="cityid" id="cityid">
     102                <option th:each="city : ${cities}" th:value="${city.cityid}" th:name="city" th:text="${city.cityname}">
    103103                </option>
    104104              </select>
Note: See TracChangeset for help on using the changeset viewer.