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

[BE] 이근표 로그인 #4

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

rootTiket
Copy link
Member

@rootTiket rootTiket commented May 15, 2024

요구사항 구현

✅ POST /users/register - 회원가입

    • 중복 ID 등록시 예외를 던지도록 구현

스크린샷 2024-05-16 오전 12 00 14

스크린샷 2024-05-16 오전 12 00 24

✅ POST /users/login - 로그인

    • 아이디 , 비밀번호를 틀릴경우 각각 예외를 날림
    • 로그인 성공시 토큰 발급하도록 구현

스크린샷 2024-05-16 오전 12 00 59

스크린샷 2024-05-16 오전 12 01 19

스크린샷 2024-05-16 오전 12 01 39

✅ GET /users/check-duplicate-id - id 중복 확인

스크린샷 2024-05-16 오전 12 02 07

✅ PATCH /attendances - 출석( 결석 )

    • 출석 요청시 현재 시간을 기준으로 날짜(목요일인가?) , 활동시간을 기준으로 해당되지 않을경우 예외를 발생하는 로직 구현

스크린샷 2024-05-16 오전 12 06 02

✅ GET /attendances - 출석 정보 모두 조회

{
    "code": 200,
    "message": "목록조회에 성공하였습니다",
    "data": {
        "name": "리츠미션",
        "date": "2024-05-16",
        "attendanceList": [
            {
                "week": 1,
                "attend": true
            },
            {
                "week": 2,
                "attend": true
            },
            {
                "week": 3,
                "attend": true
            },
            {
                "week": 4,
                "attend": true
            },
            {
                "week": 5,
                "attend": true
            },
            {
                "week": 6,
                "attend": false
            },
            {
                "week": 7,
                "attend": false
            },
            {
                "week": 8,
                "attend": false
            }
        ]
    }
} 

✅ GET /attendances/rates - 출석률 조회

스크린샷 2024-05-16 오전 12 15 39

☁️ 회고

  1. 요구사항에 나와있는대로 1~8주차 리스트를 반환하기 위해 회원가입시 출석리스트를 8주차 까지 생성하는 방식으로 로직을 구상하였습니다. 그런데 중간에 한 주씩 빠지는 주가 있어 해당 주는 활동주차가 아니므로 제외 해야합니다.
    이 부분을 계산하는 것 보다 enum으로 관리하는게 용이할 것이라 판단해서 따로 dateEnum 클래스를 만들어 관리하도록 하였습니다 과연 옳은 방향일지 모르겠습니다.

rootTiket added 12 commits May 10, 2024 00:23
1. userController 생성
2. userService 생성
3. 회원가입 로직 구현
4. 중복 id 검사 구현
1. 회원가입시 attendance 각 주차 - 날짜 별로 생성하는 로직을 구현
2. 주차에 해당하는 날짜는 enum으로 클래스 분리
1. 예외 처리시 에러가 아닌 200에 상태 코드를 추가하는 방식으로 dto 변경
2. 로그인 시 아이디와 비밀번호를 검사하는 로직 구현
1. 토큰 로그인을 위한 tokenProvider 생성
2. 예외처리 구현
3. filter 설정 완료
1. 출석체크시 올바른 요일인지 확인하는 로직 구현
2. 출석체크시 올바른 시간인지 확인하는 로직 구현
1. 사용자의 출석기록을 가져오는 로직 구현
2. 출석률을 조회하는 기능 구현
@rootTiket rootTiket self-assigned this May 15, 2024
rootTiket added 2 commits May 16, 2024 14:32
1. 날짜를 정수로 반환하는 메서드 분할
2. 날짜 유효성 검사 코드를 하나로 통합
Copy link
Member

@jiixon jiixon left a 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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setter는 보통 1.객체 일관성 유지 어려움 2.변경 의도 파악 어려움 등으로 지양하고 있는데, 안쓰신다면 지우시는게 좋을것 같아요!

Comment on lines +14 to +19
public class UserResponse {
private UUID userId;
private String name;
private String part;
private String token;
}
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

회원가입인데, token을 response에 같이 반환하는 이유가 뭘까요? 로그인이랑 회원가입과 response가 달라야 하지 않을까요?

Comment on lines +10 to +13
@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.info()로 하시면 좀더 디버깅하기 좋을 것 같아요 :)

Comment on lines +31 to +32
String bearerToken = request.getHeader("Authorization");
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const로 빼는 것이 좋을 것 같아요:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants