Skip to content

Commit

Permalink
Merge pull request #226 from BudgetBuddiesTeam/refactor/#223
Browse files Browse the repository at this point in the history
[refactor] userId -> ArumentResolver로 변경
  • Loading branch information
wnd01jun authored Nov 29, 2024
2 parents 64c696c + 2e3fd21 commit 5bf8666
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto;
import com.bbteam.budgetbuddies.domain.comment.service.CommentService;
import com.bbteam.budgetbuddies.domain.comment.validation.ExistComment;
import com.bbteam.budgetbuddies.domain.user.validation.ExistUser;
import com.bbteam.budgetbuddies.domain.user.dto.UserDto;
import com.bbteam.budgetbuddies.global.security.utils.AuthUser;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -36,9 +37,9 @@ public CommentController(CommentService<CommentRequestDto.DiscountInfoCommentReq

@PostMapping("/discounts/comments")
public ApiResponse<CommentResponseDto.DiscountInfoCommentResponseDto> saveDiscountInfoComment(
@RequestParam("userId") @ExistUser Long userId,
@AuthUser UserDto.AuthUserDto userDto,
@RequestBody CommentRequestDto.DiscountInfoCommentRequestDto discountInfoCommentRequestDto){
CommentResponseDto.DiscountInfoCommentResponseDto dto = discountCommentService.saveComment(userId, discountInfoCommentRequestDto);
CommentResponseDto.DiscountInfoCommentResponseDto dto = discountCommentService.saveComment(userDto.getId(), discountInfoCommentRequestDto);
return ApiResponse.onSuccess(dto);
}

Expand All @@ -54,9 +55,9 @@ public ApiResponse<Page<CommentResponseDto.DiscountInfoCommentResponseDto>> find

@PostMapping("/supports/comments")
public ApiResponse<CommentResponseDto.SupportInfoCommentResponseDto> saveSupportInfoComment(
@RequestParam("userId") @ExistUser Long userId,
@AuthUser UserDto.AuthUserDto userDto,
@RequestBody CommentRequestDto.SupportInfoCommentRequestDto supportInfoCommentRequestDto){
CommentResponseDto.SupportInfoCommentResponseDto dto = supportCommentService.saveComment(userId, supportInfoCommentRequestDto);
CommentResponseDto.SupportInfoCommentResponseDto dto = supportCommentService.saveComment(userDto.getId(), supportInfoCommentRequestDto);
return ApiResponse.onSuccess(dto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto;
import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto;
import com.bbteam.budgetbuddies.domain.comment.validation.ExistComment;
import com.bbteam.budgetbuddies.domain.user.validation.ExistUser;
import com.bbteam.budgetbuddies.domain.user.dto.UserDto;
import com.bbteam.budgetbuddies.global.security.utils.AuthUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
Expand All @@ -24,12 +25,11 @@ public interface CommentControllerApi {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
})
@Parameters({
@Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"),
@Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"),
@Parameter(name = "content", description = "댓글 내용입니다. requestBody"),
})
ApiResponse<CommentResponseDto.DiscountInfoCommentResponseDto> saveDiscountInfoComment(
@ExistUser Long userId,
@AuthUser UserDto.AuthUserDto userDto,
CommentRequestDto.DiscountInfoCommentRequestDto discountInfoCommentRequestDto);


Expand All @@ -51,12 +51,11 @@ ApiResponse<Page<CommentResponseDto.DiscountInfoCommentResponseDto>> findAllByDi
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
})
@Parameters({
@Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"),
@Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"),
@Parameter(name = "content", description = "댓글 내용입니다. requestBody"),
})
ApiResponse<CommentResponseDto.SupportInfoCommentResponseDto> saveSupportInfoComment(
@ExistUser Long userId,
@AuthUser UserDto.AuthUserDto userDto,
CommentRequestDto.SupportInfoCommentRequestDto supportInfoCommentRequestDto);

@Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import com.bbteam.budgetbuddies.apiPayload.ApiResponse;
import com.bbteam.budgetbuddies.domain.faq.dto.FaqRequestDto;
import com.bbteam.budgetbuddies.domain.faq.validation.ExistFaq;
import com.bbteam.budgetbuddies.domain.user.validation.ExistUser;
import com.bbteam.budgetbuddies.domain.user.dto.UserDto;
import com.bbteam.budgetbuddies.global.security.utils.AuthUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
Expand Down Expand Up @@ -44,11 +45,7 @@ public interface FaqApi {
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
})
@Parameters({
@Parameter(name = "userId", description = "FAQ를 사용하는 userId입니다.. pathVariable", in = ParameterIn.QUERY),
}
)
ApiResponse<?> postFaq(@ExistUser @RequestParam Long userId,
ApiResponse<?> postFaq(@AuthUser UserDto.AuthUserDto userDto,
@Valid @org.springframework.web.bind.annotation.RequestBody FaqRequestDto.FaqPostRequest dto);
@Operation(summary = "[Admin] FAQ 조회 API", description = "FAQ를 조회하는 API입니다."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.bbteam.budgetbuddies.domain.faq.dto.FaqResponseDto;
import com.bbteam.budgetbuddies.domain.faq.service.FaqService;
import com.bbteam.budgetbuddies.domain.faq.validation.ExistFaq;
import com.bbteam.budgetbuddies.domain.user.validation.ExistUser;
import com.bbteam.budgetbuddies.domain.user.dto.UserDto;
import com.bbteam.budgetbuddies.global.security.utils.AuthUser;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Null;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Page;
Expand All @@ -26,9 +26,9 @@ public class FaqController implements FaqApi{

@Override
@PostMapping("")
public ApiResponse<FaqResponseDto.FaqPostResponse> postFaq(@ExistUser @RequestParam Long userId,
public ApiResponse<FaqResponseDto.FaqPostResponse> postFaq(@AuthUser UserDto.AuthUserDto userDto,
@Valid @RequestBody FaqRequestDto.FaqPostRequest dto) {
return ApiResponse.onSuccess(faqService.postFaq(dto, userId));
return ApiResponse.onSuccess(faqService.postFaq(dto, userDto.getId()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

import com.bbteam.budgetbuddies.apiPayload.ApiResponse;
import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto;
import com.bbteam.budgetbuddies.domain.user.validation.ExistUser;
import com.bbteam.budgetbuddies.domain.user.dto.UserDto;
import com.bbteam.budgetbuddies.global.security.utils.AuthUser;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestParam;

public interface MainPageApi {

@Operation(summary = "[User] 메인페이지 요청 API", description = "userId 기반으로 메인 페이지를 가져옵니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
})
@Parameters({
@Parameter(name = "userId", description = "현재 데이터를 요청하는 사용자입니다. parameter"),
})
ApiResponse<MainPageResponseDto> getMainPage(@RequestParam("userId") @ExistUser Long userId);
ApiResponse<MainPageResponseDto> getMainPage(@AuthUser UserDto.AuthUserDto userDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import com.bbteam.budgetbuddies.apiPayload.ApiResponse;
import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto;
import com.bbteam.budgetbuddies.domain.mainpage.service.MainPageService;
import com.bbteam.budgetbuddies.domain.user.validation.ExistUser;
import com.bbteam.budgetbuddies.domain.user.dto.UserDto;
import com.bbteam.budgetbuddies.global.security.utils.AuthUser;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -21,8 +19,8 @@ public class MainPageController implements MainPageApi{

@GetMapping("/main")
public ApiResponse<MainPageResponseDto> getMainPage
(@RequestParam("userId") @ExistUser Long userId) {
MainPageResponseDto mainPage = mainPageService.getMainPage(userId);
(@AuthUser UserDto.AuthUserDto userDto) {
MainPageResponseDto mainPage = mainPageService.getMainPage(userDto.getId());
return ApiResponse.onSuccess(mainPage);
}
}

0 comments on commit 5bf8666

Please sign in to comment.