source: src/main/java/com/example/eatys_app/service/RestoranServiceImpl.java

Last change on this file was b3f2adb, checked in by Aleksandar Siljanoski <acewow3@…>, 14 months ago

Adding project to repo

  • Property mode set to 100644
File size: 2.1 KB
Line 
1package com.example.eatys_app.service;
2
3import com.example.eatys_app.model.Menadzer;
4import com.example.eatys_app.model.Restoran;
5import com.example.eatys_app.model.exceptions.InvalidMenadzerIdException;
6import com.example.eatys_app.model.exceptions.InvalidRestoranIdException;
7import com.example.eatys_app.repository.MenadzerRepository;
8import com.example.eatys_app.repository.RestoranRepository;
9import org.springframework.stereotype.Service;
10
11import java.util.List;
12
13@Service
14public class RestoranServiceImpl implements RestoranService{
15
16 private final RestoranRepository restoranRepository;
17 private final MenadzerRepository menadzerRepository;
18
19 public RestoranServiceImpl(RestoranRepository restoranRepository, MenadzerRepository menadzerRepository) {
20 this.restoranRepository = restoranRepository;
21 this.menadzerRepository = menadzerRepository;
22 }
23
24
25
26 @Override
27 public List<Restoran> listAll() {
28 return this.restoranRepository.findAll();
29 }
30
31 @Override
32 public Restoran findById(Integer id) {
33 return this.restoranRepository.findById(id).orElseThrow(InvalidRestoranIdException::new);
34 }
35
36 @Override
37 public Restoran create(String ime, Integer rejting, String adresa, Integer menadzerId) {
38 Menadzer menadzer = this.menadzerRepository.findById(menadzerId).orElseThrow(InvalidMenadzerIdException::new);
39 Restoran restoran= new Restoran(ime,rejting,adresa,menadzer);
40 return this.restoranRepository.save(restoran);
41 }
42
43 @Override
44 public Restoran update(Integer id, String ime, Integer rejting, String adresa, Integer menadzerId) {
45 Menadzer menadzer = this.menadzerRepository.findById(menadzerId).orElseThrow(InvalidMenadzerIdException::new);
46 Restoran restoran=this.findById(id);
47 restoran.setIme(ime);
48 restoran.setRejting(rejting);
49 restoran.setAdresa(adresa);
50 restoran.setMenadzer(menadzer);
51 return this.restoranRepository.save(restoran);
52 }
53
54 @Override
55 public Restoran delete(Integer id) {
56 Restoran restoran=this.findById(id);
57 this.restoranRepository.delete(restoran);
58 return restoran;
59 }
60}
Note: See TracBrowser for help on using the repository browser.