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