Java tutorial
/* * Copyright (c) 2016 Prasenjit Purohit * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.prasenjit.auth.controller; import net.prasenjit.auth.domain.User; import net.prasenjit.auth.model.UserModifyRequest; import net.prasenjit.auth.model.UserRegistrationRequest; import net.prasenjit.auth.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; @RestController /** * <p>UserController class.</p> * * @author PRASEN * @version $Id: $Id */ @RequestMapping(value = "/api/user") public class UserController { @Autowired private UserService userservice; /** * <p>registerUser.</p> * * @param userdata a {@link net.prasenjit.auth.model.UserRegistrationRequest} object. */ @RequestMapping(method = RequestMethod.PUT) @ResponseStatus(HttpStatus.CREATED) public void registerUser(@Validated @RequestBody UserRegistrationRequest userdata) { userservice.registerUser(userdata); } /** * <p>manageUser.</p> * * @param userName a {@link java.lang.String} object. * @param userModifyRequest a {@link net.prasenjit.auth.model.UserModifyRequest} object. */ @RequestMapping(value = "/{userName}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.ACCEPTED) public void manageUser(@PathVariable("userName") String userName, @Validated @RequestBody UserModifyRequest userModifyRequest) { switch (userModifyRequest.getOperation()) { case UNLOCK: userservice.unLockuser(userName); break; case LOCK: userservice.lockUser(userName); break; case DISABLE: userservice.disableUser(userName); break; case ENABLE: userservice.enableUser(userName); break; } } /** * <p>findAllUsers.</p> * * @return a {@link java.util.List} object. */ @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List<User> findAllUsers() { return userservice.getAllUser(); } }