Skip to content

Commit

Permalink
[#1933] refactoring controller parameter type (#1934)
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoo-jung committed Jul 25, 2016
1 parent 6844e96 commit b38ed8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -37,7 +38,6 @@
import com.navercorp.pinpoint.web.vo.UserGroup;
import com.navercorp.pinpoint.web.vo.UserGroupMember;
import com.navercorp.pinpoint.web.vo.UserGroupMemberParam;
import com.navercorp.pinpoint.web.vo.UserGroupParam;

/**
* @author minwoo.jung
Expand All @@ -48,6 +48,7 @@ public class UserGroupController {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

private static final String SSO_USER = "SSO_USER";
public static final String USER_GROUP_ID = "userGroupId";
public static final String USER_ID = "userId";

Expand All @@ -62,7 +63,7 @@ public class UserGroupController {

@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public Map<String, String> createUserGroup(@RequestBody UserGroupParam userGroup) {
public Map<String, String> createUserGroup(@RequestBody UserGroup userGroup, @RequestHeader(value=SSO_USER, required=false) String userId) {
if (StringUtils.isEmpty(userGroup.getId())) {
Map<String, String> result = new HashMap<>();
result.put("errorCode", "500");
Expand All @@ -73,7 +74,7 @@ public Map<String, String> createUserGroup(@RequestBody UserGroupParam userGroup
String userGroupNumber = userGroupService.createUserGroup(userGroup);

if (webProperties.isOpenSource() == false) {
if (initUserGroup(userGroup) == false) {
if (initUserGroup(userGroup, userId) == false) {
Map<String, String> result = new HashMap<>();
result.put("errorCode", "500");
result.put("errorMessage", "There is not userId or fail to create userGroup.");
Expand All @@ -85,27 +86,27 @@ public Map<String, String> createUserGroup(@RequestBody UserGroupParam userGroup
return result;
}

private boolean initUserGroup(UserGroupParam userGroup) {
if (StringUtils.isEmpty(userGroup.getUserId())) {
private boolean initUserGroup(UserGroup userGroup, String userId) {
if (StringUtils.isEmpty(userId)) {
userGroupService.deleteUserGroup(userGroup);
return false;
}

userGroupService.insertMember(new UserGroupMember(userGroup.getId(), userGroup.getUserId()));
userGroupService.insertMember(new UserGroupMember(userGroup.getId(), userId));
return true;
}

@RequestMapping(method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> deleteUserGroup(@RequestBody UserGroupParam userGroup) {
public Map<String, String> deleteUserGroup(@RequestBody UserGroup userGroup, @RequestHeader(value=SSO_USER, required=false) String userId) {
if (StringUtils.isEmpty(userGroup.getId())) {
Map<String, String> result = new HashMap<>();
result.put("errorCode", "500");
result.put("errorMessage", "there is id of userGroup in params to delete user group");
return result;
}
if (webProperties.isOpenSource() == false) {
if (checkValid(userGroup.getUserId(), userGroup.getId()) == false) {
if (checkValid(userId, userGroup.getId()) == false) {
Map<String, String> result = new HashMap<>();
result.put("errorCode", "500");
result.put("errorMessage", "There is not userId or you don't have authoriy for user group.");
Expand Down

This file was deleted.

0 comments on commit b38ed8e

Please sign in to comment.