Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor HashMap for HttpResponse to Response object #8806

Closed
emeroad opened this issue Apr 25, 2022 · 0 comments · Fixed by #8808
Closed

Refactor HashMap for HttpResponse to Response object #8806

emeroad opened this issue Apr 25, 2022 · 0 comments · Fixed by #8808

Comments

@emeroad
Copy link
Member

emeroad commented Apr 25, 2022

Removes redundant hashmap declarations and replaces them with Response.
Fix to handle http status code correctly when an error occurs.

Before

public Map<String, String> insertRole(@RequestBody RoleInformation roleInformation) {
        if (AdditionValueValidator.validateRoleId(roleInformation.getRoleId()) == false) {
            Map<String, String> result = new HashMap<>();
            result.put("errorCode", "500");
            result.put("errorMessage", "roleId pattern is invalid");
            return result;
        }

        roleService.insertRoleInformation(roleInformation);

        Map<String, String> result = new HashMap<>();
        result.put("result", "SUCCESS");
        return result;
    }

After

    public ResponseEntity<Response> insertRole(@RequestBody RoleInformation roleInformation) {
        if (AdditionValueValidator.validateRoleId(roleInformation.getRoleId()) == false) {
            return ErrorResponse.badRequest("roleId pattern is invalid");
        }

        roleService.insertRoleInformation(roleInformation);

        return SuccessResponse.ok();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant