1
0
forked from PGL/Clyde

added addview and download PDF

This commit is contained in:
2024-04-17 00:09:30 +02:00
parent 388c53e47b
commit 821377a72f
8 changed files with 63 additions and 39 deletions

View File

@ -225,4 +225,16 @@ public class ResearchController {
return new ResponseEntity<>(HttpStatus.OK);
}
///////
//views part
@PostMapping("/addView{url}")
public ResponseEntity<ResearchDTO> addView(@PathVariable String url){
Research research = researchesServ.getResearchByUrl(url);
if (research ==null) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(ResearchDTO.construct(researchesServ.addView(research)), HttpStatus.OK);
}
}

View File

@ -12,4 +12,6 @@ public interface ResearchRepository extends CrudRepository<Research,Long> {
Iterable<Research> findByAuthor(Researcher author);
Research findByPdfLocation(String url);
}

View File

@ -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();
@Query("select new map(to_char(r.releaseDate,'year') as label, sum (r.views) as y) from Research r group by to_char(r.releaseDate,'year')")
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, sum (r.views) as y) from Research r group by to_char(r.releaseDate,'YYYY')")
Iterable<Map<String ,Integer>> viewsByYears();
@ -19,16 +19,16 @@ public interface StatsRepository extends CrudRepository<Research,Long> {
Iterable<Map<String ,Integer>> viewsByTopics();
@Query("select new map(r.domain as label, r.language as y) from Research r group by r.domain")
@Query("select new map(r.domain as label, count(r.language) as y) from Research r group by r.domain")
Iterable<Map<String ,Integer>> languageByTopics();
@Query("select new map(to_char(r.releaseDate,'year') as label, r.language as y) from Research r group by to_char(r.releaseDate,'year')")
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, count(r.language) as y) from Research r group by to_char(r.releaseDate,'YYYY')")
Iterable<Map<String ,Integer>> languageByYears();
@Query("select new map(to_char(r.releaseDate, 'month') as label, r.language as y) from Research r group by to_char(r.releaseDate, 'month')")
@Query("select new map(to_char(r.releaseDate, 'month') as label, count(r.language) as y) from Research r group by to_char(r.releaseDate, 'month')")
Iterable<Map<String ,Integer>> languageByMonths();
@Query("select new map(to_char(r.releaseDate,'year') as label, count(r) as y) from Research r group by to_char(r.releaseDate,'year')")
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, count(r) as y) from Research r group by to_char(r.releaseDate,'YYYY')")
Iterable<Map<String ,Integer>> researchesByYears();
@Query("select new map(r.domain as label, count(r) as y) from Research r group by r.domain")

View File

@ -2,6 +2,7 @@ package ovh.herisson.Clyde.Services.ScientificPublications;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.DTO.ScientificPublications.ResearchDTO;
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchCoAuthorsRepository;
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchRepository;
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearcherRepository;
@ -186,4 +187,13 @@ public class ResearchesService {
}
researcherRepo.save(researcher);
}
public Research getResearchByUrl(String url) {
return articleRepo.findByPdfLocation(url);
}
public Research addView(Research research) {
research.setViews(research.getViews()+1);
articleRepo.save(research);
}
}

View File

@ -40,7 +40,6 @@ public class StatisticsService {
toReturn.add(statsRepo.languageByYears());
toReturn.add(statsRepo.languageByMonths());
toReturn.add(statsRepo.languageByTopics());
return toReturn;
}
}