junction front - back
This commit is contained in:
		@ -114,15 +114,15 @@ public class MockController {
 | 
			
		||||
 | 
			
		||||
        Research jojoResearch = new Research("Graphs : Advanced Search Algorithms",output,new Date(0),
 | 
			
		||||
                PaperType.Article,"here",null,"english",
 | 
			
		||||
                Access.OpenSource,"IT","This Article's title speak for itself\n We'll discuss about advanced Graph search Algorithms");
 | 
			
		||||
                Access.OpenSource,"IT","This Article's title speaks for itself \n We'll discuss about advanced Graph search Algorithms");
 | 
			
		||||
 | 
			
		||||
        Research restrictedResearch = new Research("Graphs : Advanced Search Algorithms",output,new Date(1111111111),
 | 
			
		||||
        Research restrictedResearch = new Research("just another Name",output,new Date(1111111111),
 | 
			
		||||
                PaperType.Article,"restricted",null,"english",
 | 
			
		||||
                Access.Restricted,"Restricted","This Article's title speak for itself\n We'll discuss about advanced Graph search Algorithms");
 | 
			
		||||
                Access.Restricted,"Restricted","This Article's title speaks for itself\n We'll discuss about advanced Graph search Algorithms");
 | 
			
		||||
 | 
			
		||||
        Research privateResearch = new Research("Graphs : Advanced Search Algorithms",output,new Date(),
 | 
			
		||||
        Research privateResearch = new Research("the great Potato War",output,new Date(),
 | 
			
		||||
                PaperType.Article,"private",null,"english",
 | 
			
		||||
                Access.Private,"private","This Article's title speak for itself\n We'll discuss about advanced Graph search Algorithms");
 | 
			
		||||
                Access.Private,"private","This Article's title speaks for itself\n We'll discuss about advanced Graph search Algorithms");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        researchesService.saveResearch(restrictedResearch);
 | 
			
		||||
 | 
			
		||||
@ -73,6 +73,25 @@ public class ResearchController {
 | 
			
		||||
        return new ResponseEntity<>(toReturnResearches,HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/researches/{id}")
 | 
			
		||||
    public ResponseEntity<Iterable<ResearchDTO>> getResearchesFromResearcher(@RequestHeader(value = "Authorization",required = false) String token,
 | 
			
		||||
                                                                             @PathVariable Long id
 | 
			
		||||
    ){
 | 
			
		||||
        Iterable<Research> researches = researchesServ.getResearchesByAuthor(id);
 | 
			
		||||
        if (researches == null) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
 | 
			
		||||
 | 
			
		||||
        ArrayList<ResearchDTO> toReturnResearches = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        for (Research research: researches){
 | 
			
		||||
            if (researchesServ.hasNoAccessTo(research,authServ.getUserFromToken(token))){
 | 
			
		||||
                research.setPdfLocation(null);
 | 
			
		||||
            }
 | 
			
		||||
            toReturnResearches.add(ResearchDTO.construct(research));
 | 
			
		||||
        }
 | 
			
		||||
        return new ResponseEntity<>(toReturnResearches,HttpStatus.OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** post a new research
 | 
			
		||||
     *
 | 
			
		||||
     * @return the research saved
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,8 @@
 | 
			
		||||
package ovh.herisson.Clyde.Repositories.ScientificPublications;
 | 
			
		||||
 | 
			
		||||
import org.springframework.data.jpa.repository.Query;
 | 
			
		||||
import org.springframework.data.repository.CrudRepository;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.User;
 | 
			
		||||
 | 
			
		||||
@ -8,4 +10,7 @@ public interface ResearcherRepository extends CrudRepository<Researcher,Long> {
 | 
			
		||||
    Researcher findByUser(User user);
 | 
			
		||||
 | 
			
		||||
    Researcher findById(long id);
 | 
			
		||||
 | 
			
		||||
    @Query("select r from Research r where r.author = ?1")
 | 
			
		||||
    Iterable<Research> findAllByAuthorId(Researcher author);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ public interface StatsRepository extends CrudRepository<Research,Long> {
 | 
			
		||||
    @Query("select new map(to_char(r.releaseDate, 'month') as label, sum(r.views) as y) from Research r group by to_char(r.releaseDate, 'month')")
 | 
			
		||||
    Iterable<Map<String ,Integer>> viewsByMonths();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
    Iterable<Map<String ,Integer>> viewsByYears();
 | 
			
		||||
    Iterable<Map<String ,Integer>> viewsByTopics();
 | 
			
		||||
    Iterable<Map<String ,Integer>> coAuthorByMonths();
 | 
			
		||||
@ -22,6 +22,6 @@ public interface StatsRepository extends CrudRepository<Research,Long> {
 | 
			
		||||
    Iterable<Map<String ,Integer>> researchesByYears();
 | 
			
		||||
    Iterable<Map<String ,Integer>> researchesByTopics();
 | 
			
		||||
    Iterable<Map<String ,Integer>> researchesByMonth();
 | 
			
		||||
 | 
			
		||||
**/
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -42,6 +42,13 @@ public class ResearchesService {
 | 
			
		||||
        return articleRepo.findById(id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Iterable<Research> getResearchesByAuthor(long authorId){
 | 
			
		||||
        Researcher researcher = researcherRepo.findById(authorId);
 | 
			
		||||
        if (researcher == null) return null;
 | 
			
		||||
 | 
			
		||||
        return researcherRepo.findAllByAuthorId(researcher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean hasNoAccessTo(Research research, User user){
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user