1 | package com.example.autopartz.service.impl;
|
---|
2 |
|
---|
3 | import com.example.autopartz.model.RepairShop;
|
---|
4 | import com.example.autopartz.model.manytomany.RsForCm;
|
---|
5 | import com.example.autopartz.repository.CarManufacturerRepository;
|
---|
6 | import com.example.autopartz.repository.RepairShopRepository;
|
---|
7 | import com.example.autopartz.repository.RsForCmRepository;
|
---|
8 | import com.example.autopartz.service.RepairShopService;
|
---|
9 | import org.springframework.stereotype.Service;
|
---|
10 |
|
---|
11 | import javax.transaction.Transactional;
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 | @Service
|
---|
15 | public class RepairShopServiceImpl implements RepairShopService {
|
---|
16 | private final RepairShopRepository repairShopRepository;
|
---|
17 | private final CarManufacturerRepository carManufacturerRepository;
|
---|
18 | private final RsForCmRepository rsForCmRepository;
|
---|
19 |
|
---|
20 | public RepairShopServiceImpl(RepairShopRepository repairShopRepository, CarManufacturerRepository carManufacturerRepository, RsForCmRepository rsForCmRepository) {
|
---|
21 | this.repairShopRepository = repairShopRepository;
|
---|
22 | this.carManufacturerRepository = carManufacturerRepository;
|
---|
23 | this.rsForCmRepository = rsForCmRepository;
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public List<RepairShop> findAll() {
|
---|
28 | return repairShopRepository.findAll();
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public RepairShop getByName(String name) {
|
---|
33 | return repairShopRepository.getRepairShopByName(name);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public RepairShop getById(Integer id) {
|
---|
38 | return repairShopRepository.findById(id).get();
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | @Transactional
|
---|
43 | public void save(String name, String location, String number, Integer carMId) {
|
---|
44 | RepairShop newRs = new RepairShop(name,location,number,
|
---|
45 | List.of(carManufacturerRepository.findById(carMId).get()));
|
---|
46 | repairShopRepository.save(newRs);
|
---|
47 | rsForCmRepository.save(new RsForCm(newRs.getId(), carMId));
|
---|
48 | }
|
---|
49 | }
|
---|