Search in sources :

Example 16 with PostMapping

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";
}
Also used : Comment(com.erudika.scoold.core.Comment) Post(com.erudika.scoold.core.Post) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 17 with PostMapping

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;
}
Also used : Usuario(sic.modelo.Usuario) EntityNotFoundException(javax.persistence.EntityNotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 18 with PostMapping

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);
}
Also used : DataStatisticsEvent(org.hisp.dhis.datastatistics.DataStatisticsEvent) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 19 with PostMapping

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Employee(rest.spring.entity.Employee) ArrayList(java.util.ArrayList) Manager(rest.spring.entity.Manager) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 20 with PostMapping

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();
}
Also used : InputStream(java.io.InputStream) FilterRouteDto(io.github.tesla.ops.filter.dto.FilterRouteDto) IOException(java.io.IOException) CommonResponse(io.github.tesla.ops.common.CommonResponse) TeslaException(io.github.tesla.ops.common.TeslaException) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) PostMapping(org.springframework.web.bind.annotation.PostMapping) Log(io.github.tesla.ops.common.Log) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

PostMapping (org.springframework.web.bind.annotation.PostMapping)83 ApiOperation (io.swagger.annotations.ApiOperation)21 Profile (com.erudika.scoold.core.Profile)20 Post (com.erudika.scoold.core.Post)9 Example (tk.mybatis.mapper.entity.Example)8 HashMap (java.util.HashMap)7 Service (org.apereo.cas.authentication.principal.Service)6 ResponseEntity (org.springframework.http.ResponseEntity)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)5 AuthenticationResult (org.apereo.cas.authentication.AuthenticationResult)5 RegisteredService (org.apereo.cas.services.RegisteredService)5 User (amu.zhcet.data.user.User)4 Report (com.erudika.scoold.core.Report)4 IOException (java.io.IOException)4 Map (java.util.Map)4 Credential (org.apereo.cas.authentication.Credential)4 Reply (com.erudika.scoold.core.Reply)3 Log (io.github.tesla.ops.common.Log)3 LinkedHashMap (java.util.LinkedHashMap)3