source: src/main/java/com/example/baza/service/impl/InstancaOdKnigaServiceImpl.java@ bc39b15

Last change on this file since bc39b15 was ed20c2c, checked in by HumaSejdini <humasejdini12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1package com.example.baza.service.impl;
2
3import com.example.baza.model.Dobavuvac;
4import com.example.baza.model.InstancaOdKniga;
5import com.example.baza.model.Knigi;
6import com.example.baza.model.exception.InvalidKnigaIdException;
7import com.example.baza.model.exception.InvalidUniqueIdException;
8import com.example.baza.repository.InstancaOdKnigaRepository;
9import com.example.baza.repository.KnigiRepository;
10import com.example.baza.service.InstancaOdKnigaService;
11import org.springframework.stereotype.Service;
12
13import java.util.List;
14
15@Service
16public class InstancaOdKnigaServiceImpl implements InstancaOdKnigaService {
17 private final InstancaOdKnigaRepository instancaOdKnigaRepository;
18 private final KnigiRepository knigiRepository;
19
20 public InstancaOdKnigaServiceImpl(InstancaOdKnigaRepository instancaOdKnigaRepository, KnigiRepository knigiRepository) {
21 this.instancaOdKnigaRepository = instancaOdKnigaRepository;
22 this.knigiRepository = knigiRepository;
23 }
24
25 @Override
26 public InstancaOdKniga findByUniqueId(Integer uid) {
27 return this.instancaOdKnigaRepository.findById(uid).orElseThrow(InvalidUniqueIdException::new);
28 }
29
30 @Override
31 public Knigi findById(Integer id) {
32 return this.knigiRepository.findById(id).orElseThrow(InvalidKnigaIdException::new);
33 }
34
35 @Override
36 public List<InstancaOdKniga> listAll() {
37 return this.instancaOdKnigaRepository.findAll();
38 }
39
40 @Override
41 public InstancaOdKniga create(Knigi idNaKniga, Boolean daliEOstetena, Boolean status, Dobavuvac idNaDobavuvac) {
42 return this.instancaOdKnigaRepository.save(new InstancaOdKniga(idNaKniga,daliEOstetena,status,idNaDobavuvac));
43 }
44
45 @Override
46 public InstancaOdKniga update(Integer id, Knigi idNaKniga, Boolean daliEOstetena, Boolean status, Dobavuvac idNaDobavuvac) {
47 InstancaOdKniga i=this.findByUniqueId(id);
48 i.setIdNaKniga(idNaKniga);
49 i.setDaliEOstetena(daliEOstetena);
50 i.setStatus(status);
51 i.setIdNaDobavuvac(idNaDobavuvac);
52 return this.instancaOdKnigaRepository.save(i);
53 }
54
55 @Override
56 public InstancaOdKniga delete(Integer id) {
57 InstancaOdKniga i=this.findByUniqueId(id);
58 this.instancaOdKnigaRepository.deleteById(id);
59 return i;
60 }
61}
Note: See TracBrowser for help on using the repository browser.