|
| 1 | +package org.jsondoc.sample.controller; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.jsondoc.core.annotation.Api; |
| 7 | +import org.jsondoc.core.annotation.ApiError; |
| 8 | +import org.jsondoc.core.annotation.ApiErrors; |
| 9 | +import org.jsondoc.core.annotation.ApiMethod; |
| 10 | +import org.jsondoc.core.annotation.ApiParam; |
| 11 | +import org.jsondoc.core.annotation.ApiResponseObject; |
| 12 | +import org.jsondoc.core.pojo.ApiVerb; |
| 13 | +import org.jsondoc.sample.pojo.User; |
| 14 | +import org.springframework.http.MediaType; |
| 15 | +import org.springframework.stereotype.Controller; |
| 16 | +import org.springframework.web.bind.annotation.PathVariable; |
| 17 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 18 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 19 | +import org.springframework.web.bind.annotation.ResponseBody; |
| 20 | + |
| 21 | +@Api(name = "User Services", description = "Methods for managing users") |
| 22 | +@Controller |
| 23 | +@RequestMapping(value = "/users") |
| 24 | +public class UserController { |
| 25 | + |
| 26 | + @ApiMethod(path = "/users/{id}", verb = ApiVerb.GET, description = "Gets a user with the given ID", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE }) |
| 27 | + @ApiErrors(apierrors = { @ApiError(code = "3000", description = "User not found"), @ApiError(code = "9000", description = "Illegal argument") }) |
| 28 | + @RequestMapping(value = "/{id}", method = RequestMethod.GET) |
| 29 | + public @ResponseBody @ApiResponseObject |
| 30 | + User user(@PathVariable @ApiParam(name = "id", description = "The user's ID", required = true) Integer id) { |
| 31 | + return new User(id, "jsondoc-user", 30, "M"); |
| 32 | + } |
| 33 | + |
| 34 | + @ApiMethod(path = "/users/{gender}/{age}", verb = ApiVerb.GET, description = "Gets users with the given gender and age", produces = { MediaType.APPLICATION_JSON_VALUE }) |
| 35 | + @ApiErrors(apierrors = { @ApiError(code = "3000", description = "User not found"), @ApiError(code = "9000", description = "Illegal argument") }) |
| 36 | + @RequestMapping(value = "/{gender}/{age}", method = RequestMethod.GET) |
| 37 | + public @ResponseBody @ApiResponseObject |
| 38 | + List<User> userAge(@PathVariable @ApiParam(name = "gender", description = "The user's gender", required = true) String gender, @PathVariable @ApiParam(name = "age", description = "The user's required age", required = true) Integer age) { |
| 39 | + List<User> users = new ArrayList<User>(); |
| 40 | + users.add(new User(1, "jsondoc-user-1", age, gender)); |
| 41 | + users.add(new User(2, "jsondoc-user-2", age, gender)); |
| 42 | + return users; |
| 43 | + } |
| 44 | + |
| 45 | +} |
0 commit comments