<- Back to NucleoCore
Skip to main content

Data Repository

Simplifies the retrieval and saving of data entries into the NucleoDB database. 

Definition

@Repository
public interface AuthorDataRepository extends NDBDataRepository<AuthorDE, String>{
  AuthorDE findByNameAndKey(String name, String key);
  AuthorDE findByName(String name);
  void deleteByName(String name);
}

Usage

@RestController
public class AnimeController{

  @Autowired
  AuthorDataRepository authorRepository;


  @GetMapping("/get/{name}")
  public Optional<AuthorDE> getByName(@PathVariable String name){
    return authorRepository.findByName(id);
  }
  @DeleteMapping("/get/{name}")
  public void deleteByName(@PathVariable String name){
    Optional<AuthorDE> byName = authorRepository.findByName(id);
    if(byName.isPresent()){
      authorRepository.delete(byName.get());
    }
    return null;
  }
  @UpdateMapping("/get/{name}/{genre}")
  public void updateCountryByName(@PathVariable String name, @PathVariable String genre){
    Optional<AuthorDE> byName = authorRepository.findByName(id);
    if(byName.isPresent()){
      AuthorDE author = byName.get();
      author.getData().setGenre(genre);
      authorRepository.save(author);
    }
  }
}