Skip to content

Commit

Permalink
Provide endpoint to return all genes (#86)
Browse files Browse the repository at this point in the history
* Provide endpoint to return all genes

Co-authored-by: Calvin Lu <[email protected]>
  • Loading branch information
zhx828 and calvinlu3 authored Oct 24, 2022
1 parent c7d7d56 commit 4f462d8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mskcc.oncokb.transcript.repository;

import java.util.List;
import java.util.Optional;
import org.mskcc.oncokb.transcript.domain.Gene;
import org.springframework.cache.annotation.Cacheable;
Expand All @@ -17,4 +18,7 @@ public interface GeneRepository extends JpaRepository<Gene, Long> {

@Cacheable(cacheResolver = "geneCacheResolver")
Optional<Gene> findByHugoSymbol(String hugoSymbol);

@Query("select distinct g from Gene g left join fetch g.geneAliases ga left join fetch g.ensemblGenes eg")
List<Gene> findAllWithGeneAliasAndEnsemblGenes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ public Optional<Gene> partialUpdate(Gene gene) {

/**
* Get all the genes.
* We do not use the default find all is because the FetchType.EAGER in the gene model.
* The default will trigger a lot of queries to the database.
*
* @return the list of entities.
*/
@Transactional(readOnly = true)
public List<Gene> findAll() {
log.debug("Request to get all Genes");
return geneRepository.findAll();
return geneRepository.findAllWithGeneAliasAndEnsemblGenes();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.mskcc.oncokb.transcript.web.rest;

import java.util.List;
import org.mskcc.oncokb.transcript.domain.Gene;
import org.mskcc.oncokb.transcript.service.GeneService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
* REST controller for managing {@link org.mskcc.oncokb.transcript.domain.Gene}.
*/
@RestController
@RequestMapping("/api")
public class GeneResource {

private final Logger log = LoggerFactory.getLogger(GeneResource.class);

private final GeneService geneService;

public GeneResource(GeneService geneService) {
this.geneService = geneService;
}

/**
* {@code GET /genes} : get all the genes.
*
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of genes in body.
*/
@GetMapping("/genes")
public List<Gene> getAllGenes() {
log.debug("REST request to get all Genes");
return geneService.findAll();
}
}

0 comments on commit 4f462d8

Please sign in to comment.