source: src/main/java/com/example/baza/service/impl/ChovekServiceImpl.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: 1.8 KB
Line 
1package com.example.baza.service.impl;
2
3import com.example.baza.model.Chovek2;
4import com.example.baza.model.exception.InvalidArgumentsException;
5import com.example.baza.model.exception.InvalidChovekIdException;
6import com.example.baza.model.exception.InvalidUserCredentialsException;
7import com.example.baza.repository.ChovekRepository;
8import com.example.baza.service.ChovekService;
9import org.springframework.stereotype.Service;
10
11import java.util.List;
12
13@Service
14public class ChovekServiceImpl implements ChovekService {
15 private final ChovekRepository chovekRepository;
16
17 public ChovekServiceImpl(ChovekRepository chovekRepository) {
18 this.chovekRepository = chovekRepository;
19 }
20
21 @Override
22 public List<Chovek2> listAll() {
23 return this.chovekRepository.findAll();
24 }
25
26 @Override
27 public Chovek2 findById(Integer id) {
28 return this.chovekRepository.findById(id).orElseThrow(InvalidChovekIdException::new);
29 }
30
31 @Override
32 public Chovek2 login(String username, String password) {
33 if(username == null || username.isEmpty() || password == null || password.isEmpty())
34 {
35 throw new InvalidArgumentsException();
36 }
37 return chovekRepository.findByUsernameAndPassword(username,password)
38 .orElseThrow(InvalidUserCredentialsException::new);
39 }
40
41
42 @Override
43 public Chovek2 create(String ime, String prezime, String email, String telBroj, String adresa, String embg, String username, String password) {
44 return this.chovekRepository.save(new Chovek2(ime,prezime,email,telBroj,adresa,embg,username,password));
45 }//todo : dali postoi dali ne , exception etc etc...
46
47 @Override
48 public Chovek2 delete(Integer id) {
49 Chovek2 ch=this.findById(id);
50 this.chovekRepository.delete(ch);
51 return ch;
52 }
53}
Note: See TracBrowser for help on using the repository browser.