1 |
51049
|
argiro.kok
|
package eu.dnetlib.uoaadmintools.controllers;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
|
4 |
59470
|
konstantin
|
import eu.dnetlib.uoaadmintools.entities.subscriber.Subscriber;
|
5 |
|
|
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException;
|
6 |
51049
|
argiro.kok
|
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 |
53941
|
argiro.kok
|
public List<Subscriber> getSubscriber() throws ContentNotFoundException {
|
23 |
51049
|
argiro.kok
|
List<Subscriber> list = subscriberDAO.findAll();
|
24 |
|
|
if(list == null){
|
25 |
53941
|
argiro.kok
|
throw new ContentNotFoundException("Subscribers not found");
|
26 |
51049
|
argiro.kok
|
}
|
27 |
|
|
return subscriberDAO.findAll();
|
28 |
|
|
}
|
29 |
|
|
@RequestMapping(value = "/subscriber/{email}", method = RequestMethod.GET)
|
30 |
53941
|
argiro.kok
|
public Subscriber getSubscriber(@PathVariable(value="email", required = true) String email) throws ContentNotFoundException {
|
31 |
51049
|
argiro.kok
|
Subscriber subscriber = subscriberDAO.findByEmail(email);
|
32 |
|
|
if(subscriber == null){
|
33 |
53941
|
argiro.kok
|
throw new ContentNotFoundException("Subscribers not found");
|
34 |
51049
|
argiro.kok
|
}
|
35 |
|
|
return subscriber;
|
36 |
|
|
}
|
37 |
60499
|
konstantin
|
// @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 |
51049
|
argiro.kok
|
|
51 |
|
|
}
|