-
Notifications
You must be signed in to change notification settings - Fork 0
[App] 회원가입 페이지/기능 구현 #70
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package app.db; | ||
|
|
||
| import app.model.User; | ||
| import database.ConnectionManager; | ||
| import database.CrudRepository; | ||
|
|
||
| public class UserRepository extends CrudRepository<User> { | ||
| public UserRepository(ConnectionManager connectionManager) { | ||
| super(connectionManager, User.class); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ public User(String password, String nickname, String email, String userRole) { | |
| this.userRole = userRole; | ||
| } | ||
|
|
||
| public User() { | ||
| } | ||
|
Comment on lines
+17
to
+18
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. ORM 패턴 일관성: 기본 생성자를 추가했는데, 이는 보통 ORM(Hibernate 등)의 리플렉션 기반 인스턴스화를 위해 필요합니다. 다른 엔티티도 동일하게 기본 생성자를 가지고 있는지 확인하세요. 불완전한 상태로 객체가 생성되지 않도록 접근 제어( |
||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,4 +12,11 @@ public class VariableConfig { | |
|
|
||
| public static final long IDLE_MS = 30*60*100; | ||
| public static final long ABSOLUTE_MS = 180*60*100; | ||
|
|
||
| public static final int EMAIL_MAX = 50; | ||
| public static final int EMAIL_MIN = 4; | ||
| public static final int NICKNAME_MAX = 12; | ||
| public static final int NICKNAME_MIN = 4; | ||
| public static final int PASSWORD_MAX = 16; | ||
| public static final int PASSWORD_MIN = 4; | ||
| } | ||
|
Comment on lines
+15
to
22
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. 하드코딩된 검증 값: 길이 제한이 상수로 고정되어 있습니다. 향후 변경 시 코드 수정이 필요하고, 외부 설정으로 관리되지 않습니다. 가능하면 데이터베이스나 설정 파일에서 로드하는 방식을 고려하세요. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,10 +43,10 @@ public T save(T entity) { | |
| if (Modifier.isStatic(field.getModifiers())) { | ||
| continue; | ||
| } | ||
| if ("id".equals(field.getName())) { | ||
| if ("id".equals(toColumnName(field.getName()))) { | ||
|
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. 논리 오류: 필드명 "id"를 snake_case로 변환한 결과와 비교하고 있지만, "id"는 변환해도 "id"이므로 실제로는 정상 동작합니다. 다만 명확성을 위해 변환 전 원본 필드명으로 비교하는 것이 낫습니다: |
||
| continue; | ||
| } | ||
| sqlBuilder.append(field.getName()).append(", "); | ||
| sqlBuilder.append(toColumnName(field.getName())).append(", "); | ||
| placeholder.append("?, "); | ||
| insertFields.add(field); | ||
| } | ||
|
|
@@ -128,7 +128,7 @@ public List<T> findAll() { | |
| } | ||
|
|
||
| public List<T> findByColumn(String columnName, Object value) { | ||
| String sql = "SELECT * FROM " + tableName + " WHERE " + columnName + " = ?"; | ||
| String sql = "SELECT * FROM " + tableName + " WHERE " + toColumnName(columnName) + " = ?"; | ||
|
Comment on lines
130
to
+131
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. SQL 인젝션 위험: 사용자 입력인 |
||
|
|
||
| try (Connection conn = connectionManager.getConnection(); | ||
| PreparedStatement pstmt = conn.prepareStatement(sql)) { | ||
|
|
@@ -145,7 +145,7 @@ public List<T> findByColumn(String columnName, Object value) { | |
| } | ||
|
|
||
| } catch (SQLException e) { | ||
| throw new ErrorException("엔티티 조회 중 오류 (column=" + columnName + ", value=" + value + ")", e); | ||
| throw new ErrorException("엔티티 조회 중 오류 (column=" + toColumnName(columnName) + ", value=" + value + ")", e); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -167,10 +167,10 @@ public void update(T entity) { | |
| if (Modifier.isStatic(field.getModifiers())) { | ||
| continue; | ||
| } | ||
| if ("id".equals(field.getName())) { | ||
| if ("id".equals(toColumnName(field.getName()))) { | ||
| continue; | ||
| } | ||
| sql.append(field.getName()).append(" = ?, "); | ||
| sql.append(toColumnName(field.getName())).append(" = ?, "); | ||
| updateFields.add(field); | ||
| } | ||
|
|
||
|
|
@@ -264,7 +264,7 @@ private T mapRow(ResultSet resultSet) { | |
| continue; | ||
| } | ||
|
|
||
| String columnName = field.getName(); | ||
| String columnName = toColumnName(field.getName()); | ||
| field.setAccessible(true); | ||
|
|
||
| Class<?> fieldType = field.getType(); | ||
|
|
@@ -311,4 +311,9 @@ private String toTableName(Class<?> clazz) { | |
| } | ||
| return name; | ||
| } | ||
|
|
||
| private String toColumnName(String str){ | ||
| String snake = str.replaceAll("(?<!^)([A-Z])", "_$1"); | ||
| return snake.toLowerCase(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,11 @@ public boolean support(Throwable e) { | |
| @Override | ||
| public void handle(Throwable t, Socket connection) { | ||
| ErrorException error = (ErrorException) t; | ||
| logger.debug(error.getThrowable().toString()); | ||
| logger.debug("{} - {}", error.getMessage(), error.getThrowable().toString()); | ||
| ErrorCode errorCode = error.getErrorCode(); | ||
| HttpStatus status = errorCode.getStatus(); | ||
|
|
||
|
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 body = toJson(errorCode.getCode(), error.getMessage()); | ||
| String body = toJson(errorCode.getCode(), errorCode.getMessage()); | ||
| byte[] bodyBytes = body.getBytes(StandardCharsets.UTF_8); | ||
|
|
||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
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.
중복검사 성능 문제:
findByColumn()을 각각 호출할 때마다 데이터베이스 쿼리가 2번 발생합니다. 비용이 큰 작업이므로 검사 순서를 조정하거나 길이 검증을 먼저 수행한 후 중복 검사를 하는 것이 좋습니다(유효하지 않은 데이터로 불필요한 DB 쿼리 방지).또한
findByColumn(EMAIL, email)호출 시 문자열 리터럴 "email"을 사용하는데, 이는EMAIL상수와 불일치할 위험이 있습니다. 상수 값이 실제 DB 컬럼명과 정확히 일치하는지 확인이 필요합니다.