Changeset 0ae838b for springapp/src
- Timestamp:
- 07/31/22 17:13:57 (2 years ago)
- Branches:
- main
- Children:
- a4b5062
- Parents:
- a6dcc46
- Location:
- springapp/src/main
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
springapp/src/main/java/mk/profesori/springapp/Controller/PublicController.java
ra6dcc46 r0ae838b 3 3 import java.util.List; 4 4 import java.util.Optional; 5 import java.util.regex.Matcher; 6 import java.util.regex.Pattern; 5 7 6 8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.data.jpa.domain.Specification; 7 10 import org.springframework.web.bind.annotation.CrossOrigin; 8 11 import org.springframework.web.bind.annotation.PathVariable; … … 10 13 import org.springframework.web.bind.annotation.RequestMethod; 11 14 import org.springframework.web.bind.annotation.RequestParam; 15 import org.springframework.web.bind.annotation.ResponseBody; 12 16 import org.springframework.web.bind.annotation.RestController; 13 17 … … 17 21 import mk.profesori.springapp.Model.StudyProgramme; 18 22 import mk.profesori.springapp.Model.University; 23 import mk.profesori.springapp.Repository.ProfessorRepository; 19 24 import mk.profesori.springapp.Service.MainService; 25 import mk.profesori.springapp.Service.Search.ProfessorSpecificationsBuilder; 20 26 21 27 @RestController … … 27 33 private MainService mainService; 28 34 35 @Autowired 36 private ProfessorRepository professorRepository; 37 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 */ 49 29 50 @RequestMapping(value = "/professors", method = RequestMethod.GET) 30 public List<Professor> getProfessorsByFaculty(@RequestParam Optional<Long> facultyId) { 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 } 31 59 32 if (!facultyId.isPresent()) 33 return mainService.getAllProfessors(); // ako nema parametar facultyId gi vrakja site profesori 34 return mainService.getProfessorsByFacultyId(facultyId.get()); 60 Specification<Professor> spec = builder.build(); 61 return professorRepository.findAll(spec); 35 62 } 36 63 -
springapp/src/main/java/mk/profesori/springapp/Repository/ProfessorRepository.java
ra6dcc46 r0ae838b 3 3 import java.util.List; 4 4 5 import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 5 6 import org.springframework.data.repository.CrudRepository; 6 7 import org.springframework.stereotype.Repository; … … 10 11 11 12 @Repository 12 public interface ProfessorRepository extends CrudRepository<Professor, Long> {13 13 public interface ProfessorRepository extends CrudRepository<Professor, Long>, JpaSpecificationExecutor<Professor> { 14 14 15 public List<Professor> findAll(); 16 15 17 public Professor findByProfessorId(Long id); 18 16 19 public List<Professor> findByFaculty(Faculty faculty); 17 20 } -
springapp/src/main/resources/application.properties
ra6dcc46 r0ae838b 1 1 spring.datasource.url=jdbc:postgresql://localhost:5432/profesori.mk 2 spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8; 2 3 spring.datasource.username=postgres 3 4 spring.datasource.password=1win7337
Note:
See TracChangeset
for help on using the changeset viewer.