Changeset 9bf1f8d for springapp/src
- Timestamp:
- 01/20/23 22:57:18 (22 months ago)
- Branches:
- main
- Children:
- 8dffe02
- Parents:
- 4abf55a
- Location:
- springapp/src/main
- Files:
-
- 1 added
- 29 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
springapp/src/main/java/mk/profesori/springapp/Controller/PublicController.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Controller; 2 3 import mk.profesori.springapp.Model.*; 4 import mk.profesori.springapp.Service.MainService; 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.web.bind.annotation.*; 2 7 3 8 import java.util.Collections; … … 6 11 import java.util.Optional; 7 12 8 import org.springframework.beans.factory.annotation.Autowired;9 import org.springframework.web.bind.annotation.CrossOrigin;10 import org.springframework.web.bind.annotation.PathVariable;11 import org.springframework.web.bind.annotation.RequestMapping;12 import org.springframework.web.bind.annotation.RequestMethod;13 import org.springframework.web.bind.annotation.RequestParam;14 import org.springframework.web.bind.annotation.RestController;15 16 import mk.profesori.springapp.Model.City;17 import mk.profesori.springapp.Model.Faculty;18 import mk.profesori.springapp.Model.Professor;19 import mk.profesori.springapp.Model.StudyProgramme;20 import mk.profesori.springapp.Model.Subject;21 import mk.profesori.springapp.Model.University;22 import mk.profesori.springapp.Model._Thread;23 import mk.profesori.springapp.Service.MainService;24 25 13 @RestController 26 14 @RequestMapping("/public") 27 @CrossOrigin(origins = { "http://192.168. 0.29:3000", "http://192.168.0.28:3000" })15 @CrossOrigin(origins = { "http://192.168.1.254:3000", "http://192.168.0.28:3000" }) 28 16 public class PublicController { 29 17 … … 42 30 @RequestMapping(value = "/professors/nameContains/{contained}", method = RequestMethod.GET) 43 31 public List<Professor> getProfessorsByNameContains(@PathVariable String contained) { 44 return mainService.getProfessorsByNameContains(contained); // vrakja profesori sto sodrzat "contained" vo 45 // professorName 32 return mainService.getProfessorsByNameContains(contained); // vrakja profesori sto sodrzat "contained" vo imeto 33 34 } 35 36 @RequestMapping(value = "/subjects/nameContains/{contained}", method = RequestMethod.GET) 37 public List<Subject> getSubjectsByNameContains(@PathVariable String contained) { 38 return mainService.getSubjectsByNameContains(contained); // vrakja predmeti sto sodrzat "contained" vo imeto 46 39 } 47 40 … … 49 42 public Professor getProfessorById(@PathVariable Long professorId) { 50 43 return mainService.getProfessorById(professorId); // vrakja profesor spored id 44 } 45 46 @RequestMapping(value="/professor/{professorId}/relatedOpinions", method = RequestMethod.GET) 47 public List<Opinion> getRelatedOpinions(@PathVariable Long professorId) { 48 return mainService.getRelatedOpinions(professorId); 51 49 } 52 50 … … 105 103 } 106 104 105 @RequestMapping(value = "/subjects", method = RequestMethod.GET) 106 public List<Subject> getSubjectsByStudyProgramme(@RequestParam Long studyProgrammeId) { 107 return mainService.getSubjectsByStudyProgramme(studyProgrammeId); 108 } 109 107 110 @RequestMapping(value = "/thread/{postId}", method = RequestMethod.GET) 108 111 public _Thread getThreadById(@PathVariable Long postId) { … … 119 122 return Collections.singletonMap("sessionId", sessionId); 120 123 } 124 125 @RequestMapping(value = "/latest10opinions", method = RequestMethod.GET) 126 public List<Opinion> latest10opinions() { 127 return mainService.getLatest10Opinions(); 128 } 129 130 @RequestMapping(value = "/latest10threads", method = RequestMethod.GET) 131 public List<_Thread> latest10threads() { 132 return mainService.getLatest10Threads(); 133 } 134 135 @RequestMapping(value = "/subject/{id}/threads") 136 public List<_Thread> getThreadsBySubject(@PathVariable Long id) { 137 return mainService.getThreadsBySubject(id); 138 } 139 140 @RequestMapping(value = "/university/{id}/sectionAndPostCount") 141 public List<String> getUniversitySectionCount(@PathVariable Long id) { 142 return mainService.getUniversitySectionAndPostCount(); 143 } 144 145 @RequestMapping(value = "/faculty/{id}/opinionCountForEachProfessor") 146 public List<String> getOpinionCountForEachProfessorInFaculty(@PathVariable Long id) { 147 return mainService.getOpinionCountForEachProfessorInFaculty(id); 148 } 149 150 @RequestMapping(value = "/study_programme/{id}/threadCountForEachSubject") 151 public List<String> getThreadCountForEachSubjectInStudyProgramme(@PathVariable Long id) { 152 return mainService.getThreadCountForEachSubjectInStudyProgramme(id); 153 } 154 155 @RequestMapping(value = "/user/{id}") 156 public CustomUserDetails getPublicUserProfile(@PathVariable Long id) { 157 return mainService.getPublicUserProfile(id); 158 } 159 121 160 } -
springapp/src/main/java/mk/profesori/springapp/Controller/SecureController.java
r4abf55a r9bf1f8d 3 3 import com.fasterxml.jackson.databind.node.ObjectNode; 4 4 import mk.profesori.springapp.Model.CustomUserDetails; 5 import mk.profesori.springapp.Model.Post; 5 6 import mk.profesori.springapp.Model.PostReport; 6 7 import mk.profesori.springapp.Model.UserRole; 7 8 import mk.profesori.springapp.Service.CustomUserDetailsService; 8 import mk.profesori.springapp.Service. DisallowedOperationException;9 import mk.profesori.springapp.Service. IncompatiblePostId;9 import mk.profesori.springapp.Service.Exception.DisallowedOperationException; 10 import mk.profesori.springapp.Service.Exception.IncompatiblePostId; 10 11 import mk.profesori.springapp.Service.MainService; 11 12 import org.apache.tomcat.websocket.AuthenticationException; … … 17 18 18 19 import java.util.List; 20 import java.util.Set; 19 21 20 22 @RestController 21 23 @RequestMapping("/secure") 22 @CrossOrigin(origins = { "http://192.168. 0.29:3000", "http://192.168.0.28:3000" })24 @CrossOrigin(origins = { "http://192.168.1.254:3000", "http://192.168.0.28:3000" }) 23 25 public class SecureController { 24 26 … … 77 79 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 78 80 return customUserDetailsService.loadUserByUsername(currentUser.getEmail()); 81 } 82 return null; 83 } 84 85 @RequestMapping(value = "/currentUser/posts", method = RequestMethod.GET) 86 public Set<Post> getPostsByUser(@CurrentSecurityContext SecurityContext context) { 87 Authentication authentication = context.getAuthentication(); 88 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 89 return mainService.getPostsByUser(currentUser.getEmail()); 79 90 } 80 91 return null; -
springapp/src/main/java/mk/profesori/springapp/Model/City.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 2 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.Data; 6 7 import javax.persistence.*; 3 8 import java.util.HashSet; 4 9 import java.util.Set; 5 10 6 import javax.persistence.Column;7 import javax.persistence.Entity;8 import javax.persistence.GeneratedValue;9 import javax.persistence.GenerationType;10 import javax.persistence.Id;11 import javax.persistence.OneToMany;12 import javax.persistence.Table;13 14 import com.fasterxml.jackson.annotation.JsonIdentityInfo;15 import com.fasterxml.jackson.annotation.ObjectIdGenerators;16 17 11 @Entity 12 @Data 18 13 @Table(name = "city") 19 @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "cityId")14 @JsonIdentityInfo(generator = JSOGGenerator.class) 20 15 public class City { 21 16 … … 28 23 private String cityName; 29 24 25 @Transient 30 26 @OneToMany(mappedBy = "city") 31 27 private Set<University> universities = new HashSet<>(); 32 28 33 // getters34 public Long getCityId() {35 return cityId;36 }37 38 public String getCityName() {39 return cityName;40 }41 42 public Set<University> getUniversities() {43 return universities;44 }45 46 29 } -
springapp/src/main/java/mk/profesori/springapp/Model/CustomUserDetails.java
r4abf55a r9bf1f8d 2 2 3 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 import com.fasterxml.jackson.annotation.JsonIgnore; 4 5 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 6 import lombok.EqualsAndHashCode; … … 31 32 private String fullName; 32 33 private String username; 34 @JsonIgnore 33 35 private String email; 34 private String password; // TODO 36 @JsonIgnore 37 private String password; 38 /* UseCases 39 го уредува својот кориснички профил 40 го верификува својот кориснички профил todo... 41 */ 35 42 @Enumerated(EnumType.STRING) 36 43 private UserRole userRole; 37 44 private Boolean locked = false; 38 45 private Boolean enabled = false; 39 @OneToMany(mappedBy = "customUserDetails", fetch = FetchType.EAGER, orphanRemoval = true) 46 @Transient 47 @OneToMany(mappedBy = "customUserDetails", orphanRemoval = true) 40 48 private Set<ConfirmationToken> confirmationTokens = new HashSet<>(); 41 @OneToMany(mappedBy = "author", fetch = FetchType.EAGER, orphanRemoval = true) 49 @Transient 50 @OneToMany(mappedBy = "author", orphanRemoval = true) 42 51 private Set<Post> authoredPosts = new HashSet<>(); 43 52 private Integer karma = 0; 44 53 54 @Transient 45 55 @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) 46 56 private Set<PostVote> votes = new HashSet<>(); 47 57 58 @Transient 48 59 @OneToMany(mappedBy = "user", cascade = {CascadeType.PERSIST}) 49 60 private Set<PostReport> reportsSubmitted = new HashSet<>(); … … 99 110 } 100 111 101 public Set<Post> getAuthoredPosts() {102 return this.authoredPosts;103 }104 105 public Integer getKarma() {106 return this.karma;107 }108 109 public void setKarma(Integer karma) {110 this.karma = karma;111 }112 113 112 @Override 114 113 public String toString() { 115 114 return this.id.toString(); 116 115 } 117 118 public void setLocked(Boolean locked) {119 this.locked = locked;120 }121 122 public Set<PostVote> getVotes() {123 return votes;124 }125 126 public void setVotes(Set<PostVote> votes) {127 this.votes = votes;128 }129 116 } -
springapp/src/main/java/mk/profesori/springapp/Model/Faculty.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 2 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.Data; 6 7 import javax.persistence.*; 3 8 import java.util.HashSet; 4 9 import java.util.Set; 5 10 6 import javax.persistence.Column;7 import javax.persistence.Entity;8 import javax.persistence.GeneratedValue;9 import javax.persistence.GenerationType;10 import javax.persistence.Id;11 import javax.persistence.JoinColumn;12 import javax.persistence.ManyToOne;13 import javax.persistence.OneToMany;14 import javax.persistence.Table;15 16 import com.fasterxml.jackson.annotation.JsonIdentityInfo;17 import com.voodoodyne.jackson.jsog.JSOGGenerator;18 19 11 @Entity 12 @Data 20 13 @Table(name = "faculty") 21 14 @JsonIdentityInfo(generator = JSOGGenerator.class) … … 34 27 private University university; 35 28 29 @Transient 36 30 @OneToMany(mappedBy = "faculty") 37 31 private Set<Professor> professors = new HashSet<>(); 38 32 33 @Transient 39 34 @OneToMany(mappedBy = "faculty") 40 35 private Set<StudyProgramme> studyProgrammes = new HashSet<>(); 41 36 42 // getters43 public Long getFacultyId() {44 return facultyId;45 }46 47 public String getFacultyName() {48 return facultyName;49 }50 51 public University getUniversity() {52 return university;53 }54 55 public Set<Professor> getProfessors() {56 return professors;57 }58 59 public Set<StudyProgramme> getStudyProgrammes() {60 return studyProgrammes;61 }62 63 37 } -
springapp/src/main/java/mk/profesori/springapp/Model/Opinion.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 2 3 import java.time.LocalDateTime;4 import java.util.List;3 import lombok.Data; 4 import lombok.NoArgsConstructor; 5 5 6 6 import javax.persistence.DiscriminatorValue; … … 8 8 import javax.persistence.JoinColumn; 9 9 import javax.persistence.ManyToOne; 10 11 import lombok.NoArgsConstructor;10 import java.time.LocalDateTime; 11 import java.util.List; 12 12 13 13 @Entity 14 @Data 14 15 @DiscriminatorValue("opinion") 15 16 @NoArgsConstructor … … 35 36 this.targetProfessor = targetProfessor; 36 37 } 37 38 // getters and setters39 public Professor getTargetProfessor() {40 return targetProfessor;41 }42 public void setTargetProfessor(Professor targetProfessor) {43 this.targetProfessor = targetProfessor;44 }45 46 38 } -
springapp/src/main/java/mk/profesori/springapp/Model/Post.java
r4abf55a r9bf1f8d 3 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.Data; 5 6 import lombok.NoArgsConstructor; 6 7 … … 13 14 14 15 @Entity(name = "post") 16 @Data 15 17 @Inheritance(strategy = InheritanceType.SINGLE_TABLE) 16 18 @DiscriminatorColumn(name = "post_type", discriminatorType = DiscriminatorType.STRING) … … 44 46 private Post parent; 45 47 46 @OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true )48 @OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER) 47 49 private Set<PostVote> votes = new HashSet<>(); 48 50 49 @OneToMany(mappedBy = "post", cascade={CascadeType.PERSIST} )51 @OneToMany(mappedBy = "post", cascade={CascadeType.PERSIST}, fetch = FetchType.EAGER) 50 52 private Set<PostReport> reports = new HashSet<>(); 53 51 54 @PreRemove 52 55 public void preRemove() { … … 56 59 }); 57 60 } 58 59 60 @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true) 61 @OneToMany(mappedBy = "parent", orphanRemoval = true, fetch = FetchType.EAGER) 61 62 private List<Post> children = new ArrayList<>(); 62 63 // getters and setters64 public Set<PostVote> getVotes() {65 return votes;66 }67 68 public void setVotes(Set<PostVote> votes) {69 this.votes = votes;70 }71 public Long getPostId() {72 return postId;73 }74 75 public void setPostId(Long postId) {76 this.postId = postId;77 }78 79 public String getTitle() {80 return title;81 }82 83 public void setTitle(String title) {84 this.title = title;85 }86 87 public String getContent() {88 return content;89 }90 91 public void setContent(String content) {92 this.content = content;93 }94 95 public CustomUserDetails getAuthor() {96 return author;97 }98 99 public void setAuthor(CustomUserDetails author) {100 this.author = author;101 }102 103 public LocalDateTime getTimePosted() {104 return timePosted;105 }106 107 public void setTimePosted(LocalDateTime timePosted) {108 this.timePosted = timePosted;109 }110 111 public LocalDateTime getTimeLastEdited() {112 return timeLastEdited;113 }114 115 public void setTimeLastEdited(LocalDateTime timeLastEdited) {116 this.timeLastEdited = timeLastEdited;117 }118 119 public Post getParent() {120 return parent;121 }122 123 public void setParent(Post parent) {124 this.parent = parent;125 }126 127 public List<Post> getChildren() {128 return children;129 }130 131 public void setChildren(List<Post> children) {132 this.children = children;133 }134 63 135 64 // konstruktor so parent (koga e reply) -
springapp/src/main/java/mk/profesori/springapp/Model/PostReport.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 2 3 import lombok.Data; 3 4 import lombok.NoArgsConstructor; 4 5 … … 7 8 8 9 @Entity 10 @Data 9 11 @NoArgsConstructor 10 12 public class PostReport { … … 38 40 this.resolved=false; 39 41 } 40 41 public boolean isResolved() {42 return resolved;43 }44 45 public void setResolved(boolean resolved) {46 this.resolved = resolved;47 }48 49 public Long getPostReportId() {50 return postReportId;51 }52 53 public void setPostReportId(Long postReportId) {54 this.postReportId = postReportId;55 }56 57 public CustomUserDetails getUser() {58 return user;59 }60 61 public void setUser(CustomUserDetails user) {62 this.user = user;63 }64 65 public Post getPost() {66 return post;67 }68 69 public void setPost(Post post) {70 this.post = post;71 }72 73 public LocalDateTime getTime() {74 return time;75 }76 77 public void setTime(LocalDateTime time) {78 this.time = time;79 }80 81 public String getDescription() {82 return description;83 }84 85 public void setDescription(String description) {86 this.description = description;87 }88 42 } -
springapp/src/main/java/mk/profesori/springapp/Model/PostVote.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 2 3 import lombok.Data; 3 4 import lombok.NoArgsConstructor; 4 5 … … 7 8 8 9 @Entity 10 @Data 9 11 @NoArgsConstructor 10 12 public class PostVote { … … 34 36 this.vote = vote; 35 37 } 36 37 public Long getPostVoteId() {38 return postVoteId;39 }40 41 public void setPostVoteId(Long id) {42 this.postVoteId = id;43 }44 45 public CustomUserDetails getUser() {46 return user;47 }48 49 public void setUser(CustomUserDetails user) {50 this.user = user;51 }52 53 public Post getPost() {54 return post;55 }56 57 public void setPost(Post post) {58 this.post = post;59 }60 61 public LocalDateTime getTime() {62 return time;63 }64 65 public void setTime(LocalDateTime time) {66 this.time = time;67 }68 69 public VoteType getVote() {70 return vote;71 }72 73 public void setVote(VoteType vote) {74 this.vote = vote;75 }76 38 } -
springapp/src/main/java/mk/profesori/springapp/Model/Professor.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 3 import java.util.ArrayList;4 import java.util.List;5 import javax.persistence.CascadeType;6 import javax.persistence.Column;7 import javax.persistence.Entity;8 import javax.persistence.GeneratedValue;9 import javax.persistence.GenerationType;10 import javax.persistence.Id;11 import javax.persistence.JoinColumn;12 import javax.persistence.ManyToOne;13 import javax.persistence.OneToMany;14 import javax.persistence.Table;15 2 16 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 17 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.Data; 6 7 import javax.persistence.*; 8 import java.util.ArrayList; 9 import java.util.List; 18 10 19 11 @Entity 12 @Data 20 13 @Table(name = "professor") 21 14 @JsonIdentityInfo(generator = JSOGGenerator.class) … … 34 27 private Faculty faculty; 35 28 29 @Transient 36 30 @OneToMany(mappedBy = "targetProfessor", cascade = CascadeType.ALL) 37 private List<Opinion> relatedOpinions = new ArrayList<Opinion>(); 38 39 // getters 40 public Long getProfessorId() { 41 return professorId; 42 } 43 44 public String getProfessorName() { 45 return professorName; 46 } 47 48 public Faculty getFaculty() { 49 return faculty; 50 } 51 52 public List<Opinion> getRelatedOpinions() { 53 return relatedOpinions; 54 } 31 private List<Opinion> relatedOpinions = new ArrayList<>(); 55 32 } -
springapp/src/main/java/mk/profesori/springapp/Model/StudyProgramme.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 2 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.Data; 6 7 import javax.persistence.*; 3 8 import java.util.HashSet; 4 9 import java.util.Set; 5 10 6 import javax.persistence.Column;7 import javax.persistence.Entity;8 import javax.persistence.GeneratedValue;9 import javax.persistence.GenerationType;10 import javax.persistence.Id;11 import javax.persistence.JoinColumn;12 import javax.persistence.ManyToOne;13 import javax.persistence.OneToMany;14 import javax.persistence.Table;15 16 import com.fasterxml.jackson.annotation.JsonIdentityInfo;17 import com.voodoodyne.jackson.jsog.JSOGGenerator;18 19 11 @Entity 12 @Data 20 13 @Table(name = "study_programme") 21 14 @JsonIdentityInfo(generator = JSOGGenerator.class) … … 37 30 private Faculty faculty; 38 31 32 @Transient 39 33 @OneToMany(mappedBy = "studyProgramme") 40 34 private Set<Subject> subjects = new HashSet<>(); 41 35 42 // getters43 public Long getStudyProgrammeId() {44 return studyProgrammeId;45 }46 47 public String getStudyProgrammeName() {48 return studyProgrammeName;49 }50 51 public int getCycle() {52 return cycle;53 }54 55 public Faculty getFaculty() {56 return faculty;57 }58 59 public Set<Subject> getSubjects() {60 return subjects;61 }62 63 36 } -
springapp/src/main/java/mk/profesori/springapp/Model/Subject.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 3 import java.util.ArrayList;4 import java.util.List;5 import javax.persistence.CascadeType;6 import javax.persistence.Column;7 import javax.persistence.Entity;8 import javax.persistence.GeneratedValue;9 import javax.persistence.GenerationType;10 import javax.persistence.Id;11 import javax.persistence.JoinColumn;12 import javax.persistence.ManyToOne;13 import javax.persistence.OneToMany;14 import javax.persistence.Table;15 2 16 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 17 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.Data; 6 7 import javax.persistence.*; 8 import java.util.ArrayList; 9 import java.util.List; 18 10 19 11 @Entity 12 @Data 20 13 @Table(name = "subject") 21 14 @JsonIdentityInfo(generator = JSOGGenerator.class) … … 34 27 private StudyProgramme studyProgramme; 35 28 29 @Transient 36 30 @OneToMany(mappedBy = "targetSubject", cascade = CascadeType.ALL) 37 31 private List<_Thread> threads = new ArrayList<>(); 38 32 39 // getters40 public Long getSubjectId() {41 return subjectId;42 }43 44 public String getSubjectName() {45 return subjectName;46 }47 48 public StudyProgramme getStudyProgramme() {49 return studyProgramme;50 }51 52 public List<_Thread> getThreads() {53 return threads;54 }55 56 33 } -
springapp/src/main/java/mk/profesori/springapp/Model/University.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 2 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.Data; 6 7 import javax.persistence.*; 3 8 import java.util.HashSet; 4 9 import java.util.Set; 5 10 6 import javax.persistence.Column;7 import javax.persistence.Entity;8 import javax.persistence.GeneratedValue;9 import javax.persistence.GenerationType;10 import javax.persistence.Id;11 import javax.persistence.JoinColumn;12 import javax.persistence.ManyToOne;13 import javax.persistence.OneToMany;14 import javax.persistence.Table;15 16 import com.fasterxml.jackson.annotation.JsonIdentityInfo;17 import com.voodoodyne.jackson.jsog.JSOGGenerator;18 19 11 @Entity 12 @Data 20 13 @Table(name = "university") 21 14 @JsonIdentityInfo(generator = JSOGGenerator.class) … … 34 27 private City city; 35 28 29 @Transient 36 30 @OneToMany(mappedBy = "university") 37 31 private Set<Faculty> faculties = new HashSet<>(); 38 39 // getters40 public Long getUniversityId() {41 return universityId;42 }43 44 public String getUniversityName() {45 return universityName;46 }47 48 public City getCity() {49 return city;50 }51 52 public Set<Faculty> getFaculties() {53 return faculties;54 }55 56 32 } -
springapp/src/main/java/mk/profesori/springapp/Model/_Thread.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Model; 2 2 3 import java.time.LocalDateTime; 4 5 import java.util.List; 3 import lombok.Data; 4 import lombok.NoArgsConstructor; 6 5 7 6 import javax.persistence.DiscriminatorValue; 8 9 7 import javax.persistence.Entity; 10 8 import javax.persistence.JoinColumn; 11 9 import javax.persistence.ManyToOne; 12 13 import lombok.NoArgsConstructor;10 import java.time.LocalDateTime; 11 import java.util.List; 14 12 15 13 @Entity 14 @Data 16 15 @DiscriminatorValue("thread") 17 16 @NoArgsConstructor … … 36 35 this.targetSubject = targetSubject; 37 36 } 38 39 public Subject getTargetSubject() {40 return targetSubject;41 }42 43 public void setTargetSubject(Subject targetSubject) {44 this.targetSubject = targetSubject;45 }46 37 } -
springapp/src/main/java/mk/profesori/springapp/Repository/CityRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 3 import mk.profesori.springapp.Model.City; 4 import org.springframework.data.repository.CrudRepository; 5 import org.springframework.stereotype.Repository; 2 6 3 7 import java.util.List; 4 8 5 import org.springframework.data.repository.CrudRepository;6 import org.springframework.stereotype.Repository;7 8 import mk.profesori.springapp.Model.City;9 10 9 @Repository 11 10 public interface CityRepository extends CrudRepository<City, Long>{ 12 13 11 List<City> findAll(); 14 12 City findByCityId(Long id); -
springapp/src/main/java/mk/profesori/springapp/Repository/FacultyRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 3 import mk.profesori.springapp.Model.Faculty; 4 import mk.profesori.springapp.Model.University; 5 import org.springframework.data.jpa.repository.Query; 6 import org.springframework.data.repository.CrudRepository; 7 import org.springframework.data.repository.query.Param; 8 import org.springframework.stereotype.Repository; 2 9 3 10 import java.util.List; 4 11 5 import org.springframework.data.repository.CrudRepository;6 import org.springframework.stereotype.Repository;7 8 import mk.profesori.springapp.Model.Faculty;9 import mk.profesori.springapp.Model.University;10 11 12 @Repository 12 13 public interface FacultyRepository extends CrudRepository<Faculty, Long>{ 13 14 14 List<Faculty> findAll(); 15 15 Faculty findByFacultyId(Long id); 16 16 List<Faculty> findByUniversity(University university); 17 @Query(value = "select professor.id, count(p.*)\n" + 18 "from professor left join post p on professor.id = p.professor_id\n" + 19 "where professor.faculty_id = :facultyId\n" + 20 "group by professor.id\n" + 21 "order by professor.id;", nativeQuery = true) 22 List<String> getOpinionCountForEachProfessorInFaculty(@Param("facultyId") Long id); 17 23 } -
springapp/src/main/java/mk/profesori/springapp/Repository/OpinionRepository.java
r4abf55a r9bf1f8d 2 2 3 3 import mk.profesori.springapp.Model.Opinion; 4 import mk.profesori.springapp.Model.Professor; 4 5 import org.springframework.data.repository.CrudRepository; 5 6 import org.springframework.stereotype.Repository; 7 8 import java.util.List; 6 9 7 10 @Repository 8 11 public interface OpinionRepository extends CrudRepository<Opinion,Long> { 9 12 Opinion findByPostId(Long postId); 13 List<Opinion> findByTargetProfessor(Professor p); 14 List<Opinion> findTop10ByOrderByTimePosted(); 10 15 } -
springapp/src/main/java/mk/profesori/springapp/Repository/PostVoteRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 2 3 import mk.profesori.springapp.Model.Post; 3 4 import mk.profesori.springapp.Model.PostVote; 4 5 import org.springframework.data.repository.CrudRepository; 5 6 import org.springframework.stereotype.Repository; 6 7 8 import java.util.List; 9 7 10 @Repository 8 11 public interface PostVoteRepository extends CrudRepository<PostVote,Long> { 9 12 PostVote findByPostVoteId(Long id); 13 List<PostVote> findByPost(Post post); 10 14 } -
springapp/src/main/java/mk/profesori/springapp/Repository/ProfessorRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 2 3 import java.util.List;4 3 import mk.profesori.springapp.Model.Faculty; 4 import mk.profesori.springapp.Model.Professor; 5 5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 6 6 import org.springframework.data.repository.CrudRepository; 7 7 import org.springframework.stereotype.Repository; 8 8 9 import mk.profesori.springapp.Model.Faculty; 10 import mk.profesori.springapp.Model.Professor; 9 import java.util.List; 11 10 12 11 @Repository … … 14 13 15 14 List<Professor> findAll(); 16 17 15 Professor findByProfessorId(Long id); 18 19 16 List<Professor> findByFaculty(Faculty faculty); 20 21 17 List<Professor> findByProfessorNameContainingIgnoreCase(String name); 22 18 } -
springapp/src/main/java/mk/profesori/springapp/Repository/StudyProgrammeRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 3 import java.util.List;4 5 import org.springframework.data.repository.CrudRepository;6 import org.springframework.stereotype.Repository;7 2 8 3 import mk.profesori.springapp.Model.Faculty; 9 4 import mk.profesori.springapp.Model.StudyProgramme; 5 import org.springframework.data.jpa.repository.Query; 6 import org.springframework.data.repository.CrudRepository; 7 import org.springframework.data.repository.query.Param; 8 import org.springframework.stereotype.Repository; 9 10 import java.util.List; 10 11 11 12 12 13 @Repository 13 14 public interface StudyProgrammeRepository extends CrudRepository<StudyProgramme, Long>{ 14 15 15 List<StudyProgramme> findAll(); 16 16 StudyProgramme findByStudyProgrammeId(Long id); 17 17 List<StudyProgramme> findByFaculty(Faculty faculty); 18 @Query(value = "select subject.id, count(p.*)\n" + 19 "from subject left join post p on subject.id = p.subject_id\n" + 20 "where subject.study_programme_id = :studyProgrammeId\n" + 21 "group by subject.id\n" + 22 "order by subject.id;", nativeQuery = true) 23 List<String> getThreadCountForEachSubjectInStudyProgramme(@Param("studyProgrammeId") Long id); 18 24 } -
springapp/src/main/java/mk/profesori/springapp/Repository/SubjectRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 2 3 import mk.profesori.springapp.Model.StudyProgramme; 4 import mk.profesori.springapp.Model.Subject; 3 5 import org.springframework.data.repository.CrudRepository; 4 6 import org.springframework.stereotype.Repository; 5 7 6 import mk.profesori.springapp.Model.Subject;8 import java.util.List; 7 9 8 10 @Repository 9 11 public interface SubjectRepository extends CrudRepository<Subject, Long> { 10 12 Subject findBySubjectId(Long id); 13 List<Subject> findByStudyProgramme(StudyProgramme studyProgramme); 14 List<Subject> findBySubjectNameContainingIgnoreCase(String name); 11 15 } -
springapp/src/main/java/mk/profesori/springapp/Repository/UniversityRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 3 import mk.profesori.springapp.Model.City; 4 import mk.profesori.springapp.Model.University; 5 import org.springframework.data.jpa.repository.Query; 6 import org.springframework.data.repository.CrudRepository; 7 import org.springframework.stereotype.Repository; 2 8 3 9 import java.util.List; 4 10 5 import org.springframework.data.repository.CrudRepository;6 import org.springframework.stereotype.Repository;7 8 import mk.profesori.springapp.Model.City;9 import mk.profesori.springapp.Model.University;10 11 11 @Repository 12 12 public interface UniversityRepository extends CrudRepository<University, Long> { 13 14 13 List<University> findAll(); 15 14 16 15 University findByUniversityId(Long id); 17 18 16 List<University> findByCity(City city); 17 18 @Query(value = "select facultyid, sectioncount, opinioncount from\n" + 19 "(select faculty_id as facultyid, t1.subject_count+t2.professor_count as sectioncount\n" + 20 "from (select sp.faculty_id, count(*) as subject_count\n" + 21 " from subject s join study_programme sp on s.study_programme_id = sp.id\n" + 22 " group by sp.faculty_id) as t1\n" + 23 " natural join\n" + 24 " (select count(*) as professor_count, f.id as faculty_id\n" + 25 " from professor p join faculty f on f.id = p.faculty_id\n" + 26 " group by f.id) as t2) as q1\n" + 27 "natural join\n" + 28 "(select facultyid, count1+count2 as opinioncount from\n" + 29 " (select pr.faculty_id as facultyid, count(*) as count1\n" + 30 " from post po join professor pr on po.professor_id = pr.id\n" + 31 " where professor_id is not null\n" + 32 " group by pr.faculty_id) as t3\n" + 33 " natural join\n" + 34 " (select sp.faculty_id as facultyid, count(*) as count2\n" + 35 " from post po join subject s on po.subject_id = s.id join study_programme sp on s.study_programme_id = sp.id\n" + 36 " where po.subject_id is not null\n" + 37 " group by sp.faculty_id) as t4) as q2;", nativeQuery = true) 38 List<String> findSectionAndPostCount(); 19 39 } -
springapp/src/main/java/mk/profesori/springapp/Repository/UserRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 2 3 import java.util.Optional; 4 3 import mk.profesori.springapp.Model.CustomUserDetails; 5 4 import org.springframework.data.jpa.repository.JpaRepository; 6 5 import org.springframework.data.jpa.repository.Modifying; … … 9 8 import org.springframework.transaction.annotation.Transactional; 10 9 11 import mk.profesori.springapp.Model.CustomUserDetails;10 import java.util.Optional; 12 11 13 12 @Repository … … 16 15 Optional<CustomUserDetails> findByEmail(String email); 17 16 Optional<CustomUserDetails> findByUsername(String username); 17 Optional<CustomUserDetails> findById(Long id); 18 18 19 19 @Transactional -
springapp/src/main/java/mk/profesori/springapp/Repository/_ThreadRepository.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Repository; 2 2 3 import mk.profesori.springapp.Model.Subject; 3 4 import mk.profesori.springapp.Model._Thread; 4 5 import org.springframework.data.repository.CrudRepository; 5 6 import org.springframework.stereotype.Repository; 6 7 8 import java.util.List; 9 7 10 @Repository 8 11 public interface _ThreadRepository extends CrudRepository<_Thread,Long> { 9 12 _Thread findByPostId(Long postId); 13 List<_Thread> findTop10ByOrderByTimePosted(); 14 List<_Thread> findByTargetSubject(Subject s); 10 15 } -
springapp/src/main/java/mk/profesori/springapp/Security/SecurityConfiguration.java
r4abf55a r9bf1f8d 37 37 @Override 38 38 public void addCorsMappings(CorsRegistry registry) { 39 registry.addMapping("/**").allowedOrigins("http://192.168. 0.29:3000", "http://192.168.0.28:3000")39 registry.addMapping("/**").allowedOrigins("http://192.168.1.254:3000", "http://192.168.0.28:3000") 40 40 .allowCredentials(true); 41 41 } -
springapp/src/main/java/mk/profesori/springapp/Service/CustomUserDetailsService.java
r4abf55a r9bf1f8d 1 1 package mk.profesori.springapp.Service; 2 2 3 import java.time.LocalDateTime; 4 import java.util.UUID; 5 3 import lombok.AllArgsConstructor; 4 import mk.profesori.springapp.Model.ConfirmationToken; 5 import mk.profesori.springapp.Model.CustomUserDetails; 6 import mk.profesori.springapp.Repository.UserRepository; 6 7 import org.springframework.beans.factory.annotation.Autowired; 7 8 import org.springframework.security.core.userdetails.UserDetails; … … 12 13 import org.springframework.stereotype.Service; 13 14 14 import lombok.AllArgsConstructor; 15 import mk.profesori.springapp.Model.ConfirmationToken; 16 import mk.profesori.springapp.Model.CustomUserDetails; 17 import mk.profesori.springapp.Repository.UserRepository; 15 import java.time.LocalDateTime; 16 import java.util.UUID; 18 17 19 18 @Service -
springapp/src/main/java/mk/profesori/springapp/Service/Exception/DisallowedOperationException.java
r4abf55a r9bf1f8d 1 package mk.profesori.springapp.Service ;1 package mk.profesori.springapp.Service.Exception; 2 2 3 3 public class DisallowedOperationException extends RuntimeException{ -
springapp/src/main/java/mk/profesori/springapp/Service/Exception/IncompatiblePostId.java
r4abf55a r9bf1f8d 1 package mk.profesori.springapp.Service ;1 package mk.profesori.springapp.Service.Exception; 2 2 3 3 public class IncompatiblePostId extends RuntimeException{ -
springapp/src/main/java/mk/profesori/springapp/Service/MainService.java
r4abf55a r9bf1f8d 3 3 import mk.profesori.springapp.Model.*; 4 4 import mk.profesori.springapp.Repository.*; 5 import mk.profesori.springapp.Service.Exception.DisallowedOperationException; 6 import mk.profesori.springapp.Service.Exception.IncompatiblePostId; 5 7 import org.springframework.security.core.userdetails.UsernameNotFoundException; 6 8 import org.springframework.stereotype.Service; … … 9 11 import java.util.ArrayList; 10 12 import java.util.List; 13 import java.util.Set; 11 14 12 15 @Service … … 24 27 private final UserRepository userRepository; 25 28 private final PostReportRepository postReportRepository; 26 27 public MainService(ProfessorRepository professorRepository, StudyProgrammeRepository studyProgrammeRepository, FacultyRepository facultyRepository, UniversityRepository universityRepository, CityRepository cityRepository, OpinionRepository opinionRepository, _ThreadRepository _threadRepository, SubjectRepository subjectRepository, PostVoteRepository postVoteRepository, UserRepository userRepository, PostReportRepository postReportRepository) { 29 private final PostRepository postRepository; 30 31 public MainService(ProfessorRepository professorRepository, StudyProgrammeRepository studyProgrammeRepository, FacultyRepository facultyRepository, UniversityRepository universityRepository, CityRepository cityRepository, OpinionRepository opinionRepository, _ThreadRepository _threadRepository, SubjectRepository subjectRepository, PostVoteRepository postVoteRepository, UserRepository userRepository, PostReportRepository postReportRepository, PostRepository postRepository) { 28 32 this.professorRepository = professorRepository; 29 33 this.studyProgrammeRepository = studyProgrammeRepository; … … 37 41 this.userRepository = userRepository; 38 42 this.postReportRepository = postReportRepository; 43 this.postRepository = postRepository; 39 44 } 40 45 … … 58 63 public List<Professor> getProfessorsByNameContains(String contained) { 59 64 return new ArrayList<>(professorRepository.findByProfessorNameContainingIgnoreCase(contained)); 65 } 66 67 public List<Subject> getSubjectsByNameContains(String contained) { 68 return new ArrayList<>(subjectRepository.findBySubjectNameContainingIgnoreCase(contained)); 60 69 } 61 70 … … 200 209 public void delete_Thread(Long postId) {_threadRepository.deleteById(postId);} 201 210 202 public StringupdateOpinion(String newContent, Long newTargetProfessorId, Long newParentPostId, Long postId) {211 public void updateOpinion(String newContent, Long newTargetProfessorId, Long newParentPostId, Long postId) { 203 212 Opinion opinionToUpdate = opinionRepository.findByPostId(postId); 204 213 … … 218 227 opinionToUpdate.setParent(newParentOpinion); 219 228 229 propagateNewTargetProfessorToChildren(opinionToUpdate, newTargetProfessor); 230 231 opinionToUpdate.setTimeLastEdited(LocalDateTime.now()); 232 opinionRepository.save(opinionToUpdate); 233 } 234 235 public void propagateNewTargetProfessorToChildren(Opinion opinionToUpdate, Professor newTargetProfessor) { 220 236 for(Post p : opinionToUpdate.getChildren()) { 237 // direct children 221 238 Opinion o = (Opinion) p; 222 239 o.setTargetProfessor(newTargetProfessor); 240 // ancestors 241 if(o.getChildren().isEmpty()) return; 242 propagateNewTargetProfessorToChildren(o, newTargetProfessor); 223 243 } 224 opinionToUpdate.setTimeLastEdited(LocalDateTime.now()); 225 opinionRepository.save(opinionToUpdate); 226 return null; 227 } 228 229 public String update_Thread(String newTitle, String newContent, Long newTargetSubjectId, Long newParentThreadId, Long postId) { 244 } 245 246 public void update_Thread(String newTitle, String newContent, Long newTargetSubjectId, Long newParentThreadId, Long postId) { 230 247 _Thread _threadToUpdate = _threadRepository.findByPostId(postId); 231 248 … … 251 268 } 252 269 253 for(Post p : _threadToUpdate.getChildren()) { 254 _Thread t = (_Thread) p; 255 t.setTargetSubject(newTargetSubject); 256 } 270 propagateNewTargetSubjectToChildren(_threadToUpdate, newTargetSubject); 271 257 272 _threadToUpdate.setTimeLastEdited(LocalDateTime.now()); 258 273 _threadRepository.save(_threadToUpdate); 259 return null; 274 } 275 276 public void propagateNewTargetSubjectToChildren(_Thread _threadToUpdate, Subject newTargetSubject) { 277 for(Post p : _threadToUpdate.getChildren()) { 278 // direct children 279 _Thread t = (_Thread) p; 280 t.setTargetSubject(newTargetSubject); 281 // ancestors 282 if (t.getChildren().isEmpty()) return; 283 propagateNewTargetSubjectToChildren(t, newTargetSubject); 284 } 260 285 } 261 286 … … 306 331 postReportRepository.save(reportToAdd); 307 332 } 333 334 public List<Opinion> getRelatedOpinions(Long professorId) { 335 Professor p = professorRepository.findByProfessorId(professorId); 336 return opinionRepository.findByTargetProfessor(p); 337 } 338 339 public List<Opinion> getLatest10Opinions() { 340 return opinionRepository.findTop10ByOrderByTimePosted(); 341 } 342 public List<_Thread> getLatest10Threads() { 343 return _threadRepository.findTop10ByOrderByTimePosted(); 344 } 345 346 public List<String> getUniversitySectionAndPostCount() { 347 return universityRepository.findSectionAndPostCount(); 348 } 349 350 public List<Subject> getSubjectsByStudyProgramme(Long studyProgrammeId) { 351 StudyProgramme sp = studyProgrammeRepository.findByStudyProgrammeId(studyProgrammeId); 352 return subjectRepository.findByStudyProgramme(sp); 353 } 354 355 public List<String> getOpinionCountForEachProfessorInFaculty(Long id) { 356 return facultyRepository.getOpinionCountForEachProfessorInFaculty(id); 357 } 358 359 public List<_Thread> getThreadsBySubject(Long id) { 360 Subject s = subjectRepository.findBySubjectId(id); 361 return _threadRepository.findByTargetSubject(s); 362 } 363 364 public List<String> getThreadCountForEachSubjectInStudyProgramme(Long id) { 365 return studyProgrammeRepository.getThreadCountForEachSubjectInStudyProgramme(id); 366 } 367 368 public Set<Post> getPostsByUser(String email) { 369 CustomUserDetails u = userRepository.findByEmail(email).orElseThrow( 370 () -> new UsernameNotFoundException(String.format("User with email %s not found", email))); 371 return postRepository.findByAuthor(u); 372 } 373 374 public CustomUserDetails getPublicUserProfile(Long id) { 375 return userRepository.findById(id).orElseThrow( 376 () -> new UsernameNotFoundException(String.format("User with id %d not found", id))); 377 } 308 378 } -
springapp/src/main/java/mk/profesori/springapp/Service/RegistrationService.java
r4abf55a r9bf1f8d 45 45 String tokenToResend = customUserDetailsService 46 46 .createToken(userRepository.findByEmail(request.getEmail()).get()); 47 String link = "http://192.168. 0.29:8080/registration/confirm?token=" + tokenToResend;47 String link = "http://192.168.1.254:8080/registration/confirm?token=" + tokenToResend; 48 48 emailSender.send(request.getEmail(), emailSender.buildEmail(request.getUsername(), link)); 49 49 return tokenToResend; … … 66 66 UserRole.REGULAR)); 67 67 68 String link = "http://192.168. 0.29:8080/registration/confirm?token=" + token;68 String link = "http://192.168.1.254:8080/registration/confirm?token=" + token; 69 69 70 70 emailSender.send(request.getEmail(), emailSender.buildEmail(request.getUsername(), link)); -
springapp/src/main/resources/application.properties
r4abf55a r9bf1f8d 6 6 spring.jpa.show-sql=false 7 7 spring.jpa.properties.hibernate.format_sql=true 8 server.address=192.168. 0.299 spring.mail.host= localhost8 server.address=192.168.1.254 9 spring.mail.host=192.168.1.254 10 10 spring.mail.username=mailuser 11 11 spring.mail.password=mailpass 12 12 spring.mail.port=1025 13 spring.jpa.open-in-view=false
Note:
See TracChangeset
for help on using the changeset viewer.