Changeset a4b5062
- Timestamp:
- 07/31/22 20:09:54 (2 years ago)
- Branches:
- main
- Children:
- 080a3f3, 74b8c52
- Parents:
- 0ae838b
- Location:
- springapp/src/main/java/mk/profesori/springapp
- Files:
-
- 3 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
springapp/src/main/java/mk/profesori/springapp/Controller/PublicController.java
r0ae838b ra4b5062 3 3 import java.util.List; 4 4 import java.util.Optional; 5 import java.util.regex.Matcher;6 import java.util.regex.Pattern;7 5 8 6 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.data.jpa.domain.Specification;10 7 import org.springframework.web.bind.annotation.CrossOrigin; 11 8 import org.springframework.web.bind.annotation.PathVariable; … … 13 10 import org.springframework.web.bind.annotation.RequestMethod; 14 11 import org.springframework.web.bind.annotation.RequestParam; 15 import org.springframework.web.bind.annotation.ResponseBody;16 12 import org.springframework.web.bind.annotation.RestController; 17 13 … … 21 17 import mk.profesori.springapp.Model.StudyProgramme; 22 18 import mk.profesori.springapp.Model.University; 23 import mk.profesori.springapp.Repository.ProfessorRepository;24 19 import mk.profesori.springapp.Service.MainService; 25 import mk.profesori.springapp.Service.Search.ProfessorSpecificationsBuilder;26 20 27 21 @RestController … … 33 27 private MainService mainService; 34 28 35 @ Autowired36 p rivate ProfessorRepository professorRepository;29 @RequestMapping(value = "/professors", method = RequestMethod.GET) 30 public List<Professor> getProfessorsByFaculty(@RequestParam Optional<Long> facultyId) { 37 31 38 /* 39 * @RequestMapping(value = "/professors", method = RequestMethod.GET) 40 * public List<Professor> getProfessorsByFaculty(@RequestParam Optional<Long> 41 * facultyId) { 42 * 43 * if (!facultyId.isPresent()) 44 * return mainService.getAllProfessors(); // ako nema parametar facultyId gi 45 * vrakja site profesori 46 * return mainService.getProfessorsByFacultyId(facultyId.get()); 47 * } 48 */ 32 if (!facultyId.isPresent()) 33 return mainService.getAllProfessors(); // ako nema parametar facultyId gi vrakja site profesori 49 34 50 @RequestMapping(value = "/professors", method = RequestMethod.GET) 51 @ResponseBody 52 public List<Professor> search(@RequestParam(value = "search") String search) { 53 ProfessorSpecificationsBuilder builder = new ProfessorSpecificationsBuilder(); 54 Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),", Pattern.UNICODE_CHARACTER_CLASS); 55 Matcher matcher = pattern.matcher(search + ","); 56 while (matcher.find()) { 57 builder.with(matcher.group(1), matcher.group(2), matcher.group(3)); 58 } 35 return mainService.getProfessorsByFacultyId(facultyId.get()); 36 } 59 37 60 Specification<Professor> spec = builder.build(); 61 return professorRepository.findAll(spec); 38 @RequestMapping(value = "/professors/nameContains/{contained}", method = RequestMethod.GET) 39 public List<Professor> getProfessorsByNameContains(@PathVariable String contained) { 40 return mainService.getProfessorsByNameContains(contained); // vrakja profesori sto sodrzat "contained" vo 41 // professorName 62 42 } 63 43 -
springapp/src/main/java/mk/profesori/springapp/Repository/ProfessorRepository.java
r0ae838b ra4b5062 18 18 19 19 public List<Professor> findByFaculty(Faculty faculty); 20 21 public List<Professor> findByProfessorNameContainingIgnoreCase(String name); 20 22 } -
springapp/src/main/java/mk/profesori/springapp/Service/MainService.java
r0ae838b ra4b5062 55 55 List<Professor> list = new ArrayList<>(); 56 56 professorRepository.findByFaculty(faculty).forEach(list::add); 57 return list; 58 } 59 60 public List<Professor> getProfessorsByNameContains(String contained) { 61 List<Professor> list = new ArrayList<>(); 62 professorRepository.findByProfessorNameContainingIgnoreCase(contained).forEach(list::add); 57 63 return list; 58 64 }
Note:
See TracChangeset
for help on using the changeset viewer.