- Timestamp:
- 10/27/22 17:35:03 (2 years ago)
- Branches:
- main
- Children:
- 3b6962d
- Parents:
- 8d83180
- Location:
- springapp
- Files:
-
- 5 added
- 1 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
springapp/pom.xml
r8d83180 rc68150f 30 30 <artifactId>spring-boot-starter-web</artifactId> 31 31 </dependency> 32 33 32 <dependency> 34 33 <groupId>org.postgresql</groupId> … … 63 62 <scope>compile</scope> 64 63 </dependency> 64 65 65 </dependencies> 66 66 -
springapp/src/main/java/mk/profesori/springapp/Controller/PublicController.java
r8d83180 rc68150f 18 18 import mk.profesori.springapp.Model.Professor; 19 19 import mk.profesori.springapp.Model.StudyProgramme; 20 import mk.profesori.springapp.Model.Subject; 20 21 import mk.profesori.springapp.Model.University; 22 import mk.profesori.springapp.Model._Thread; 21 23 import mk.profesori.springapp.Service.MainService; 22 24 23 25 @RestController 24 26 @RequestMapping("/public") 25 @CrossOrigin(origins = { "http://192.168.0.17:3000", "http://192.168.0. 28:3000" })27 @CrossOrigin(origins = { "http://192.168.0.17:3000", "http://192.168.0.39:3000" }) 26 28 public class PublicController { 27 29 … … 98 100 } 99 101 102 @RequestMapping(value = "/subject/{subjectId}", method = RequestMethod.GET) 103 public Subject getSubjectById(@PathVariable Long subjectId) { 104 return mainService.getSubjectById(subjectId); // vrakja predmet spored id 105 } 106 107 @RequestMapping(value = "/thread/{postId}", method = RequestMethod.GET) 108 public _Thread getThreadById(@PathVariable Long postId) { 109 return mainService.get_ThreadById(postId); // vrakja thread (tema) spored id 110 } 111 100 112 @RequestMapping(value = "/loginSuccessRegular", method = RequestMethod.GET) 101 113 public Map<String, String> loginSuccessRegular(@RequestParam String sessionId) { -
springapp/src/main/java/mk/profesori/springapp/Controller/SecureController.java
r8d83180 rc68150f 1 1 package mk.profesori.springapp.Controller; 2 2 3 import java.util.Collections;4 import java.util.Map;5 6 import org.springframework.beans.factory.annotation.Autowired;3 import com.fasterxml.jackson.databind.node.ObjectNode; 4 import mk.profesori.springapp.Model.CustomUserDetails; 5 import mk.profesori.springapp.Service.CustomUserDetailsService; 6 import mk.profesori.springapp.Service.MainService; 7 7 import org.springframework.security.core.Authentication; 8 8 import org.springframework.security.core.annotation.CurrentSecurityContext; 9 9 import org.springframework.security.core.context.SecurityContext; 10 10 import org.springframework.security.core.userdetails.UserDetails; 11 import org.springframework.web.bind.annotation.CrossOrigin; 12 import org.springframework.web.bind.annotation.PathVariable; 13 import org.springframework.web.bind.annotation.RequestBody; 14 import org.springframework.web.bind.annotation.RequestMapping; 15 import org.springframework.web.bind.annotation.RequestMethod; 16 import org.springframework.web.bind.annotation.RequestParam; 17 import org.springframework.web.bind.annotation.RestController; 18 19 import com.fasterxml.jackson.databind.node.ObjectNode; 20 21 import mk.profesori.springapp.Model.CustomUserDetails; 22 import mk.profesori.springapp.Service.CustomUserDetailsService; 23 import mk.profesori.springapp.Service.MainService; 11 import org.springframework.web.bind.annotation.*; 24 12 25 13 @RestController 26 14 @RequestMapping("/secure") 27 @CrossOrigin(origins = { "http://192.168.0.17:3000", "http://192.168.0. 28:3000" })15 @CrossOrigin(origins = { "http://192.168.0.17:3000", "http://192.168.0.39:3000" }) 28 16 public class SecureController { 29 17 30 @Autowired 31 private MainService mainService; 32 @Autowired 18 private final MainService mainService; 19 final 33 20 CustomUserDetailsService customUserDetailsService; 21 22 public SecureController(MainService mainService, CustomUserDetailsService customUserDetailsService) { 23 this.mainService = mainService; 24 this.customUserDetailsService = customUserDetailsService; 25 } 34 26 35 27 @RequestMapping(value = "/professor/{professorId}/addOpinion", method = RequestMethod.POST) … … 39 31 Authentication authentication = context.getAuthentication(); 40 32 41 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) { 42 CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal(); 43 String title = objectNode.get("title").asText(); 33 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 44 34 String content = objectNode.get("content").asText(); 45 mainService.addOpinion( title,content, professorId, currentUser);35 mainService.addOpinion(content, professorId, currentUser); 46 36 } 47 37 } … … 53 43 Authentication authentication = context.getAuthentication(); 54 44 55 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) { 56 CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal(); 45 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 57 46 String content = objectNode.get("content").asText(); 58 47 mainService.replyToOpinion(content, professorId, postId, currentUser); 48 } 49 } 50 51 @RequestMapping(value = "/subject/{subjectId}/addThread", method = RequestMethod.POST) 52 public void addThread(@RequestBody ObjectNode objectNode, @PathVariable Long subjectId, 53 @CurrentSecurityContext SecurityContext context) { 54 55 Authentication authentication = context.getAuthentication(); 56 57 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 58 String title = objectNode.get("title").asText(); 59 String content = objectNode.get("content").asText(); 60 mainService.addThread(title, content, subjectId, currentUser); 61 } 62 } 63 64 @RequestMapping(value = "/subject/{subjectId}/replyToThread/{postId}", method = RequestMethod.POST) 65 public void replyToThread(@RequestBody ObjectNode objectNode, @PathVariable Long subjectId, 66 @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 67 68 Authentication authentication = context.getAuthentication(); 69 70 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 71 String content = objectNode.get("content").asText(); 72 mainService.replyToThread(content, subjectId, postId, currentUser); 59 73 } 60 74 } … … 64 78 65 79 Authentication authentication = context.getAuthentication(); 66 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) { 67 CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal(); 80 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 68 81 return customUserDetailsService.loadUserByUsername(currentUser.getEmail()); 69 82 } … … 72 85 } 73 86 74 @RequestMapping(value = "/professor/{professorId}/upvoteOpinion/{postId}", method = RequestMethod.GET) 75 public void upvoteOpinion(@PathVariable Long professorId, 76 @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 87 @RequestMapping(value = "/upvoteOpinion/{postId}", method = RequestMethod.GET) 88 public void upvoteOpinion(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 77 89 78 90 Authentication authentication = context.getAuthentication(); 79 91 80 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) { 81 CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal(); 92 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 82 93 mainService.upvoteOpinion(postId, currentUser); 83 94 } 84 95 } 85 96 86 @RequestMapping(value = "/professor/{professorId}/downvoteOpinion/{postId}", method = RequestMethod.GET) 87 public void downvoteOpinion(@PathVariable Long professorId, 88 @PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 97 @RequestMapping(value = "/downvoteOpinion/{postId}", method = RequestMethod.GET) 98 public void downvoteOpinion(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 89 99 90 100 Authentication authentication = context.getAuthentication(); 91 101 92 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails) { 93 CustomUserDetails currentUser = (CustomUserDetails) authentication.getPrincipal(); 102 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 94 103 mainService.downvoteOpinion(postId, currentUser); 95 104 } 96 105 } 97 106 107 @RequestMapping(value = "/upvoteThread/{postId}", method = RequestMethod.GET) 108 public void upvoteThread(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 109 110 Authentication authentication = context.getAuthentication(); 111 112 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 113 mainService.upvote_Thread(postId, currentUser); 114 } 115 } 116 117 @RequestMapping(value = "/downvoteThread/{postId}", method = RequestMethod.GET) 118 public void downvoteThread(@PathVariable Long postId, @CurrentSecurityContext SecurityContext context) { 119 120 Authentication authentication = context.getAuthentication(); 121 122 if (authentication != null && authentication.getPrincipal() instanceof CustomUserDetails currentUser) { 123 mainService.downvote_Thread(postId, currentUser); 124 } 125 } 126 98 127 } -
springapp/src/main/java/mk/profesori/springapp/Model/ConfirmationToken.java
r8d83180 rc68150f 12 12 import javax.persistence.SequenceGenerator; 13 13 14 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 15 import com.voodoodyne.jackson.jsog.JSOGGenerator; 16 14 17 import lombok.Getter; 15 18 import lombok.NoArgsConstructor; … … 20 23 @NoArgsConstructor 21 24 @Entity 25 @JsonIdentityInfo(generator = JSOGGenerator.class) 22 26 public class ConfirmationToken { 23 27 24 28 @Id 25 29 @SequenceGenerator(name = "confirmation_token_sequence", sequenceName = "confirmation_token_sequence", allocationSize = 1) … … 42 46 private CustomUserDetails customUserDetails; 43 47 44 public ConfirmationToken(String token, LocalDateTime createdAt, LocalDateTime expiredAt, 45 CustomUserDetails customUserDetails) {46 48 public ConfirmationToken(String token, LocalDateTime createdAt, LocalDateTime expiredAt, 49 CustomUserDetails customUserDetails) { 50 47 51 this.token = token; 48 52 this.createdAt = createdAt; -
springapp/src/main/java/mk/profesori/springapp/Model/CustomUserDetails.java
r8d83180 rc68150f 1 1 package mk.profesori.springapp.Model; 2 2 3 import java.util.ArrayList; 4 import java.util.Collection; 5 import java.util.Collections; 6 import java.util.HashSet; 7 import java.util.List; 8 import java.util.Set; 9 10 import javax.persistence.CascadeType; 11 import javax.persistence.Entity; 12 import javax.persistence.EnumType; 13 import javax.persistence.Enumerated; 14 import javax.persistence.FetchType; 15 import javax.persistence.GeneratedValue; 16 import javax.persistence.GenerationType; 17 import javax.persistence.Id; 18 import javax.persistence.JoinTable; 19 import javax.persistence.JoinColumn; 20 import javax.persistence.ManyToMany; 21 import javax.persistence.OneToMany; 22 import javax.persistence.SequenceGenerator; 23 3 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 import com.voodoodyne.jackson.jsog.JSOGGenerator; 5 import lombok.EqualsAndHashCode; 6 import lombok.Getter; 7 import lombok.NoArgsConstructor; 8 import lombok.Setter; 24 9 import org.springframework.security.core.GrantedAuthority; 25 10 import org.springframework.security.core.authority.SimpleGrantedAuthority; 26 11 import org.springframework.security.core.userdetails.UserDetails; 27 12 28 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 29 import com.voodoodyne.jackson.jsog.JSOGGenerator; 30 31 import lombok.EqualsAndHashCode; 32 import lombok.Getter; 33 import lombok.NoArgsConstructor; 34 import lombok.Setter; 13 import javax.persistence.*; 14 import java.util.Collection; 15 import java.util.Collections; 16 import java.util.HashSet; 17 import java.util.Set; 35 18 36 19 @Getter … … 59 42 private Set<Post> authoredPosts = new HashSet<>(); 60 43 private Integer karma = 0; 61 @ManyToMany(fetch = FetchType.EAGER) 62 @JoinTable(name = "post_like", joinColumns = @JoinColumn(name = "custom_user_details_id"), inverseJoinColumns = @JoinColumn(name = "post_id")) 63 Set<Post> likedPosts; 64 @ManyToMany(fetch = FetchType.EAGER) 65 @JoinTable(name = "post_dislike", joinColumns = @JoinColumn(name = "custom_user_details_id"), inverseJoinColumns = @JoinColumn(name = "post_id")) 66 Set<Post> dislikedPosts; 44 45 public Set<PostVote> getVotes() { 46 return votes; 47 } 48 49 public void setVotes(Set<PostVote> votes) { 50 this.votes = votes; 51 } 52 53 @OneToMany(mappedBy = "user") 54 private Set<PostVote> votes = new HashSet<>(); 67 55 68 56 public CustomUserDetails(String fullName, String username, String email, String password, UserRole userRole) { … … 122 110 } 123 111 124 public Set<Post> getLikedPosts() { 125 return this.likedPosts; 112 @Override 113 public String toString() { 114 return this.id.toString(); 126 115 } 127 116 128 public void setLikedPosts(Set<Post> likedPosts) {129 this.likedPosts = likedPosts;130 }131 132 public Set<Post> getDislikedPosts() {133 return this.dislikedPosts;134 }135 136 public void setDislikedPosts(Set<Post> dislikedPosts) {137 this.likedPosts = dislikedPosts;138 }139 117 } -
springapp/src/main/java/mk/profesori/springapp/Model/Post.java
r8d83180 rc68150f 3 3 import java.time.LocalDateTime; 4 4 import java.util.ArrayList; 5 import java.util.HashSet; 5 6 import java.util.List; 6 7 import java.util.Set; … … 55 56 56 57 @ManyToOne 57 @JoinColumn(name = "parent_post_id" , nullable = true)58 @JoinColumn(name = "parent_post_id") 58 59 private Post parent; 60 61 @OneToMany(mappedBy = "post") 62 private Set<PostVote> votes = new HashSet<>(); 63 64 public Set<PostVote> getVotes() { 65 return votes; 66 } 67 68 public void setVotes(Set<PostVote> votes) { 69 this.votes = votes; 70 } 59 71 60 72 @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL) 61 73 private List<Post> children = new ArrayList<>(); 62 63 @ManyToMany(mappedBy = "likedPosts")64 Set<CustomUserDetails> likes;65 66 @ManyToMany(mappedBy = "dislikedPosts")67 Set<CustomUserDetails> dislikes;68 74 69 75 // getters and setters … … 132 138 } 133 139 134 public Set<CustomUserDetails> getLikes() {135 return likes;136 }137 138 public void setLikes(Set<CustomUserDetails> likes) {139 this.likes = likes;140 }141 142 public Set<CustomUserDetails> getDislikes() {143 return dislikes;144 }145 146 public void setDislikes(Set<CustomUserDetails> dislikes) {147 this.dislikes = dislikes;148 }149 150 140 // konstruktor so parent (koga e reply) 151 141 public Post(String title, String content, CustomUserDetails author, LocalDateTime timePosted, … … 174 164 } 175 165 166 @Override 167 public String toString() { 168 return this.postId.toString(); 169 } 170 176 171 } -
springapp/src/main/java/mk/profesori/springapp/Model/StudyProgramme.java
r8d83180 rc68150f 12 12 import javax.persistence.ManyToOne; 13 13 import javax.persistence.OneToMany; 14 import javax.persistence.OneToOne;15 14 import javax.persistence.Table; 16 15 … … 41 40 private Set<Subject> subjects = new HashSet<>(); 42 41 43 @OneToOne(mappedBy = "relatedStudyProgramme")44 private Section relatedSection;45 46 42 // getters 47 43 public Long getStudyProgrammeId() { … … 65 61 } 66 62 67 public Section getRelatedSection() {68 return relatedSection;69 }70 63 } -
springapp/src/main/java/mk/profesori/springapp/Model/Subject.java
r8d83180 rc68150f 15 15 16 16 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 17 import com. fasterxml.jackson.annotation.ObjectIdGenerators;17 import com.voodoodyne.jackson.jsog.JSOGGenerator; 18 18 19 19 @Entity 20 20 @Table(name = "subject") 21 @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "subjectId")21 @JsonIdentityInfo(generator = JSOGGenerator.class) 22 22 public class Subject { 23 23 -
springapp/src/main/java/mk/profesori/springapp/Model/University.java
r8d83180 rc68150f 15 15 16 16 import com.fasterxml.jackson.annotation.JsonIdentityInfo; 17 import com. fasterxml.jackson.annotation.ObjectIdGenerators;17 import com.voodoodyne.jackson.jsog.JSOGGenerator; 18 18 19 19 @Entity 20 20 @Table(name = "university") 21 @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "universityId")21 @JsonIdentityInfo(generator = JSOGGenerator.class) 22 22 public class University { 23 23 -
springapp/src/main/java/mk/profesori/springapp/Model/_Thread.java
r8d83180 rc68150f 2 2 3 3 import java.time.LocalDateTime; 4 import java.util.ArrayList; 4 5 5 import java.util.List; 6 6 7 import javax.persistence.Column;8 7 import javax.persistence.DiscriminatorValue; 9 import javax.persistence.ElementCollection; 8 10 9 import javax.persistence.Entity; 11 10 import javax.persistence.JoinColumn; 12 11 import javax.persistence.ManyToOne; 13 12 13 import lombok.NoArgsConstructor; 14 14 15 @Entity 15 16 @DiscriminatorValue("thread") 17 @NoArgsConstructor 16 18 public class _Thread extends Post { 17 18 @Column(name = "tags") // unused19 @ElementCollection20 private List<String> tags = new ArrayList<>();21 22 @ManyToOne23 @JoinColumn(name = "section_id")24 private Section parentSection;25 19 26 20 @ManyToOne … … 31 25 public _Thread(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 32 26 LocalDateTime timeLastEdited, 33 Post parent, List<Post> children, S ection parentSection, Subject targetSubject) {27 Post parent, List<Post> children, Subject targetSubject) { 34 28 super(title, content, author, timePosted, timeLastEdited, parent, children); 35 this.parentSection = parentSection;36 29 this.targetSubject = targetSubject; 37 30 } … … 39 32 // konstruktor bez parent (koga NE e reply) 40 33 public _Thread(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 41 LocalDateTime timeLastEdited, List<Post> children, S ection parentSection, Subject targetSubject) {34 LocalDateTime timeLastEdited, List<Post> children, Subject targetSubject) { 42 35 super(title, content, author, timePosted, timeLastEdited, children); 43 this.parentSection = parentSection;44 36 this.targetSubject = targetSubject; 45 }46 47 // getters48 public List<String> getTags() {49 return tags;50 }51 52 public Section getParentSection() {53 return parentSection;54 37 } 55 38 -
springapp/src/main/java/mk/profesori/springapp/Repository/OpinionRepository.java
r8d83180 rc68150f 1 1 package mk.profesori.springapp.Repository; 2 2 3 import mk.profesori.springapp.Model.Opinion; 3 4 import org.springframework.data.repository.CrudRepository; 4 5 import org.springframework.stereotype.Repository; 5 6 6 import mk.profesori.springapp.Model.Opinion;7 8 7 @Repository 9 public interface OpinionRepository extends CrudRepository<Opinion, 10 public Opinion findByPostId(Long id);8 public interface OpinionRepository extends CrudRepository<Opinion,Long> { 9 Opinion findByPostId(Long postId); 11 10 } -
springapp/src/main/java/mk/profesori/springapp/Security/SecurityConfiguration.java
r8d83180 rc68150f 37 37 @Override 38 38 public void addCorsMappings(CorsRegistry registry) { 39 registry.addMapping("/**").allowedOrigins("http://192.168.0.17:3000", "http://192.168.0. 28:3000")39 registry.addMapping("/**").allowedOrigins("http://192.168.0.17:3000", "http://192.168.0.39:3000") 40 40 .allowCredentials(true); 41 41 } -
springapp/src/main/java/mk/profesori/springapp/Service/EmailValidator.java
r8d83180 rc68150f 13 13 public boolean test(String email) { 14 14 15 String regex = "^(.+)@(.+)$"; 15 String regex = "^(.+)@(.+)$"; //TODO bilosto@@ ->> illegal address exception od mailsender 16 16 17 17 Pattern pattern = Pattern.compile(regex); -
springapp/src/main/java/mk/profesori/springapp/Service/MainService.java
r8d83180 rc68150f 1 1 package mk.profesori.springapp.Service; 2 3 import mk.profesori.springapp.Model.*; 4 import mk.profesori.springapp.Repository.*; 5 import org.springframework.stereotype.Service; 2 6 3 7 import java.util.ArrayList; 4 8 import java.util.List; 5 9 6 import org.springframework.beans.factory.annotation.Autowired;7 import org.springframework.stereotype.Service;8 9 import mk.profesori.springapp.Repository.CityRepository;10 import mk.profesori.springapp.Repository.FacultyRepository;11 import mk.profesori.springapp.Repository.OpinionRepository;12 import mk.profesori.springapp.Repository.ProfessorRepository;13 import mk.profesori.springapp.Repository.StudyProgrammeRepository;14 import mk.profesori.springapp.Repository.UniversityRepository;15 import mk.profesori.springapp.Repository.UserRepository;16 import mk.profesori.springapp.Model.City;17 import mk.profesori.springapp.Model.CustomUserDetails;18 import mk.profesori.springapp.Model.Faculty;19 import mk.profesori.springapp.Model.Opinion;20 import mk.profesori.springapp.Model.Professor;21 import mk.profesori.springapp.Model.StudyProgramme;22 import mk.profesori.springapp.Model.University;23 24 10 @Service 25 11 public class MainService { 26 12 27 @Autowired 28 private ProfessorRepository professorRepository; 29 @Autowired 30 private StudyProgrammeRepository studyProgrammeRepository; 31 @Autowired 32 private FacultyRepository facultyRepository; 33 @Autowired 34 private UniversityRepository universityRepository; 35 @Autowired 36 private CityRepository cityRepository; 37 @Autowired 38 private OpinionRepository opinionRepository; 39 @Autowired 40 private UserRepository userRepository; 13 private final ProfessorRepository professorRepository; 14 private final StudyProgrammeRepository studyProgrammeRepository; 15 private final FacultyRepository facultyRepository; 16 private final UniversityRepository universityRepository; 17 private final CityRepository cityRepository; 18 private final OpinionRepository opinionRepository; 19 private final _ThreadRepository _threadRepository; 20 private final SubjectRepository subjectRepository; 21 private final PostVoteRepository postVoteRepository; 22 private final UserRepository userRepository; 23 24 public MainService(ProfessorRepository professorRepository, StudyProgrammeRepository studyProgrammeRepository, FacultyRepository facultyRepository, UniversityRepository universityRepository, CityRepository cityRepository, OpinionRepository opinionRepository, _ThreadRepository _threadRepository, SubjectRepository subjectRepository, PostVoteRepository postVoteRepository, UserRepository userRepository) { 25 this.professorRepository = professorRepository; 26 this.studyProgrammeRepository = studyProgrammeRepository; 27 this.facultyRepository = facultyRepository; 28 this.universityRepository = universityRepository; 29 this.cityRepository = cityRepository; 30 this.opinionRepository = opinionRepository; 31 this._threadRepository = _threadRepository; 32 this.subjectRepository = subjectRepository; 33 this.postVoteRepository = postVoteRepository; 34 this.userRepository = userRepository; 35 } 41 36 42 37 public List<Professor> getAllProfessors() { 43 38 44 List<Professor> list = new ArrayList<>(); 45 professorRepository.findAll().forEach(list::add); 46 return list; 39 return new ArrayList<>(professorRepository.findAll()); 47 40 } 48 41 … … 56 49 Faculty faculty = facultyRepository.findByFacultyId(facultyId); 57 50 58 List<Professor> list = new ArrayList<>(); 59 professorRepository.findByFaculty(faculty).forEach(list::add); 60 return list; 51 return new ArrayList<>(professorRepository.findByFaculty(faculty)); 61 52 } 62 53 63 54 public List<Professor> getProfessorsByNameContains(String contained) { 64 List<Professor> list = new ArrayList<>(); 65 professorRepository.findByProfessorNameContainingIgnoreCase(contained).forEach(list::add); 66 return list; 55 return new ArrayList<>(professorRepository.findByProfessorNameContainingIgnoreCase(contained)); 67 56 } 68 57 69 58 public List<StudyProgramme> getAllStudyProgrammes() { 70 59 71 List<StudyProgramme> list = new ArrayList<>(); 72 studyProgrammeRepository.findAll().forEach(list::add); 73 return list; 60 return new ArrayList<>(studyProgrammeRepository.findAll()); 74 61 } 75 62 … … 83 70 Faculty faculty = facultyRepository.findByFacultyId(facultyId); 84 71 85 List<StudyProgramme> list = new ArrayList<>(); 86 studyProgrammeRepository.findByFaculty(faculty).forEach(list::add); 87 return list; 72 return new ArrayList<>(studyProgrammeRepository.findByFaculty(faculty)); 88 73 } 89 74 90 75 public List<Faculty> getAllFaculties() { 91 List<Faculty> list = new ArrayList<>(); 92 facultyRepository.findAll().forEach(list::add); 93 return list; 76 return new ArrayList<>(facultyRepository.findAll()); 94 77 } 95 78 … … 102 85 University university = universityRepository.findByUniversityId(universityId); 103 86 104 List<Faculty> list = new ArrayList<>(); 105 facultyRepository.findByUniversity(university).forEach(list::add); 106 return list; 87 return new ArrayList<>(facultyRepository.findByUniversity(university)); 107 88 } 108 89 109 90 public List<University> getAllUniversities() { 110 List<University> list = new ArrayList<>(); 111 universityRepository.findAll().forEach(list::add); 112 return list; 91 return new ArrayList<>(universityRepository.findAll()); 113 92 } 114 93 … … 121 100 City city = cityRepository.findByCityId(cityId); 122 101 123 List<University> list = new ArrayList<>(); 124 universityRepository.findByCity(city).forEach(list::add); 125 return list; 102 return new ArrayList<>(universityRepository.findByCity(city)); 126 103 } 127 104 128 105 public List<City> getAllCities() { 129 List<City> list = new ArrayList<>(); 130 cityRepository.findAll().forEach(list::add); 131 return list; 106 return new ArrayList<>(cityRepository.findAll()); 132 107 } 133 108 … … 136 111 } 137 112 138 public void addOpinion(String title, Stringcontent, Long professorId, CustomUserDetails currentUser) {113 public void addOpinion(String content, Long professorId, CustomUserDetails currentUser) { 139 114 140 115 Professor targetProfessor = professorRepository.findByProfessorId(professorId); 141 116 142 Opinion opinionToAdd = new Opinion( title, content, currentUser, null, null,117 Opinion opinionToAdd = new Opinion(null, content, currentUser, null, null, 143 118 null, targetProfessor); 144 119 … … 155 130 opinionRepository.save(opinionToAdd); 156 131 132 //mozda ne treba 157 133 targetOpinion.getChildren().add(opinionToAdd); 158 134 opinionRepository.save(targetOpinion); 159 135 } 160 136 161 public void upvoteOpinion(Long postId, CustomUserDetails currentUser) {162 Opinion targetOpinion = opinionRepository.findByPostId(postId);137 public void addThread(String title, String content, Long subjectId, CustomUserDetails currentUser) { 138 Subject targetSubject = subjectRepository.findBySubjectId(subjectId); 163 139 164 if (!targetOpinion.getLikes().contains(currentUser)) { 165 166 targetOpinion.getLikes().add(currentUser); 167 // opinionRepository.save(targetOpinion); 168 169 targetOpinion.getAuthor().setKarma(targetOpinion.getAuthor().getKarma() + 1); 170 userRepository.save(targetOpinion.getAuthor()); 171 172 currentUser.getLikedPosts().add(targetOpinion); 173 userRepository.save(currentUser); 174 } 140 _Thread _threadToAdd = new _Thread(title, content, currentUser, null, null, null, targetSubject); 141 _threadRepository.save(_threadToAdd); 175 142 } 176 143 144 public void replyToThread(String content, Long subjectId, Long postId, CustomUserDetails currentUser) { 145 Subject targetSubject = subjectRepository.findBySubjectId(subjectId); 146 _Thread target_Thread = _threadRepository.findByPostId(postId); 147 148 _Thread _threadToAdd = new _Thread(null, content, currentUser, null, null, target_Thread, null, targetSubject); 149 _threadRepository.save(_threadToAdd); 150 151 //mozda ne treba 152 target_Thread.getChildren().add(_threadToAdd); 153 _threadRepository.save(target_Thread); 154 } 155 156 public Subject getSubjectById(Long subjectId) { 157 return subjectRepository.findBySubjectId(subjectId); 158 } 159 160 public _Thread get_ThreadById(Long postId) { 161 return _threadRepository.findByPostId(postId); 162 } 163 164 public void upvoteOpinion(Long postId, CustomUserDetails currentUser) { 165 Post targetPost = opinionRepository.findByPostId(postId); 166 PostVote voteToAdd = new PostVote(currentUser, targetPost, VoteType.UPVOTE); 167 postVoteRepository.save(voteToAdd); 168 targetPost.getAuthor().setKarma(targetPost.getAuthor().getKarma()+1); 169 userRepository.save(targetPost.getAuthor()); 170 } 177 171 public void downvoteOpinion(Long postId, CustomUserDetails currentUser) { 178 Opinion targetOpinion = opinionRepository.findByPostId(postId); 172 Post targetPost = opinionRepository.findByPostId(postId); 173 PostVote voteToAdd = new PostVote(currentUser, targetPost, VoteType.DOWNVOTE); 174 postVoteRepository.save(voteToAdd); 175 targetPost.getAuthor().setKarma(targetPost.getAuthor().getKarma()-1); 176 userRepository.save(targetPost.getAuthor()); 177 } 179 178 180 if (!targetOpinion.getDislikes().contains(currentUser)) { 179 public void upvote_Thread(Long postId, CustomUserDetails currentUser) { 180 Post targetPost = _threadRepository.findByPostId(postId); 181 PostVote voteToAdd = new PostVote(currentUser, targetPost, VoteType.UPVOTE); 182 postVoteRepository.save(voteToAdd); 183 targetPost.getAuthor().setKarma(targetPost.getAuthor().getKarma()+1); 184 userRepository.save(targetPost.getAuthor()); 181 185 182 targetOpinion.getDislikes().add(currentUser); 183 // opinionRepository.save(targetOpinion); 184 185 targetOpinion.getAuthor().setKarma(targetOpinion.getAuthor().getKarma() - 1); 186 userRepository.save(targetOpinion.getAuthor()); 187 188 currentUser.getDislikedPosts().add(targetOpinion); 189 userRepository.save(currentUser); 190 } 186 } 187 public void downvote_Thread(Long postId, CustomUserDetails currentUser) { 188 Post targetPost = _threadRepository.findByPostId(postId); 189 PostVote voteToAdd = new PostVote(currentUser, targetPost, VoteType.DOWNVOTE); 190 postVoteRepository.save(voteToAdd); 191 targetPost.getAuthor().setKarma(targetPost.getAuthor().getKarma()-1); 192 userRepository.save(targetPost.getAuthor()); 191 193 } 192 194 } -
springapp/src/main/resources/application.properties
r8d83180 rc68150f 4 4 spring.datasource.password=1win7337 5 5 spring.jpa.hibernate.ddl-auto=update 6 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect 6 7 spring.jpa.show-sql=false 7 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect8 8 spring.jpa.properties.hibernate.format_sql=true 9 9 server.address=192.168.0.17 10 spring.mail.host=192.168.0. 2810 spring.mail.host=192.168.0.39 11 11 spring.mail.username=mailuser 12 12 spring.mail.password=mailpass
Note:
See TracChangeset
for help on using the changeset viewer.