Changeset 0ae838b for springapp/src/main


Ignore:
Timestamp:
07/31/22 17:13:57 (2 years ago)
Author:
unknown <mlviktor23@…>
Branches:
main
Children:
a4b5062
Parents:
a6dcc46
Message:

created Search service in springapp

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  
    33import java.util.List;
    44import java.util.Optional;
     5import java.util.regex.Matcher;
     6import java.util.regex.Pattern;
    57
    68import org.springframework.beans.factory.annotation.Autowired;
     9import org.springframework.data.jpa.domain.Specification;
    710import org.springframework.web.bind.annotation.CrossOrigin;
    811import org.springframework.web.bind.annotation.PathVariable;
     
    1013import org.springframework.web.bind.annotation.RequestMethod;
    1114import org.springframework.web.bind.annotation.RequestParam;
     15import org.springframework.web.bind.annotation.ResponseBody;
    1216import org.springframework.web.bind.annotation.RestController;
    1317
     
    1721import mk.profesori.springapp.Model.StudyProgramme;
    1822import mk.profesori.springapp.Model.University;
     23import mk.profesori.springapp.Repository.ProfessorRepository;
    1924import mk.profesori.springapp.Service.MainService;
     25import mk.profesori.springapp.Service.Search.ProfessorSpecificationsBuilder;
    2026
    2127@RestController
     
    2733    private MainService mainService;
    2834
     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
    2950    @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        }
    3159
    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);
    3562    }
    3663
  • springapp/src/main/java/mk/profesori/springapp/Repository/ProfessorRepository.java

    ra6dcc46 r0ae838b  
    33import java.util.List;
    44
     5import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
    56import org.springframework.data.repository.CrudRepository;
    67import org.springframework.stereotype.Repository;
     
    1011
    1112@Repository
    12 public interface ProfessorRepository extends CrudRepository<Professor, Long>{
    13    
     13public interface ProfessorRepository extends CrudRepository<Professor, Long>, JpaSpecificationExecutor<Professor> {
     14
    1415    public List<Professor> findAll();
     16
    1517    public Professor findByProfessorId(Long id);
     18
    1619    public List<Professor> findByFaculty(Faculty faculty);
    1720}
  • springapp/src/main/resources/application.properties

    ra6dcc46 r0ae838b  
    11spring.datasource.url=jdbc:postgresql://localhost:5432/profesori.mk
     2spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;
    23spring.datasource.username=postgres
    34spring.datasource.password=1win7337
Note: See TracChangeset for help on using the changeset viewer.