-
Notifications
You must be signed in to change notification settings - Fork 1
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
[com8599-issue6] user 회원가입 기능 #22
base: com8599
Are you sure you want to change the base?
Changes from all commits
9a6f361
91cddf0
94ef3b8
c04e473
1f7101b
d2a8e48
892214a
c932065
803a1b8
d96caed
071157e
a19bb8b
7ee0063
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package com.study.realworld; | ||
|
||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import java.util.Arrays; | ||
Comment on lines
+3
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 피드백감사합니다 다음 커밋부터 유의하여 커밋하겠습니다!! |
||
|
||
@SpringBootApplication | ||
public class RealworldApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(RealworldApplication.class, args); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.study.realworld.common; | ||
|
||
public enum ErrorCode { | ||
EXCEPTION(-1, "통신중 에러가 발생했습니다."), | ||
NONE(0, "이상없음"), | ||
INVALID_REQUEST(1, "잘못된 요청입니다."), | ||
DB(2, "데이터 베이스 오류입니다."), | ||
SAME_NICKNAME(3, "동일 닉네임유저가 존재합니다."), | ||
SAME_EMAIL(4, "동일 이메일유저가 존재합니다."), | ||
|
||
NOT_FOUND_SESSION_USER(10000, "유저 정보를 찾을 수 없습니다."), | ||
|
||
SQLEXCEPTION(-2, "서버와 통신중 에러가 발생했습니다."), | ||
; | ||
Comment on lines
+4
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ENUM 명을 |
||
|
||
private int code; | ||
private String desc; | ||
|
||
ErrorCode(int code, String desc) { | ||
this.code = code; | ||
this.desc = desc; | ||
} | ||
|
||
public int getCode() { | ||
return code; | ||
} | ||
|
||
public String getDesc() { | ||
return desc; | ||
} | ||
|
||
public static ErrorCode parse(int code) { | ||
for (ErrorCode e : ErrorCode.values()) { | ||
if (code == e.getCode()) { | ||
return e; | ||
} | ||
} | ||
return INVALID_REQUEST; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.study.realworld.common; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
|
||
public class JsonFunc { | ||
public static String getErrorJson(ErrorCode errorCode, Object... objects) { | ||
JsonObject json = new JsonObject(); | ||
|
||
json.addProperty("E", String.valueOf(errorCode.getCode())); | ||
|
||
if (objects == null || objects.length == 0) { | ||
return json.toString(); | ||
} | ||
|
||
for (int i = 0; i < objects.length; i = i + 2) { | ||
json.addProperty(String.valueOf(objects[i]), String.valueOf(objects[i + 1])); | ||
} | ||
System.out.println(errorCode.name() + " - " + errorCode.getCode() + " - " + errorCode.getDesc()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logging이 더 좋을 것 같네요. |
||
|
||
return json.toString(); | ||
} | ||
|
||
public static String getResultJson(Object result) throws JsonProcessingException { | ||
JsonObject json = new JsonObject(); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
json.add("R", new JsonParser().parse(objectMapper.writeValueAsString(result))); | ||
|
||
return json.toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.study.realworld.controller; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.study.realworld.common.ErrorCode; | ||
import com.study.realworld.common.JsonFunc; | ||
import com.study.realworld.domain.User; | ||
import com.study.realworld.service.UserService; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
public class UserController { | ||
UserService userService; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 접근 제어자는 어디에...? |
||
|
||
public UserController(UserService userService) { | ||
this.userService = userService; | ||
} | ||
Comment on lines
+19
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 방식으로 생성자 주입 하셨다면 위의 |
||
|
||
@ApiOperation(value = "사용자 등록", notes = "사용자 등록") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 동일한 내용을 표현하고 있는데, value와 notes를 구분하신 이유는 무엇인가요? |
||
@PostMapping("/users") //post 등록 api | ||
public String users(@JsonProperty("user") User user) throws JsonProcessingException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Input Parameter로 User를 직접 사용하기 보다는, |
||
Object result = userService.users(user); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수의 타입에 Object를 사용하는 방식은 좋지 않아 보입니다 ㅜㅜ |
||
if (result instanceof ErrorCode) { | ||
return JsonFunc.getErrorJson((ErrorCode) result); | ||
} | ||
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 방식으로 에러를 넘기는 것보다는 throw exception을 처리하도록 하시는게 좋아보여요. |
||
return JsonFunc.getResultJson(user); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반환 타입으로 String을 사용하시기 보다는 ResponseEntity를 사용하시는 것이 좋아보입니다. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.study.realworld.dao; | ||
|
||
import org.springframework.jdbc.core.PreparedStatementSetter; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
|
||
public class PSSetDao { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public static class PSSForInts implements PreparedStatementSetter { | ||
private Integer[] value; | ||
|
||
public PSSForInts(Integer... value) { | ||
this.value = value; | ||
} | ||
|
||
public void setValues(PreparedStatement ps) throws SQLException { | ||
|
||
for (int i = 0; i < value.length; i++) { | ||
ps.setInt((i + 1), this.value[i]); | ||
} | ||
} | ||
} | ||
|
||
public static class PSSForStrings implements PreparedStatementSetter { | ||
private String[] value; | ||
|
||
public PSSForStrings(String... value) { | ||
this.value = value; | ||
} | ||
|
||
public void setValues(PreparedStatement ps) throws SQLException { | ||
|
||
for (int i = 0; i < value.length; i++) { | ||
ps.setString((i + 1), this.value[i]); | ||
} | ||
} | ||
} | ||
|
||
public static class PSSForIntsStrings implements PreparedStatementSetter { | ||
int intCount; | ||
int stringCount; | ||
Object[] objects; | ||
|
||
public PSSForIntsStrings(int intCount, int stringCount, Object... objects) { | ||
this.intCount = intCount; | ||
this.stringCount = stringCount; | ||
this.objects = objects; | ||
} | ||
|
||
public void setValues(PreparedStatement ps) throws SQLException { | ||
int pos = 1; | ||
|
||
for (int i = 0; i < intCount; i++) ps.setInt(pos++, (Integer) objects[i]); | ||
for (int i = 0; i < stringCount; i++) ps.setString(pos++, (String) objects[i + intCount]); | ||
} | ||
} | ||
|
||
public static class PSSForStringsInts implements PreparedStatementSetter { | ||
int stringCount; | ||
int intCount; | ||
Object[] objects; | ||
|
||
public PSSForStringsInts(int stringCount, int intCount, Object... objects) { | ||
this.stringCount = stringCount; | ||
this.intCount = intCount; | ||
this.objects = objects; | ||
} | ||
|
||
public void setValues(PreparedStatement ps) throws SQLException { | ||
int pos = 1; | ||
|
||
for (int i = 0; i < stringCount; i++) ps.setString(pos++, (String) objects[i]); | ||
for (int i = 0; i < intCount; i++) ps.setInt(pos++, (Integer) objects[i + stringCount]); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자바 객체와 xml을 직렬화/역직렬화 하는 부분이 어디인가요?