Skip to content

Commit

Permalink
Merge pull request #86 from Likelion-YeungNam-Univ/feature-user
Browse files Browse the repository at this point in the history
feat: User Entity 자가 진단 테스트 유무 필드 추가 및 관련 API 구현
  • Loading branch information
Jsplix authored Aug 1, 2024
2 parents 2564af8 + 3515f55 commit 50de8a7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,9 @@ public interface UserApi {
})),
})
ResponseEntity<UserInfoResponseDto> exchange(HttpServletRequest request, @RequestBody UserExchangeRequestDto userExchangeRequestDto);

@PatchMapping("/self-test")
@Operation(summary = "유저 자가 테스트 완료 처리", description = "로그인 한 사용자의 자가 진단 테스트 유무를 완료 처리하는 API 입니다.")
@ApiResponse(responseCode = "200", description = "자가 진단 테스트 완료")
ResponseEntity<UserInfoResponseDto> completeSelfTest(HttpServletRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public ResponseEntity<UserInfoResponseDto> exchange(HttpServletRequest request,
);
}

public ResponseEntity<UserInfoResponseDto> completeSelfTest(HttpServletRequest request) {
String accessToken = jwtProvider.getToken(request);
String userId = jwtProvider.getUserId(accessToken);

return ResponseEntity.ok().body(
UserInfoResponseDto.fromEntity(userService.completeSelfTest(Long.parseLong(userId)))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public record UserInfoResponseDto(
@Schema(description = "소셜 ID", example = "1234567890")
Long socialId,
@Schema(description = "짝꿍 닉네임", example = "mateNickname")
String mateNickname
String mateNickname,
@Schema(description = "자가 진단 테스트 유무", example = "true")
boolean isSelfTested
) {
public static UserInfoResponseDto fromEntity(User user) {
return new UserInfoResponseDto(
Expand All @@ -39,7 +41,8 @@ public static UserInfoResponseDto fromEntity(User user) {
user.getSocialId(),
Optional.ofNullable(user.getMate())
.map(User::getNickname)
.orElse(null)
.orElse(null),
user.getIsSelfTested()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class User extends BaseTimeEntity implements UserDetails {
@Column(nullable = false)
private Boolean isChanged;

@Column(nullable = false)
private Boolean isSelfTested;

@OneToOne
private User mate;

Expand All @@ -79,6 +82,7 @@ public User(String email, String password, String nickname, String profileImgUrl
this.point = 0;
this.socialId = socialId;
this.isChanged = false;
this.isSelfTested = false;
}

public static User of(OAuthUserInfoDto dto, SignInRequestDto request) {
Expand Down Expand Up @@ -152,4 +156,8 @@ public void setIsChanged(boolean state) {
this.isChanged = state;
}

public void setIsSelfTested(boolean isSelfTested) {
this.isSelfTested = isSelfTested;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ public User exchange(Long userId, UserExchangeRequestDto userExchangeRequestDto)

return user;
}

@Transactional
public User completeSelfTest(Long userId) {
User user = read(userId);
user.setIsSelfTested(true);

return user;
}
}

0 comments on commit 50de8a7

Please sign in to comment.