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

[FEAT] Spring security 관련 커스텀 어노테이션 생성 및 적용 #257

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.genius.gitget.challenge.participant.service.ParticipantService;
import com.genius.gitget.challenge.user.domain.User;
import com.genius.gitget.challenge.user.service.UserService;
import com.genius.gitget.global.security.domain.UserPrincipal;
import com.genius.gitget.global.util.annotation.GitGetUser;
import com.genius.gitget.global.util.response.dto.SingleResponse;
import com.genius.gitget.global.util.response.dto.SlicingResponse;
import java.time.LocalDate;
Expand All @@ -28,7 +28,6 @@
import org.springframework.data.domain.Slice;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -61,11 +60,11 @@ public ResponseEntity<SingleResponse<InstancePreviewResponse>> getInstanceInform

@PostMapping("/today")
public ResponseEntity<SingleResponse<CertificationResponse>> certificateByGithub(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@RequestBody CertificationRequest certificationRequest
) {
CertificationResponse certificationResponse = certificationFacade.updateCertification(
userPrincipal.getUser(), certificationRequest);
user, certificationRequest);

return ResponseEntity.ok().body(
new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), certificationResponse)
Expand All @@ -74,10 +73,9 @@ public ResponseEntity<SingleResponse<CertificationResponse>> certificateByGithub

