2019-08-21 10:37:47 +02:00
|
|
|
package eu.eudat.controllers;
|
|
|
|
|
|
|
|
import eu.eudat.logic.managers.ContactEmailManager;
|
|
|
|
import eu.eudat.models.data.ContactEmail.ContactEmailModel;
|
2020-06-25 18:39:10 +02:00
|
|
|
import eu.eudat.models.data.ContactEmail.PublicContactEmailModel;
|
2019-08-21 10:37:47 +02:00
|
|
|
import eu.eudat.models.data.helpers.responses.ResponseItem;
|
|
|
|
import eu.eudat.models.data.security.Principal;
|
|
|
|
import eu.eudat.types.ApiMessageCode;
|
2020-01-16 16:46:24 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2019-08-21 10:37:47 +02:00
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@RequestMapping(value = "api/contactEmail")
|
|
|
|
public class ContactEmail {
|
2020-01-16 16:46:24 +01:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ContactEmail.class);
|
2019-08-21 10:37:47 +02:00
|
|
|
|
|
|
|
private ContactEmailManager contactEmailManager;
|
|
|
|
|
|
|
|
public ContactEmail(ContactEmailManager contactEmailManager) {
|
|
|
|
this.contactEmailManager = contactEmailManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity sendContactEmail(@RequestBody ContactEmailModel contactEmailModel, Principal principal) {
|
|
|
|
try {
|
2019-08-22 09:36:53 +02:00
|
|
|
this.contactEmailManager.emailValidation(contactEmailModel);
|
2019-08-21 10:37:47 +02:00
|
|
|
this.contactEmailManager.sendContactEmail(contactEmailModel, principal);
|
|
|
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
|
|
|
} catch (Exception ex) {
|
2020-01-16 16:46:24 +01:00
|
|
|
logger.error(ex.getMessage(), ex);
|
2019-08-22 09:36:53 +02:00
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
|
2019-08-21 10:37:47 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-25 18:39:10 +02:00
|
|
|
|
|
|
|
@Transactional
|
|
|
|
@RequestMapping(method = RequestMethod.POST, path = "public", consumes = "application/x-www-form-urlencoded", produces = "application/json")
|
|
|
|
public @ResponseBody
|
|
|
|
ResponseEntity sendContactEmailNoAuth(@ModelAttribute PublicContactEmailModel contactEmailModel) {
|
|
|
|
logger.info(contactEmailModel.toString());
|
|
|
|
try {
|
|
|
|
this.contactEmailManager.sendContactEmailNoAuth(contactEmailModel);
|
|
|
|
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
|
|
|
|
} catch (Exception ex) {
|
|
|
|
logger.error(ex.getMessage(), ex);
|
|
|
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 10:37:47 +02:00
|
|
|
}
|