source: src/main/java/com/example/baza/service/impl/KnigiServiceImpl.java

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

Initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1package com.example.baza.service.impl;
2
3
4import com.example.baza.model.*;
5import com.example.baza.model.exception.InvalidArgumentsException;
6import com.example.baza.model.exception.InvalidKnigaIdException;
7import com.example.baza.model.exception.KnigaNotFoundException;
8import com.example.baza.repository.KnigiRepository;
9import com.example.baza.service.KnigiService;
10import org.springframework.stereotype.Service;
11
12import java.util.List;
13import java.util.Set;
14import java.util.*;
15@Service
16public class KnigiServiceImpl implements KnigiService {
17 private final KnigiRepository knigiRepository;
18
19 public KnigiServiceImpl(KnigiRepository knigiRepository) {
20 this.knigiRepository = knigiRepository;
21 }
22
23 @Override
24 public Knigi findById(Integer id) {
25 return this.knigiRepository.findById(id).orElseThrow(InvalidKnigaIdException::new);
26 }
27
28
29
30 @Override
31 public List<Knigi> findByOpisLike(String opis) {
32 if(opis == null || opis.isEmpty()){
33 throw new InvalidArgumentsException();
34 }
35 return this.knigiRepository.findByOpisLike(opis);
36 }
37
38 @Override
39 public List<Knigi> findByNaslovLike(String naslov) {
40 if(naslov == null || naslov.isEmpty())
41 {
42 throw new InvalidArgumentsException();
43 }
44 return this.knigiRepository.findByNaslovLike(naslov);
45 }
46
47 @Override
48 public List<Knigi> listAll() {
49 return this.knigiRepository.findAll();
50 }
51
52 @Override
53 public List<Knigi> findByNaslov(String naslov) {
54 if(naslov == null || naslov.isEmpty())
55 {
56 throw new InvalidArgumentsException();
57 }
58 return this.knigiRepository.findByNaslov(naslov);
59 }
60
61 @Override
62 public Knigi create(String naslov, String opis, Izdavac izdavac, Set<Kategorija> kategorijas, Set<Avtor> avtors) {
63 return this.knigiRepository.save(new Knigi(naslov,opis,izdavac,kategorijas,avtors));
64 //more things todo
65 }
66
67 @Override
68 public Knigi update(Integer id, String naslov, String opis, Izdavac izdavac, Set<Kategorija> kategorijas, Set<Avtor> avtors) {
69 Knigi knigi=this.findById(id);
70 knigi.setOpis(opis);
71 knigi.setNaslov(naslov);
72 knigi.setIzdavac(izdavac);
73 knigi.setKategorijas(kategorijas);
74 knigi.setAvtors(avtors);
75 return this.knigiRepository.save(knigi);
76 }
77
78
79
80 @Override
81 public Knigi deletebyId(Integer id) {
82 Knigi knigi=this.findById(id);
83 this.knigiRepository.deleteById(id);
84 return knigi;
85 }
86
87 @Override
88 public void delteById(Integer id) {
89 this.knigiRepository.deleteById(id);
90 }
91}
Note: See TracBrowser for help on using the repository browser.