use of org.springframework.web.bind.annotation.PostMapping in project scoold by Erudika.
the class CommentController method createAjax.
@PostMapping
public String createAjax(@RequestParam String comment, @RequestParam String parentid, HttpServletRequest req, Model model) {
Profile authUser = utils.getAuthUser(req);
if (utils.canComment(authUser, req) && !StringUtils.isBlank(comment) && !StringUtils.isBlank(parentid)) {
Comment showComment = utils.populate(req, new Comment(), "comment");
showComment.setCreatorid(authUser.getId());
Map<String, String> error = utils.validate(showComment);
if (error.isEmpty()) {
showComment.setComment(comment);
showComment.setParentid(parentid);
showComment.setAuthorName(authUser.getName());
if (showComment.create() != null) {
long commentCount = authUser.getComments();
utils.addBadgeOnce(authUser, COMMENTATOR, commentCount >= COMMENTATOR_IFHAS);
authUser.setComments(commentCount + 1);
authUser.update();
model.addAttribute("showComment", showComment);
// send email to the author of parent post
Post parentPost = pc.read(parentid);
if (parentPost != null) {
parentPost.addCommentId(showComment.getId());
parentPost.update();
}
sendCommentNotification(parentPost, showComment, authUser);
}
}
}
return "comment";
}
use of org.springframework.web.bind.annotation.PostMapping in project sic by belluccifranco.
the class AuthController method login.
@PostMapping("/login")
public String login(@RequestBody Credencial credencial) {
Usuario usuario;
try {
usuario = usuarioService.getUsuarioPorNombreContrasenia(credencial.getUsername(), Utilidades.encriptarConMD5(credencial.getPassword()));
} catch (EntityNotFoundException ex) {
throw new UnauthorizedException(ResourceBundle.getBundle("Mensajes").getString("mensaje_usuario_logInInvalido"), ex);
}
String token = this.generarToken(usuario.getId_Usuario());
usuario.setToken(token);
usuarioService.actualizar(usuario);
return token;
}
use of org.springframework.web.bind.annotation.PostMapping in project dhis2-core by dhis2.
the class DataStatisticsController method saveEvent.
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void saveEvent(@RequestParam DataStatisticsEventType eventType, String favorite) {
Date timestamp = new Date();
String username = currentUserService.getCurrentUsername();
DataStatisticsEvent event = new DataStatisticsEvent(eventType, timestamp, username, favorite);
dataStatisticsService.addEvent(event);
}
use of org.springframework.web.bind.annotation.PostMapping in project spring-boot-rest-api by shaikhhafiz.
the class EmployeeController method createEmployee.
/**
* Save a new employee
* @param employee
* @return
*/
@PostMapping("employees/create")
public ResponseEntity<Employee> createEmployee(@PathVariable("managerId") Long managerId, @Valid @RequestBody Employee employee) {
Manager manager = null;
manager = managerService.findById(managerId);
if (manager == null) {
return new ResponseEntity("Manager with manager id " + managerId + "is not exist", HttpStatus.NO_CONTENT);
}
employee.setManager(manager);
List<Employee> employees = new ArrayList<Employee>();
employees.add(employee);
manager.setEmployees(employees);
/*
* To do check manager have at least one employee ohterwise manager.getEmployees().add(employee) will return
* null pointer exception
*/
// manager.getEmployees().add(employee);
Manager managerTemp = null;
managerTemp = managerService.save(manager);
if (managerTemp == null) {
return new ResponseEntity("Employee cant be created", HttpStatus.FAILED_DEPENDENCY);
}
return new ResponseEntity(employee, HttpStatus.CREATED);
}
use of org.springframework.web.bind.annotation.PostMapping in project tesla by linking12.
the class FilterRouteController method save.
@Log("保存路由")
@RequiresPermissions("filter:route:add")
@PostMapping("/save")
@ResponseBody()
public CommonResponse save(RouteVo zuulVo, @RequestParam(name = "zipFile", required = false) MultipartFile zipFile) {
try {
// grpc路由
if (zipFile != null) {
InputStream directoryZipStream = zipFile.getInputStream();
CommonResponse response = judgeFileType(directoryZipStream, "zip");
if (response != null) {
return response;
} else {
String serviceFileName = zuulVo.getServiceFileName();
byte[] protoContext = protobufService.compileDirectoryProto(zipFile, serviceFileName);
FilterRouteDto zuulDto = zuulVo.buildRouteDto();
zuulDto.setProtoContext(protoContext);
routeService.save(zuulDto);
}
} else {
FilterRouteDto zuulDto = zuulVo.buildRouteDto();
routeService.save(zuulDto);
}
} catch (IOException e) {
throw new TeslaException("保存路由失败", e);
}
return CommonResponse.ok();
}
Aggregations