1 |
51049
|
argiro.kok
|
package eu.dnetlib.uoaadmintools.controllers;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
|
4 |
|
|
import eu.dnetlib.uoaadmintools.entities.Community;
|
5 |
|
|
import eu.dnetlib.uoaadmintools.entities.DivId;
|
6 |
|
|
import eu.dnetlib.uoaadmintools.entities.Subscriber;
|
7 |
|
|
import eu.dnetlib.uoaadmintools.handlers.NotFoundException;
|
8 |
|
|
import org.apache.log4j.Logger;
|
9 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
|
|
import org.springframework.web.bind.annotation.*;
|
11 |
|
|
|
12 |
|
|
import java.util.Iterator;
|
13 |
|
|
import java.util.List;
|
14 |
|
|
|
15 |
|
|
/**
|
16 |
|
|
* Created by argirok on 2/3/2018.
|
17 |
|
|
*/
|
18 |
|
|
@RestController
|
19 |
|
|
@CrossOrigin(origins = "*")
|
20 |
|
|
public class SubscriberController {
|
21 |
|
|
private final Logger log = Logger.getLogger(this.getClass());
|
22 |
|
|
@Autowired
|
23 |
|
|
private SubscriberDAO subscriberDAO;
|
24 |
|
|
@RequestMapping(value = "/subscriber", method = RequestMethod.GET)
|
25 |
|
|
public List<Subscriber> getSubscriber() throws NotFoundException {
|
26 |
|
|
List<Subscriber> list = subscriberDAO.findAll();
|
27 |
|
|
if(list == null){
|
28 |
|
|
throw new NotFoundException("Subscribers not found");
|
29 |
|
|
}
|
30 |
|
|
return subscriberDAO.findAll();
|
31 |
|
|
}
|
32 |
|
|
@RequestMapping(value = "/subscriber/{email}", method = RequestMethod.GET)
|
33 |
|
|
public Subscriber getSubscriber(@PathVariable(value="email", required = true) String email) throws NotFoundException {
|
34 |
|
|
Subscriber subscriber = subscriberDAO.findByEmail(email);
|
35 |
|
|
if(subscriber == null){
|
36 |
|
|
throw new NotFoundException("Subscribers not found");
|
37 |
|
|
}
|
38 |
|
|
return subscriber;
|
39 |
|
|
}
|
40 |
|
|
@RequestMapping(value = "/subscriber", method = RequestMethod.POST)
|
41 |
|
|
public Subscriber saveSubscriber(@RequestBody Subscriber subscriber) {
|
42 |
|
|
return subscriberDAO.save(subscriber);
|
43 |
|
|
}
|
44 |
|
|
@RequestMapping(value = "/subscriber/{email}", method = RequestMethod.DELETE)
|
45 |
|
|
public void deleteSubscriber(@PathVariable(value="email", required = true) String email) throws NotFoundException {
|
46 |
|
|
Subscriber subscriber = subscriberDAO.findByEmail(email);
|
47 |
|
|
if(subscriber == null){
|
48 |
|
|
throw new NotFoundException("Subscribers not found");
|
49 |
|
|
}
|
50 |
|
|
subscriberDAO.delete(subscriber.getId());
|
51 |
|
|
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
}
|