Changeset 7cb8c3c


Ignore:
Timestamp:
07/28/22 21:12:41 (2 years ago)
Author:
unknown <mlviktor23@…>
Branches:
main
Children:
4a64cf0
Parents:
0e62f4d
Message:

swapped JsonManaged/BackReference with JsonIdentityInfo in Model, created React app

Files:
19 added
14 edited

Legend:

Unmodified
Added
Removed
  • springapp/src/main/java/mk/profesori/springapp/Controller/MainController.java

    r0e62f4d r7cb8c3c  
    55
    66import org.springframework.beans.factory.annotation.Autowired;
     7import org.springframework.web.bind.annotation.CrossOrigin;
    78import org.springframework.web.bind.annotation.PathVariable;
    89import org.springframework.web.bind.annotation.RequestMapping;
     
    1920
    2021@RestController
     22@CrossOrigin(origins = "http://192.168.0.17:3000")
    2123public class MainController {
    2224   
  • springapp/src/main/java/mk/profesori/springapp/Model/City.java

    r0e62f4d r7cb8c3c  
    1212import javax.persistence.Table;
    1313
    14 import com.fasterxml.jackson.annotation.JsonManagedReference;
     14import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     15import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    1516
    1617@Entity
    1718@Table(name = "city")
     19@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "cityId")
    1820public class City {
    1921
     
    2931    private Set<University> universities = new HashSet<>();
    3032
    31     //getters
     33    // getters
    3234    public Long getCityId() {
    3335        return cityId;
     
    3840    }
    3941
    40     @JsonManagedReference
    4142    public Set<University> getUniversities() {
    4243        return universities;
    4344    }
    44    
     45
    4546}
  • springapp/src/main/java/mk/profesori/springapp/Model/CustomUserDetails.java

    r0e62f4d r7cb8c3c  
    2222import org.springframework.security.core.userdetails.UserDetails;
    2323
    24 import com.fasterxml.jackson.annotation.JsonManagedReference;
     24import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     25import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    2526
    2627import lombok.EqualsAndHashCode;
     
    3435@NoArgsConstructor
    3536@Entity
     37@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
    3638public class CustomUserDetails implements UserDetails {
    3739
     
    4042    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_sequence")
    4143    private Long id;
    42     private String fullName; //opcionalno, smee da e prazno
     44    private String fullName; // opcionalno, smee da e prazno
    4345    private String username;
    4446    private String email;
     
    9799    }
    98100
    99     @JsonManagedReference
    100101    List<Post> getAuthoredPosts() {
    101102        return this.authoredPosts;
    102103    }
    103    
     104
    104105}
  • springapp/src/main/java/mk/profesori/springapp/Model/Faculty.java

    r0e62f4d r7cb8c3c  
    1414import javax.persistence.Table;
    1515
    16 import com.fasterxml.jackson.annotation.JsonBackReference;
    17 import com.fasterxml.jackson.annotation.JsonManagedReference;
     16import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     17import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    1818
    1919@Entity
    2020@Table(name = "faculty")
     21@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "facultyId")
    2122public class Faculty {
    2223
     
    3940    private Set<StudyProgramme> studyProgrammes = new HashSet<>();
    4041
    41     //getters
     42    // getters
    4243    public Long getFacultyId() {
    4344        return facultyId;
     
    4849    }
    4950
    50     @JsonBackReference
    5151    public University getUniversity() {
    5252        return university;
    5353    }
    5454
    55     @JsonManagedReference
    5655    public Set<Professor> getProfessors() {
    5756        return professors;
    5857    }
    5958
    60     @JsonManagedReference
    6159    public Set<StudyProgramme> getStudyProgrammes() {
    6260        return studyProgrammes;
    6361    }
    64    
     62
    6563}
  • springapp/src/main/java/mk/profesori/springapp/Model/Opinion.java

    r0e62f4d r7cb8c3c  
    99import javax.persistence.ManyToOne;
    1010
    11 import com.fasterxml.jackson.annotation.JsonBackReference;
    12 
    1311@Entity
    1412@DiscriminatorValue("opinion")
    15 public class Opinion extends Post{
     13public class Opinion extends Post {
    1614
    1715    @ManyToOne
     
    2624    }
    2725
    28     //getters and setters
    29     @JsonBackReference
     26    // getters and setters
    3027    public Professor getTargetProfessor() {
    3128        return targetProfessor;
  • springapp/src/main/java/mk/profesori/springapp/Model/Post.java

    r0e62f4d r7cb8c3c  
    1919import javax.persistence.OneToMany;
    2020
    21 import com.fasterxml.jackson.annotation.JsonBackReference;
    22 import com.fasterxml.jackson.annotation.JsonManagedReference;
     21import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     22import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    2323
    24 @Entity(name="post")
     24@Entity(name = "post")
    2525@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    26 @DiscriminatorColumn(name="post_type",
    27   discriminatorType = DiscriminatorType.STRING)
     26@DiscriminatorColumn(name = "post_type", discriminatorType = DiscriminatorType.STRING)
     27@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "postId")
    2828public class Post {
    29    
     29
    3030    @Id
    3131    @GeneratedValue(strategy = GenerationType.IDENTITY)
    3232    @Column(name = "id")
    3333    private Long postId;
    34    
     34
    3535    @Column(name = "title")
    3636    private String title;
    3737
    38     @Column(name = "content", columnDefinition="TEXT")
     38    @Column(name = "content", columnDefinition = "TEXT")
    3939    private String content;
    40    
     40
    4141    @ManyToOne
    4242    @JoinColumn(name = "custom_user_details_id")
    4343    private CustomUserDetails author;
    44    
     44
    4545    @Column(name = "time_posted")
    4646    private LocalDateTime timePosted;
     
    5858    @JoinColumn(name = "parent_post_id", nullable = true)
    5959    private Post parent;
    60    
     60
    6161    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
    6262    private List<Post> children = new ArrayList<>();
    6363
    64     //getters and setters
     64    // getters and setters
    6565    public Long getPostId() {
    6666        return postId;
     
    8686        this.content = content;
    8787    }
    88    
    89     @JsonBackReference
     88
    9089    public CustomUserDetails getAuthor() {
    9190        return author;
     
    128127    }
    129128
    130     @JsonBackReference
    131129    public Post getParent() {
    132130        return parent;
     
    137135    }
    138136
    139     @JsonManagedReference
    140137    public List<Post> getChildren() {
    141138        return children;
     
    160157        this.children = children;
    161158    }
    162    
     159
    163160}
  • springapp/src/main/java/mk/profesori/springapp/Model/Professor.java

    r0e62f4d r7cb8c3c  
    22
    33import java.util.ArrayList;
    4 import java.util.HashSet;
    54import java.util.List;
    6 import java.util.Set;
    7 
    85import javax.persistence.CascadeType;
    96import javax.persistence.Column;
     
    1714import javax.persistence.Table;
    1815
    19 import com.fasterxml.jackson.annotation.JsonBackReference;
    20 import com.fasterxml.jackson.annotation.JsonManagedReference;
     16import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     17import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    2118
    2219@Entity
    2320@Table(name = "professor")
     21@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "professorId")
    2422public class Professor {
    2523
     
    3937    private List<Opinion> relatedOpinions = new ArrayList<Opinion>();
    4038
    41     //getters
     39    // getters
    4240    public Long getProfessorId() {
    4341        return professorId;
     
    4846    }
    4947
    50     @JsonBackReference
    5148    public Faculty getFaculty() {
    5249        return faculty;
    5350    }
    5451
    55     @JsonManagedReference
    5652    public List<Opinion> getRelatedOpinions() {
    5753        return relatedOpinions;
  • springapp/src/main/java/mk/profesori/springapp/Model/Section.java

    r0e62f4d r7cb8c3c  
    1414import javax.persistence.OneToOne;
    1515
    16 import com.fasterxml.jackson.annotation.JsonBackReference;
    17 import com.fasterxml.jackson.annotation.JsonManagedReference;
     16import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     17import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    1818
    1919@Entity
     20@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "sectionId")
    2021public class Section {
    21    
     22
    2223    @Id
    2324    @GeneratedValue(strategy = GenerationType.IDENTITY)
     
    3536    private StudyProgramme relatedStudyProgramme;
    3637
    37     //getters and setters
     38    // getters and setters
    3839    public Long getSectionId() {
    3940        return sectionId;
     
    4445    }
    4546
    46     @JsonManagedReference
    4747    public List<_Thread> getThreads() {
    4848        return threads;
     
    5353    }
    5454
    55     @JsonBackReference
    5655    public StudyProgramme getRelatedStudyProgramme() {
    5756        return relatedStudyProgramme;
     
    6766        this.relatedStudyProgramme = relatedStudyProgramme;
    6867    }
    69    
     68
    7069}
  • springapp/src/main/java/mk/profesori/springapp/Model/StudyProgramme.java

    r0e62f4d r7cb8c3c  
    1515import javax.persistence.Table;
    1616
    17 import com.fasterxml.jackson.annotation.JsonBackReference;
    18 import com.fasterxml.jackson.annotation.JsonManagedReference;
     17import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     18import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    1919
    2020@Entity
    2121@Table(name = "study_programme")
     22@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "studyProgrammeId")
    2223public class StudyProgramme {
    2324
     
    4344    private Section relatedSection;
    4445
    45     //getters
     46    // getters
    4647    public Long getStudyProgrammeId() {
    4748        return studyProgrammeId;
     
    5657    }
    5758
    58     @JsonBackReference
    5959    public Faculty getFaculty() {
    6060        return faculty;
    6161    }
    6262
    63     @JsonManagedReference
    6463    public Set<Subject> getSubjects() {
    6564        return subjects;
    6665    }
    6766
    68     @JsonManagedReference
    6967    public Section getRelatedSection() {
    7068        return relatedSection;
  • springapp/src/main/java/mk/profesori/springapp/Model/Subject.java

    r0e62f4d r7cb8c3c  
    22
    33import java.util.ArrayList;
    4 import java.util.HashSet;
    54import java.util.List;
    6 import java.util.Set;
    7 
    85import javax.persistence.CascadeType;
    96import javax.persistence.Column;
     
    1714import javax.persistence.Table;
    1815
    19 import com.fasterxml.jackson.annotation.JsonBackReference;
    20 import com.fasterxml.jackson.annotation.JsonManagedReference;
     16import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     17import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    2118
    2219@Entity
    2320@Table(name = "subject")
     21@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "subjectId")
    2422public class Subject {
    2523
     
    3937    private List<_Thread> threads = new ArrayList<>();
    4038
    41     //getters
     39    // getters
    4240    public Long getSubjectId() {
    4341        return subjectId;
     
    4846    }
    4947
    50     @JsonBackReference
    5148    public StudyProgramme getStudyProgramme() {
    5249        return studyProgramme;
    5350    }
    5451
    55     @JsonManagedReference
    5652    public List<_Thread> getThreads() {
    5753        return threads;
    5854    }
    59    
     55
    6056}
  • springapp/src/main/java/mk/profesori/springapp/Model/University.java

    r0e62f4d r7cb8c3c  
    1414import javax.persistence.Table;
    1515
    16 import com.fasterxml.jackson.annotation.JsonBackReference;
    17 import com.fasterxml.jackson.annotation.JsonManagedReference;
     16import com.fasterxml.jackson.annotation.JsonIdentityInfo;
     17import com.fasterxml.jackson.annotation.ObjectIdGenerators;
    1818
    1919@Entity
    20 @Table(name="university")
     20@Table(name = "university")
     21@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "universityId")
    2122public class University {
    2223
     
    3637    private Set<Faculty> faculties = new HashSet<>();
    3738
    38     //getters
     39    // getters
    3940    public Long getUniversityId() {
    4041        return universityId;
     
    4546    }
    4647
    47     @JsonBackReference
    4848    public City getCity() {
    4949        return city;
    5050    }
    5151
    52     @JsonManagedReference
    5352    public Set<Faculty> getFaculties() {
    5453        return faculties;
    5554    }
    56    
     55
    5756}
  • springapp/src/main/java/mk/profesori/springapp/Model/_Thread.java

    r0e62f4d r7cb8c3c  
    1111import javax.persistence.JoinColumn;
    1212import javax.persistence.ManyToOne;
    13 
    14 import com.fasterxml.jackson.annotation.JsonBackReference;
    1513
    1614@Entity
     
    3937    }
    4038
    41     //getters
     39    // getters
    4240    public List<String> getTags() {
    4341        return tags;
    4442    }
    4543
    46     @JsonBackReference
    4744    public Section getParentSection() {
    4845        return parentSection;
    4946    }
    5047
    51     @JsonBackReference
    5248    public Subject getTargetSubject() {
    5349        return targetSubject;
    5450    }
    55    
     51
    5652}
  • springapp/src/main/java/mk/profesori/springapp/Repository/UniversityRepository.java

    r0e62f4d r7cb8c3c  
    77
    88import mk.profesori.springapp.Model.City;
    9 import mk.profesori.springapp.Model.Faculty;
    109import mk.profesori.springapp.Model.University;
    1110
    1211@Repository
    13 public interface UniversityRepository extends CrudRepository<University, Long>{
     12public interface UniversityRepository extends CrudRepository<University, Long> {
    1413
    1514    public List<University> findAll();
     15
    1616    public University findByUniversityId(Long id);
     17
    1718    public List<University> findByCity(City city);
    1819}
  • springapp/src/main/java/mk/profesori/springapp/Security/SecurityConfiguration.java

    r0e62f4d r7cb8c3c  
    11package mk.profesori.springapp.Security;
    22
    3 import org.springframework.beans.factory.annotation.Autowired;
    43import org.springframework.context.annotation.Bean;
    54import org.springframework.context.annotation.Configuration;
     
    2827
    2928    @Bean
    30     public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
     29    public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration)
     30            throws Exception {
    3131        return authenticationConfiguration.getAuthenticationManager();
    3232    }
    33    
     33
    3434    @Bean
    3535    protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    3636        http
    37             .csrf().disable() //PRIVREMENO
    38             .authorizeRequests()
     37                .cors()
     38                .and()
     39                .csrf().disable() // PRIVREMENO
     40                .authorizeRequests()
    3941                .antMatchers("/registration/**")
    4042                .permitAll()
    41             .anyRequest()
    42             .authenticated().and()
    43             .formLogin();
    44        
     43                .anyRequest()
     44                .permitAll().and() // bese .authenticated()
     45                .formLogin();
     46
    4547        return http.build();
    4648    }
Note: See TracChangeset for help on using the changeset viewer.