source: src/main/java/com/project/beautycenter/service/impl/VraboteniServiceImpl.java

Last change on this file was 850b344, checked in by Tamara Simikj <tamara.simic12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 2.2 KB
RevLine 
[850b344]1package com.project.beautycenter.service.impl;
2
3import com.project.beautycenter.model.Beautycenter;
4import com.project.beautycenter.model.Users;
5import com.project.beautycenter.model.Vraboteni;
6import com.project.beautycenter.model.exceptions.InvalidUserIdException;
7import com.project.beautycenter.repository.BeautyCenterRepository;
8import com.project.beautycenter.repository.UsersRepository;
9import com.project.beautycenter.repository.VraboteniRepository;
10import com.project.beautycenter.service.VraboteniService;
11import org.springframework.stereotype.Service;
12
13import java.time.Instant;
14import java.util.List;
15
16@Service
17public class VraboteniServiceImpl implements VraboteniService {
18 private final VraboteniRepository vraboteniRepository;
19 private final UsersRepository usersRepository;
20 private final BeautyCenterRepository beautyCenterRepository;
21
22 public VraboteniServiceImpl(VraboteniRepository vraboteniRepository, UsersRepository usersRepository, BeautyCenterRepository beautyCenterRepository) {
23 this.vraboteniRepository = vraboteniRepository;
24 this.usersRepository = usersRepository;
25 this.beautyCenterRepository = beautyCenterRepository;
26 }
27
28 @Override
29 public List<Vraboteni> findAll() {
30 return this.vraboteniRepository.findAll();
31 }
32
33 @Override
34 public Vraboteni findbyId(Integer id) {
35 return this.vraboteniRepository.findById(id).orElseThrow(NullPointerException::new);
36 }
37
38 @Override
39 public Vraboteni findVrabotenByUserId(Integer id) {
40 return this.vraboteniRepository.getById(id);
41 }
42
43 @Override
44 public Vraboteni create(Users users, String ime, String middleName, String prezime, String telBr, String email,
45 Integer rabIskustvo, Instant rabotiOd, String beautyCenterId) {
46
47 Users user = this.usersRepository.findById(users.getId()).orElseThrow(InvalidUserIdException::new);
48 Beautycenter beautycenter = this.beautyCenterRepository.getById(beautyCenterId);
49 Vraboteni vraboteni = new Vraboteni(user, ime, middleName, prezime, telBr, email, rabIskustvo, rabotiOd, beautycenter);
50 return this.vraboteniRepository.save(vraboteni);
51 }
52}
Note: See TracBrowser for help on using the repository browser.