Ignore:
Timestamp:
07/31/22 20:09:54 (2 years ago)
Author:
unknown <mlviktor23@…>
Branches:
main
Children:
080a3f3, 74b8c52
Parents:
0ae838b
Message:

changed search implementation in springapp

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  
    33import java.util.List;
    44import java.util.Optional;
    5 import java.util.regex.Matcher;
    6 import java.util.regex.Pattern;
    75
    86import org.springframework.beans.factory.annotation.Autowired;
    9 import org.springframework.data.jpa.domain.Specification;
    107import org.springframework.web.bind.annotation.CrossOrigin;
    118import org.springframework.web.bind.annotation.PathVariable;
     
    1310import org.springframework.web.bind.annotation.RequestMethod;
    1411import org.springframework.web.bind.annotation.RequestParam;
    15 import org.springframework.web.bind.annotation.ResponseBody;
    1612import org.springframework.web.bind.annotation.RestController;
    1713
     
    2117import mk.profesori.springapp.Model.StudyProgramme;
    2218import mk.profesori.springapp.Model.University;
    23 import mk.profesori.springapp.Repository.ProfessorRepository;
    2419import mk.profesori.springapp.Service.MainService;
    25 import mk.profesori.springapp.Service.Search.ProfessorSpecificationsBuilder;
    2620
    2721@RestController
     
    3327    private MainService mainService;
    3428
    35     @Autowired
    36     private ProfessorRepository professorRepository;
     29    @RequestMapping(value = "/professors", method = RequestMethod.GET)
     30    public List<Professor> getProfessorsByFaculty(@RequestParam Optional<Long> facultyId) {
    3731
    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
    4934
    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    }
    5937
    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
    6242    }
    6343
  • springapp/src/main/java/mk/profesori/springapp/Repository/ProfessorRepository.java

    r0ae838b ra4b5062  
    1818
    1919    public List<Professor> findByFaculty(Faculty faculty);
     20
     21    public List<Professor> findByProfessorNameContainingIgnoreCase(String name);
    2022}
  • springapp/src/main/java/mk/profesori/springapp/Service/MainService.java

    r0ae838b ra4b5062  
    5555        List<Professor> list = new ArrayList<>();
    5656        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);
    5763        return list;
    5864    }
Note: See TracChangeset for help on using the changeset viewer.