@PostMapping("/pass")
public ResponseEntity<SingleResponse<ActivatedResponse>> passCertification(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@RequestBody CertificationRequest certificationRequest
) {
User user = userPrincipal.getUser();
ActivatedResponse activatedResponse = certificationFacade.passCertification(
user.getId(), certificationRequest);

Expand All @@ -88,11 +86,11 @@ public ResponseEntity<SingleResponse<ActivatedResponse>> passCertification(

@GetMapping("/week/{instanceId}")
public ResponseEntity<SingleResponse<WeekResponse>> getWeekCertification(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@PathVariable Long instanceId
) {
LocalDate kstDate = DateUtil.convertToKST(LocalDateTime.now());
Participant participant = participantService.findByJoinInfo(userPrincipal.getUser().getId(), instanceId);
Participant participant = participantService.findByJoinInfo(user.getId(), instanceId);
WeekResponse weekResponse = certificationFacade.getMyWeekCertifications(participant.getId(), kstDate);

return ResponseEntity.ok().body(
Expand All @@ -102,12 +100,11 @@ public ResponseEntity<SingleResponse<WeekResponse>> getWeekCertification(

@GetMapping("/week/all/{instanceId}")
public ResponseEntity<SlicingResponse<WeekResponse>> getAllUserWeekCertification(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@PathVariable Long instanceId,
@PageableDefault Pageable pageable
) {
LocalDate kstDate = DateUtil.convertToKST(LocalDateTime.now());
User user = userPrincipal.getUser();
Slice<WeekResponse> certifications = certificationFacade.getOthersWeekCertifications(
user.getId(), instanceId, kstDate, pageable);

Expand All @@ -134,15 +131,13 @@ public ResponseEntity<SingleResponse<TotalResponse>> getTotalCertifications(

@GetMapping("/information/{instanceId}")
public ResponseEntity<SingleResponse<CertificationInformation>> getCertificationInformation(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@PathVariable Long instanceId
) {

LocalDate kstDate = DateUtil.convertToKST(LocalDateTime.now());
Instance instance = instanceService.findInstanceById(instanceId);
Participant participant = participantService.findByJoinInfo(
userPrincipal.getUser().getId(),
instanceId);
Participant participant = participantService.findByJoinInfo(user.getId(), instanceId);

CertificationInformation certificationInformation = certificationFacade.getCertificationInformation(
instance, participant, kstDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import com.genius.gitget.challenge.certification.dto.github.PullRequestResponse;
import com.genius.gitget.challenge.certification.facade.GithubFacade;
import com.genius.gitget.challenge.certification.util.DateUtil;
import com.genius.gitget.global.security.domain.UserPrincipal;
import com.genius.gitget.challenge.user.domain.User;
import com.genius.gitget.global.util.annotation.GitGetUser;
import com.genius.gitget.global.util.response.dto.CommonResponse;
import com.genius.gitget.global.util.response.dto.ListResponse;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -31,10 +31,10 @@ public class GithubController {

@PostMapping("/register/token")
public ResponseEntity<CommonResponse> registerGithubToken(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@RequestBody GithubTokenRequest githubTokenRequest
) {
githubFacade.registerGithubPersonalToken(userPrincipal.getUser(), githubTokenRequest.githubToken());
githubFacade.registerGithubPersonalToken(user, githubTokenRequest.githubToken());

return ResponseEntity.ok().body(
new CommonResponse(SUCCESS.getStatus(), SUCCESS.getMessage())
Expand All @@ -43,9 +43,9 @@ public ResponseEntity<CommonResponse> registerGithubToken(

@GetMapping("/repositories")
public ResponseEntity<ListResponse<String>> getPublicRepositories(
@AuthenticationPrincipal UserPrincipal userPrincipal
@GitGetUser User user
) {
List<String> repositories = githubFacade.getPublicRepositories(userPrincipal.getUser());
List<String> repositories = githubFacade.getPublicRepositories(user);

return ResponseEntity.ok().body(
new ListResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), repositories)
Expand All @@ -54,9 +54,9 @@ public ResponseEntity<ListResponse<String>> getPublicRepositories(

@GetMapping("/verify/token")
public ResponseEntity<CommonResponse> verifyGithubToken(
@AuthenticationPrincipal UserPrincipal userPrincipal
@GitGetUser User user
) {
githubFacade.verifyGithubToken(userPrincipal.getUser());
githubFacade.verifyGithubToken(user);

return ResponseEntity.ok().body(
new CommonResponse(SUCCESS.getStatus(), SUCCESS.getMessage())
Expand All @@ -65,11 +65,11 @@ public ResponseEntity<CommonResponse> verifyGithubToken(

@GetMapping("/verify/repository")
public ResponseEntity<CommonResponse> verifyRepository(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@RequestParam String repo
) {

githubFacade.verifyRepository(userPrincipal.getUser(), repo);
githubFacade.verifyRepository(user, repo);

return ResponseEntity.ok().body(
new CommonResponse(SUCCESS.getStatus(), SUCCESS.getMessage())
Expand All @@ -78,12 +78,12 @@ public ResponseEntity<CommonResponse> verifyRepository(

@GetMapping("/verify/pull-request")
public ResponseEntity<ListResponse<PullRequestResponse>> verifyPullRequest(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@RequestParam String repo
) {

List<PullRequestResponse> pullRequestResponses = githubFacade.verifyPullRequest(
userPrincipal.getUser(), repo, DateUtil.convertToKST(LocalDateTime.now())
user, repo, DateUtil.convertToKST(LocalDateTime.now())
);

return ResponseEntity.ok().body(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import com.genius.gitget.challenge.instance.dto.detail.JoinRequest;
import com.genius.gitget.challenge.instance.dto.detail.JoinResponse;
import com.genius.gitget.challenge.instance.service.InstanceDetailFacade;
import com.genius.gitget.global.security.domain.UserPrincipal;
import com.genius.gitget.challenge.user.domain.User;
import com.genius.gitget.global.util.annotation.GitGetUser;
import com.genius.gitget.global.util.response.dto.SingleResponse;
import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -35,11 +35,11 @@ public class InstanceDetailController {

@GetMapping("/{instanceId}")
public ResponseEntity<SingleResponse<InstanceResponse>> getInstanceDetail(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@PathVariable Long instanceId
) {
InstanceResponse instanceDetailInformation = instanceDetailFacade.getInstanceDetailInformation(
userPrincipal.getUser(), instanceId);
user, instanceId);

return ResponseEntity.ok().body(
new SingleResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), instanceDetailInformation)
Expand All @@ -48,7 +48,7 @@ public ResponseEntity<SingleResponse<InstanceResponse>> getInstanceDetail(

@PostMapping("/{instanceId}")
public ResponseEntity<SingleResponse<JoinResponse>> joinChallenge(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@PathVariable Long instanceId,
@RequestParam String repo
) {
Expand All @@ -58,7 +58,7 @@ public ResponseEntity<SingleResponse<JoinResponse>> joinChallenge(
.repository(repo)
.todayDate(kstDate)
.build();
JoinResponse joinResponse = instanceDetailFacade.joinNewChallenge(userPrincipal.getUser(), joinRequest);
JoinResponse joinResponse = instanceDetailFacade.joinNewChallenge(user, joinRequest);

return ResponseEntity.ok().body(
new SingleResponse<>(JOIN_SUCCESS.getStatus(), JOIN_SUCCESS.getMessage(), joinResponse)
Expand All @@ -67,10 +67,10 @@ public ResponseEntity<SingleResponse<JoinResponse>> joinChallenge(

@DeleteMapping("/{instanceId}")
public ResponseEntity<SingleResponse<JoinResponse>> quitChallenge(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@PathVariable Long instanceId
) {
JoinResponse joinResponse = instanceDetailFacade.quitChallenge(userPrincipal.getUser(), instanceId);
JoinResponse joinResponse = instanceDetailFacade.quitChallenge(user, instanceId);

return ResponseEntity.ok().body(
new SingleResponse<>(QUIT_SUCCESS.getStatus(), QUIT_SUCCESS.getMessage(), joinResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import com.genius.gitget.challenge.instance.dto.search.InstanceSearchRequest;
import com.genius.gitget.challenge.instance.dto.search.InstanceSearchResponse;
import com.genius.gitget.challenge.instance.facade.InstanceHomeFacade;
import com.genius.gitget.global.security.domain.UserPrincipal;
import com.genius.gitget.challenge.user.domain.User;
import com.genius.gitget.global.util.annotation.GitGetUser;
import com.genius.gitget.global.util.exception.SuccessCode;
import com.genius.gitget.global.util.response.dto.PagingResponse;
import com.genius.gitget.global.util.response.dto.SlicingResponse;
Expand All @@ -18,7 +19,6 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -46,13 +46,13 @@ public ResponseEntity<PagingResponse<InstanceSearchResponse>> searchInstances(
@GetMapping("/recommend")
public ResponseEntity<SlicingResponse<HomeInstanceResponse>> getRecommendInstances(
Pageable pageable,
@AuthenticationPrincipal UserPrincipal userPrincipal) {
@GitGetUser User user) {

PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(),
Sort.by(Direction.DESC, "participantCount"));

Slice<HomeInstanceResponse> recommendations = instanceHomeFacade.recommendInstances(
userPrincipal.getUser(), pageRequest);
user, pageRequest);
return ResponseEntity.ok().body(
new SlicingResponse<>(SUCCESS.getStatus(), SUCCESS.getMessage(), recommendations)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.genius.gitget.challenge.likes.dto.UserLikesAddResponse;
import com.genius.gitget.challenge.likes.dto.UserLikesResponse;
import com.genius.gitget.challenge.likes.facade.LikesFacade;
import com.genius.gitget.global.security.domain.UserPrincipal;
import com.genius.gitget.challenge.user.domain.User;
import com.genius.gitget.global.util.annotation.GitGetUser;
import com.genius.gitget.global.util.exception.SuccessCode;
import com.genius.gitget.global.util.response.dto.CommonResponse;
import com.genius.gitget.global.util.response.dto.PagingResponse;
Expand All @@ -15,7 +16,6 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -35,10 +35,10 @@ public class LikesController {
@GetMapping("/likes")
public ResponseEntity<PagingResponse<UserLikesResponse>> getLikesListOfUser(
Pageable pageable,
@AuthenticationPrincipal UserPrincipal userPrincipal) {
@GitGetUser User user) {

PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize());
Page<UserLikesResponse> likesResponses = likesFacade.getLikesList(userPrincipal.getUser(), pageRequest);
Page<UserLikesResponse> likesResponses = likesFacade.getLikesList(user, pageRequest);

return ResponseEntity.ok().body(
new PagingResponse<>(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage(), likesResponses)
Expand All @@ -48,9 +48,9 @@ public ResponseEntity<PagingResponse<UserLikesResponse>> getLikesListOfUser(
// 좋아요 목록 추가
@PostMapping("/likes")
public ResponseEntity<SingleResponse<UserLikesAddResponse>> addLikes(
@AuthenticationPrincipal UserPrincipal userPrincipal,
@GitGetUser User user,
@RequestBody UserLikesAddRequest userLikesAddRequest) {
UserLikesAddResponse userLikesAddResponse = likesFacade.addLikes(userPrincipal.getUser(),
UserLikesAddResponse userLikesAddResponse = likesFacade.addLikes(user,
userLikesAddRequest.getIdentifier(),
userLikesAddRequest.getInstanceId());
return ResponseEntity.ok().body(
Expand All @@ -61,9 +61,9 @@ public ResponseEntity<SingleResponse<UserLikesAddResponse>> addLikes(

// 좋아요 목록 삭제
@DeleteMapping("/likes/{likesId}")
public ResponseEntity<CommonResponse> deleteLikes(@AuthenticationPrincipal UserPrincipal userPrincipal,
public ResponseEntity<CommonResponse> deleteLikes(@GitGetUser User user,
@PathVariable(value = "likesId") Long likesId) {
likesFacade.deleteLikes(userPrincipal.getUser(), likesId);
likesFacade.deleteLikes(user, likesId);
return ResponseEntity.ok().body(
new CommonResponse(SuccessCode.SUCCESS.getStatus(), SuccessCode.SUCCESS.getMessage())
);
Expand Down
Loading