1 | package com.example.moviezone.service.Impl;
|
---|
2 |
|
---|
3 | import com.example.moviezone.model.Customer;
|
---|
4 | import com.example.moviezone.model.Event;
|
---|
5 | import com.example.moviezone.model.manytomany.CustomerIsInterestedInEvent;
|
---|
6 | import com.example.moviezone.repository.CustomerIsInterestedInEventRepository;
|
---|
7 | import com.example.moviezone.service.CustomerIsInterestedInEventService;
|
---|
8 | import org.springframework.stereotype.Service;
|
---|
9 |
|
---|
10 | @Service
|
---|
11 | public class CustomerIsInterestedInEventImpl implements CustomerIsInterestedInEventService {
|
---|
12 | private final CustomerIsInterestedInEventRepository customerIsInterestedInEventRepository;
|
---|
13 |
|
---|
14 | public CustomerIsInterestedInEventImpl(CustomerIsInterestedInEventRepository customerIsInterestedInEventRepository) {
|
---|
15 | this.customerIsInterestedInEventRepository = customerIsInterestedInEventRepository;
|
---|
16 | }
|
---|
17 |
|
---|
18 | @Override
|
---|
19 | public CustomerIsInterestedInEvent add(Integer id_customer, Integer id_event) {
|
---|
20 | CustomerIsInterestedInEvent customerIsInterestedInEvent=new CustomerIsInterestedInEvent(id_customer,id_event);
|
---|
21 | return customerIsInterestedInEventRepository.save(customerIsInterestedInEvent);
|
---|
22 | }
|
---|
23 |
|
---|
24 | @Override
|
---|
25 | public void delete(Customer customer, Event event) {
|
---|
26 | CustomerIsInterestedInEvent customerIsInterestedInEvent=findByCustomerAndEvent(customer,event);
|
---|
27 | customerIsInterestedInEventRepository.delete(customerIsInterestedInEvent);
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public CustomerIsInterestedInEvent findByCustomerAndEvent(Customer customer, Event event) {
|
---|
32 | return customerIsInterestedInEventRepository.findFirstByIdeventAndAndIdcustomer(event.getId_event(),customer.getId_user());
|
---|
33 | }
|
---|
34 | }
|
---|