-
Notifications
You must be signed in to change notification settings - Fork 14
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
[BE] 이근표 로그인 #4
base: main
Are you sure you want to change the base?
[BE] 이근표 로그인 #4
Conversation
1. userController 생성 2. userService 생성 3. 회원가입 로직 구현 4. 중복 id 검사 구현
1. 회원가입시 attendance 각 주차 - 날짜 별로 생성하는 로직을 구현 2. 주차에 해당하는 날짜는 enum으로 클래스 분리
1. 예외 처리시 에러가 아닌 200에 상태 코드를 추가하는 방식으로 dto 변경 2. 로그인 시 아이디와 비밀번호를 검사하는 로직 구현
1. 토큰 로그인을 위한 tokenProvider 생성 2. 예외처리 구현 3. filter 설정 완료
1. 출석체크시 올바른 요일인지 확인하는 로직 구현 2. 출석체크시 올바른 시간인지 확인하는 로직 구현
1. 사용자의 출석기록을 가져오는 로직 구현 2. 출석률을 조회하는 기능 구현
1. 날짜를 정수로 반환하는 메서드 분할 2. 날짜 유효성 검사 코드를 하나로 통합
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.
마감기한까지 완성이 더 중요하다고 생각합니다!! 전부 다 짜신거 같아서 고생하셨어용
import static leets.attendance.domain.user.presentation.UserResponseMessage.*; | ||
|
||
@RestController | ||
@EnableJpaAuditing |
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.
이부분은 메인클래스에서 JPA Auditing을 활성화 시켜줘야하는데, src/main/java/leets/attendance/AttendanceApplication.java
에 써줘야 하지 않을까요?
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
@Table |
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.
User
는 예약어로 충돌될수 있기 때문에 name = ""
을 활용해서 users라고 해주는 것이 어떨까요?
import lombok.*; | ||
import java.util.UUID; | ||
|
||
@Setter |
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.
Setter
는 보통 1.객체 일관성 유지 어려움 2.변경 의도 파악 어려움 등으로 지양하고 있는데, 안쓰신다면 지우시는게 좋을것 같아요!
public class UserResponse { | ||
private UUID userId; | ||
private String name; | ||
private String part; | ||
private String token; | ||
} |
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.
Builder 보다 생성자를 이용해서 하는것은 어떨까요?
public UserResponse(User user, String token) {
this.userId = user.getUserId();
this.name = user.getName();
this.part = user.getPart();
this.token = token;
}
throw new InvalidIdException(); | ||
} | ||
String password = loginRequest.getPassword(); | ||
User user = userRepository.findById(id).orElseThrow(Exception::new); |
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.
.orElseThrow(UserNotFoundExcepiton::new);
으로 고치시면 좀 더 확실한 에러처리가 될것 같아요!
exception에 잘 구현하신거 같은데 UserNotFoundExcepiton
추가하시면 됩니다~
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder |
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.
이 부분도 마찬가지입니다!
} | ||
|
||
@PostMapping(value = "/register") | ||
public ResponseDto<UserResponse> register(@RequestBody UserRequest userRequest) throws Exception{ |
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.
회원가입인데, token을 response에 같이 반환하는 이유가 뭘까요? 로그인이랑 회원가입과 response가 달라야 하지 않을까요?
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor |
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.
@Getter
외의 어노테이션은 꼭 필요하진 않을 것 같습니다:)
어노테이션을 붙이실 때, 확실한 이유를 가지고 왜 이 어노테이션이 사용되는지를 고려해보시면 좋을 것 같아요!
|
||
@GetMapping(value = "/check-duplicate-id") | ||
public ResponseDto<String> checkDuplicateId(@RequestBody Map<String,String> id) throws Exception{ | ||
System.out.println(id); |
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.
log.info()
로 하시면 좀더 디버깅하기 좋을 것 같아요 :)
String bearerToken = request.getHeader("Authorization"); | ||
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer")) { |
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.
const
로 빼는 것이 좋을 것 같아요:)
요구사항 구현
✅ POST /users/register - 회원가입
✅ POST /users/login - 로그인
✅ GET /users/check-duplicate-id - id 중복 확인
✅ PATCH /attendances - 출석( 결석 )
✅ GET /attendances - 출석 정보 모두 조회
✅ GET /attendances/rates - 출석률 조회
☁️ 회고
이 부분을 계산하는 것 보다 enum으로 관리하는게 용이할 것이라 판단해서 따로 dateEnum 클래스를 만들어 관리하도록 하였습니다 과연 옳은 방향일지 모르겠습니다.