1 | package com.project.beautycenter.service.impl;
|
---|
2 |
|
---|
3 | import com.project.beautycenter.model.Beautycenter;
|
---|
4 | import com.project.beautycenter.model.Users;
|
---|
5 | import com.project.beautycenter.model.Vraboteni;
|
---|
6 | import com.project.beautycenter.model.exceptions.InvalidUserIdException;
|
---|
7 | import com.project.beautycenter.repository.BeautyCenterRepository;
|
---|
8 | import com.project.beautycenter.repository.UsersRepository;
|
---|
9 | import com.project.beautycenter.repository.VraboteniRepository;
|
---|
10 | import com.project.beautycenter.service.VraboteniService;
|
---|
11 | import org.springframework.stereotype.Service;
|
---|
12 |
|
---|
13 | import java.time.Instant;
|
---|
14 | import java.util.List;
|
---|
15 |
|
---|
16 | @Service
|
---|
17 | public 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 | }
|
---|