Commit 8c0322bd by Juho Juopperi

rest annotations and return types

1 parent 83117e3f
package fi.codecrew.moya.rest.pojo.util.v1; package fi.codecrew.moya.rest.pojo.util.v1;
import com.wordnik.swagger.annotations.ApiModel;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement
@ApiModel
public class ErrorRoot { public class ErrorRoot {
private String error; private String error;
......
...@@ -310,7 +310,7 @@ public class UserRestView { ...@@ -310,7 +310,7 @@ public class UserRestView {
@POST @POST
@Path("/{userid}/check-password") @Path("/{userid}/check-password")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Check user password") @ApiOperation(value = "Check user password", response = EventUserRestPojo.class)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response checkPassword(@PathParam("userid") @ApiParam("User ID") Integer userId, public Response checkPassword(@PathParam("userid") @ApiParam("User ID") Integer userId,
@FormParam("password") @ApiParam("Password") String password) { @FormParam("password") @ApiParam("Password") String password) {
...@@ -337,7 +337,7 @@ public class UserRestView { ...@@ -337,7 +337,7 @@ public class UserRestView {
@POST @POST
@Path("/{userid}/reset-password") @Path("/{userid}/reset-password")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Reset user password") @ApiOperation(value = "Reset user password", response = EventUserRestPojo.class)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response resetPassword(@PathParam("userid") @ApiParam("User ID") Integer userId, public Response resetPassword(@PathParam("userid") @ApiParam("User ID") Integer userId,
@FormParam("password") @ApiParam("New password") String password) { @FormParam("password") @ApiParam("New password") String password) {
...@@ -352,24 +352,28 @@ public class UserRestView { ...@@ -352,24 +352,28 @@ public class UserRestView {
} }
} }
/**
* Post forma parameter "image" with the image data in it.
* @param request
* @param userId
* @return
* @throws IOException
*/
@PUT @PUT
@Path("/{userId}/image") @Path("/{userid}/image")
@ApiOperation(value = "Upload image") @ApiOperation(value = "Upload image", response = EventUserRestPojo.class)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Consumes(MediaType.MULTIPART_FORM_DATA)
public Response updateUserImage(@Context HttpServletRequest request, public Response updateUserImage(@Context HttpServletRequest request,
@PathParam("userId") @ApiParam("User ID") Integer userId) throws IOException { @PathParam("userid") @ApiParam("User ID") Integer userId) throws IOException {
try { try {
Part imagePart = request.getPart("image"); Part imagePart = request.getPart("image");
EventUser eventUser = userbean.findByUserId(userId, true);
User user = userbean.getUser(userId);
EventUser eventUser = userbean.getEventUser(user, true);
UserImage userImage = userbean.uploadImage(eventUser, imagePart.getContentType(), UserImage userImage = userbean.uploadImage(eventUser, imagePart.getContentType(),
imagePart.getInputStream(), imagePart.getSubmittedFileName(), null); imagePart.getInputStream(), imagePart.getSubmittedFileName(), null);
return Response.ok(PojoUtils.initEventUserRestPojo(eventUser)).build();
return Response.ok().build();
} catch (ServletException e) { } catch (ServletException e) {
logger.error("Updating user image failed", e); logger.error("Updating user image failed", e);
return Response.serverError().build(); return Response.serverError().entity(PojoUtils.initErrorPojo("Updating user image failed")).build();
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!