Changeset 4a64cf0 for springapp/src
- Timestamp:
- 07/29/22 21:31:30 (2 years ago)
- Branches:
- main
- Children:
- 3a44163
- Parents:
- 7cb8c3c
- Location:
- springapp/src/main/java/mk/profesori/springapp
- Files:
-
- 2 added
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
springapp/src/main/java/mk/profesori/springapp/Controller/PublicController.java
r7cb8c3c r4a64cf0 20 20 21 21 @RestController 22 @CrossOrigin(origins = "http://192.168.0.17:3000") 23 public class MainController { 24 22 @RequestMapping("/public") 23 @CrossOrigin(origins = { "http://192.168.0.17:3000", "http://192.168.0.24:3000" }) 24 public class PublicController { 25 25 26 @Autowired 26 27 private MainService mainService; … … 29 30 public List<Professor> getProfessorsByFaculty(@RequestParam Optional<Long> facultyId) { 30 31 31 if(!facultyId.isPresent()) return mainService.getAllProfessors(); //ako nema parametar facultyId gi vrakja site profesori 32 if (!facultyId.isPresent()) 33 return mainService.getAllProfessors(); // ako nema parametar facultyId gi vrakja site profesori 32 34 return mainService.getProfessorsByFacultyId(facultyId.get()); 33 35 } … … 35 37 @RequestMapping(value = "/professor/{professorId}", method = RequestMethod.GET) 36 38 public Professor getProfessorById(@PathVariable Long professorId) { 37 return mainService.getProfessorById(professorId); //vrakja profesor spored id39 return mainService.getProfessorById(professorId); // vrakja profesor spored id 38 40 } 39 41 … … 41 43 public List<StudyProgramme> getStudyProgrammesByFaculty(@RequestParam Optional<Long> facultyId) { 42 44 43 if(!facultyId.isPresent()) return mainService.getAllStudyProgrammes(); //ako nema parametar facultyId gi vrakja site studiski programi 45 if (!facultyId.isPresent()) 46 return mainService.getAllStudyProgrammes(); // ako nema parametar facultyId gi vrakja site studiski programi 44 47 return mainService.getStudyProgrammesByFacultyId(facultyId.get()); 45 48 } … … 47 50 @RequestMapping(value = "/study_programme/{studyProgrammeId}", method = RequestMethod.GET) 48 51 public StudyProgramme getStudyProgrammeById(@PathVariable Long studyProgrammeId) { 49 return mainService.getStudyProgrammeById(studyProgrammeId); //vrakja studiska programa spored id52 return mainService.getStudyProgrammeById(studyProgrammeId); // vrakja studiska programa spored id 50 53 } 51 54 … … 53 56 public List<Faculty> getFacultiesByUniversity(@RequestParam Optional<Long> universityId) { 54 57 55 if(!universityId.isPresent()) return mainService.getAllFaculties(); //ako nema parametar universityId gi vrakja site fakulteti 58 if (!universityId.isPresent()) 59 return mainService.getAllFaculties(); // ako nema parametar universityId gi vrakja site fakulteti 56 60 return mainService.getFacultiesByUniversityId(universityId.get()); 57 61 } … … 59 63 @RequestMapping(value = "/faculty/{facultyId}", method = RequestMethod.GET) 60 64 public Faculty getFacultyById(@PathVariable Long facultyId) { 61 return mainService.getFacultyById(facultyId); // vrakja fakultet spored id65 return mainService.getFacultyById(facultyId); // vrakja fakultet spored id 62 66 } 63 67 … … 65 69 public List<University> getUniversitiesByCity(@RequestParam Optional<Long> cityId) { 66 70 67 if(!cityId.isPresent()) return mainService.getAllUniversities(); //ako nema parametar cityId gi vrakja site univerziteti 71 if (!cityId.isPresent()) 72 return mainService.getAllUniversities(); // ako nema parametar cityId gi vrakja site univerziteti 68 73 return mainService.getUniversitiesByCityId(cityId.get()); 69 74 } … … 71 76 @RequestMapping(value = "/university/{universityId}", method = RequestMethod.GET) 72 77 public University getUniversityById(@PathVariable Long universityId) { 73 return mainService.getUniversityById(universityId); // vrakja univerzitet spored id78 return mainService.getUniversityById(universityId); // vrakja univerzitet spored id 74 79 } 75 80 76 81 @RequestMapping(value = "/cities", method = RequestMethod.GET) 77 82 public List<City> getCities() { 78 return mainService.getAllCities(); //gi vrakja site gradovi83 return mainService.getAllCities(); // gi vrakja site gradovi 79 84 } 80 85 81 86 @RequestMapping(value = "/city/{cityId}", method = RequestMethod.GET) 82 87 public City getCityById(@PathVariable Long cityId) { 83 return mainService.getCityById(cityId); // vrakja grad spored id88 return mainService.getCityById(cityId); // vrakja grad spored id 84 89 } 85 86 90 } -
springapp/src/main/java/mk/profesori/springapp/Model/Opinion.java
r7cb8c3c r4a64cf0 9 9 import javax.persistence.ManyToOne; 10 10 11 import lombok.NoArgsConstructor; 12 11 13 @Entity 12 14 @DiscriminatorValue("opinion") 15 @NoArgsConstructor 13 16 public class Opinion extends Post { 14 17 15 18 @ManyToOne 16 @JoinColumn(name = "professor_id" , nullable = false)19 @JoinColumn(name = "professor_id") 17 20 private Professor targetProfessor; 18 21 19 public Opinion(Long postId, String title, String content, CustomUserDetails author, LocalDateTime timePosted, 20 LocalDateTime timeLastEdited, Integer upvoteCount, Integer downvoteCount, Post parent, 21 List<Post> children, Professor targetProfessor) { 22 super(postId, title, content, author, timePosted, timeLastEdited, upvoteCount, downvoteCount, parent, children); 22 // konstruktor so parent (koga e reply) 23 public Opinion(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 24 LocalDateTime timeLastEdited, 25 Integer upvoteCount, Integer downvoteCount, Post parent, List<Post> children, Professor targetProfessor) { 26 super(title, content, author, timePosted, timeLastEdited, upvoteCount, downvoteCount, parent, children); 27 this.targetProfessor = targetProfessor; 28 } 29 30 // konstruktor bez parent (koga NE e reply) 31 public Opinion(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 32 LocalDateTime timeLastEdited, 33 Integer upvoteCount, Integer downvoteCount, List<Post> children, Professor targetProfessor) { 34 super(title, content, author, timePosted, timeLastEdited, upvoteCount, downvoteCount, children); 23 35 this.targetProfessor = targetProfessor; 24 36 } -
springapp/src/main/java/mk/profesori/springapp/Model/Post.java
r7cb8c3c r4a64cf0 22 22 import com.fasterxml.jackson.annotation.ObjectIdGenerators; 23 23 24 import lombok.NoArgsConstructor; 25 24 26 @Entity(name = "post") 25 27 @Inheritance(strategy = InheritanceType.SINGLE_TABLE) 26 28 @DiscriminatorColumn(name = "post_type", discriminatorType = DiscriminatorType.STRING) 27 29 @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "postId") 30 @NoArgsConstructor 28 31 public class Post { 29 32 … … 143 146 } 144 147 145 public Post(Long postId, String title, String content, CustomUserDetails author, LocalDateTime timePosted,146 LocalDateTime timeLastEdited, Integer upvoteCount, Integer downvoteCount, Post parent,147 L ist<Post> children) {148 this.postId = postId;148 // konstruktor so parent (koga e reply) 149 public Post(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 150 LocalDateTime timeLastEdited, 151 Integer upvoteCount, Integer downvoteCount, Post parent, List<Post> children) { 149 152 this.title = title; 150 153 this.content = content; 151 154 this.author = author; 152 this.timePosted = timePosted;153 this.timeLastEdited = timeLastEdited;154 this.upvoteCount = upvoteCount;155 this.downvoteCount = downvoteCount;155 this.timePosted = LocalDateTime.now(); 156 this.timeLastEdited = LocalDateTime.now(); 157 this.upvoteCount = 0; 158 this.downvoteCount = 0; 156 159 this.parent = parent; 157 this.children = children; 160 this.children = new ArrayList<>(); 161 } 162 163 // konstruktor bez parent (koga NE e reply) 164 public Post(String title, String content, CustomUserDetails author, LocalDateTime timePosted, 165 LocalDateTime timeLastEdited, 166 Integer upvoteCount, Integer downvoteCount, List<Post> children) { 167 this.title = title; 168 this.content = content; 169 this.author = author; 170 this.timePosted = LocalDateTime.now(); 171 this.timeLastEdited = LocalDateTime.now(); 172 this.upvoteCount = 0; 173 this.downvoteCount = 0; 174 this.parent = null; 175 this.children = new ArrayList<>(); 158 176 } 159 177 -
springapp/src/main/java/mk/profesori/springapp/Model/_Thread.java
r7cb8c3c r4a64cf0 1 1 package mk.profesori.springapp.Model; 2 2 3 import java.time.LocalDateTime;4 3 import java.util.ArrayList; 5 4 import java.util.List; … … 28 27 private Subject targetSubject; 29 28 30 public _Thread(Long postId, String title, String content, CustomUserDetails author, LocalDateTime timePosted, 31 LocalDateTime timeLastEdited, Integer upvoteCount, Integer downvoteCount, Post parent, 32 List<Post> children, List<String> tags, Section parentSection, Subject targetSubject) { 33 super(postId, title, content, author, timePosted, timeLastEdited, upvoteCount, downvoteCount, parent, children); 34 this.tags = tags; 35 this.parentSection = parentSection; 36 this.targetSubject = targetSubject; 37 } 29 // TODO 30 /* 31 * public _Thread(String title, String content, List<String> tags, Section 32 * parentSection, Subject targetSubject) { 33 * super(title, content); 34 * this.tags = tags; 35 * this.parentSection = parentSection; 36 * this.targetSubject = targetSubject; 37 * } 38 */ 38 39 39 40 // getters -
springapp/src/main/java/mk/profesori/springapp/Security/SecurityConfiguration.java
r7cb8c3c r4a64cf0 12 12 13 13 import lombok.RequiredArgsConstructor; 14 import mk.profesori.springapp.Service.CustomUserDetailsService;15 14 16 15 @Configuration … … 18 17 @EnableWebSecurity 19 18 public class SecurityConfiguration { 20 21 private final CustomUserDetailsService customUserDetailsService;22 19 23 20 @Bean … … 35 32 protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception { 36 33 http 34 .httpBasic() // neenkriptirani credentials osven ako ne e preky https/tls 35 .and() 37 36 .cors() 38 37 .and() 39 38 .csrf().disable() // PRIVREMENO 40 39 .authorizeRequests() 41 .antMatchers("/ registration/**")42 . permitAll()43 .an yRequest()44 . permitAll().and() // bese .authenticated()40 .antMatchers("/secure/**").hasAnyAuthority("REGULAR", "MODERATOR") 41 .antMatchers("/public/**").permitAll() 42 .antMatchers("/registration/**").permitAll() 43 .and() 45 44 .formLogin(); 46 45 -
springapp/src/main/java/mk/profesori/springapp/Service/CustomUserDetailsService.java
r7cb8c3c r4a64cf0 64 64 return userRepository.enableUser(email); 65 65 } 66 67 66 } -
springapp/src/main/java/mk/profesori/springapp/Service/MainService.java
r7cb8c3c r4a64cf0 9 9 import mk.profesori.springapp.Repository.CityRepository; 10 10 import mk.profesori.springapp.Repository.FacultyRepository; 11 import mk.profesori.springapp.Repository.OpinionRepository; 11 12 import mk.profesori.springapp.Repository.ProfessorRepository; 12 13 import mk.profesori.springapp.Repository.StudyProgrammeRepository; 13 14 import mk.profesori.springapp.Repository.UniversityRepository; 14 15 import mk.profesori.springapp.Model.City; 16 import mk.profesori.springapp.Model.CustomUserDetails; 15 17 import mk.profesori.springapp.Model.Faculty; 18 import mk.profesori.springapp.Model.Opinion; 16 19 import mk.profesori.springapp.Model.Professor; 17 20 import mk.profesori.springapp.Model.StudyProgramme; 18 21 import mk.profesori.springapp.Model.University; 19 22 20 @Service 23 @Service 21 24 public class MainService { 22 25 23 26 @Autowired 24 27 private ProfessorRepository professorRepository; … … 31 34 @Autowired 32 35 private CityRepository cityRepository; 36 @Autowired 37 private OpinionRepository opinionRepository; 33 38 34 39 public List<Professor> getAllProfessors() { … … 45 50 46 51 public List<Professor> getProfessorsByFacultyId(Long facultyId) { 47 52 48 53 Faculty faculty = facultyRepository.findByFacultyId(facultyId); 49 54 … … 66 71 67 72 public List<StudyProgramme> getStudyProgrammesByFacultyId(Long facultyId) { 68 73 69 74 Faculty faculty = facultyRepository.findByFacultyId(facultyId); 70 75 … … 85 90 86 91 public List<Faculty> getFacultiesByUniversityId(Long universityId) { 87 92 88 93 University university = universityRepository.findByUniversityId(universityId); 89 94 … … 104 109 105 110 public List<University> getUniversitiesByCityId(Long cityId) { 106 111 107 112 City city = cityRepository.findByCityId(cityId); 108 113 … … 121 126 return cityRepository.findByCityId(id); 122 127 } 128 129 public void addOpinion(String title, String content, Long professorId, CustomUserDetails currentUser) { 130 131 Professor targetProfessor = professorRepository.findByProfessorId(professorId); 132 133 Opinion opinionToAdd = new Opinion(title, content, currentUser, null, null, 134 null, null, null, targetProfessor); 135 136 opinionRepository.save(opinionToAdd); 137 } 138 139 public void replyToOpinion(String content, Long professorId, Long postId, CustomUserDetails currentUser) { 140 141 Professor targetProfessor = professorRepository.findByProfessorId(professorId); 142 Opinion targetOpinion = opinionRepository.findByPostId(postId); 143 144 Opinion opinionToAdd = new Opinion(null, content, currentUser, null, null, 145 null, null, targetOpinion, null, targetProfessor); 146 opinionRepository.save(opinionToAdd); 147 148 targetOpinion.getChildren().add(opinionToAdd); 149 opinionRepository.save(targetOpinion); 150 } 123 151 }
Note:
See TracChangeset
for help on using the changeset viewer.