Skip to content

Commit

Permalink
[Refactor/#294] Add missing @Valid annotation to ApiController methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnsugyeong committed Jun 29, 2024
1 parent 02f9a90 commit e34cb6d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.example.waggle.domain.board.presentation.controller;

import static com.example.waggle.global.annotation.api.PredefinedErrorStatus.ADMIN;
import static com.example.waggle.global.annotation.api.PredefinedErrorStatus.AUTH;
import static com.example.waggle.global.annotation.api.PredefinedErrorStatus.BOARD_DATA_CHANGE;
import static com.example.waggle.global.util.PageUtil.LATEST_SORTING;
import static com.example.waggle.global.util.PageUtil.STORY_SIZE;

import com.example.waggle.domain.board.application.story.StoryCommandService;
import com.example.waggle.domain.board.application.story.StoryQueryService;
import com.example.waggle.domain.board.persistence.entity.Story;
Expand All @@ -20,20 +26,23 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

import static com.example.waggle.global.annotation.api.PredefinedErrorStatus.*;
import static com.example.waggle.global.util.PageUtil.LATEST_SORTING;
import static com.example.waggle.global.util.PageUtil.STORY_SIZE;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -64,7 +73,7 @@ public ApiResponseDto<Long> createStory(@RequestPart("createStoryRequest") @Vali
@ApiErrorCodeExample(status = BOARD_DATA_CHANGE)
@PutMapping(value = "/{storyId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ApiResponseDto<Long> updateStory(@PathVariable("storyId") Long storyId,
@RequestPart("updateStoryRequest") StoryRequest updateStoryRequest,
@RequestPart("updateStoryRequest") @Valid StoryRequest updateStoryRequest,
@AuthUser Member member) {
List<String> removedPrefixMedia = updateStoryRequest.getMediaList().stream()
.map(media -> MediaUtil.removePrefix(media)).collect(Collectors.toList());
Expand Down Expand Up @@ -107,7 +116,8 @@ public ApiResponseDto<StorySummaryListDto> searchStoryListBySorting(
@RequestParam(name = "currentPage", defaultValue = "0") int currentPage) {
ObjectUtil.validateKeywordLength(keyword);
Pageable pageable = PageRequest.of(currentPage, STORY_SIZE, LATEST_SORTING);
Page<Story> PagedStoryList = storyQueryService.getPagedStoryListByKeywordAndSortParam(keyword, sortParam, pageable);
Page<Story> PagedStoryList = storyQueryService.getPagedStoryListByKeywordAndSortParam(keyword, sortParam,
pageable);
return ApiResponseDto.onSuccess(StoryConverter.toListDto(PagedStoryList));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.example.waggle.domain.schedule.presentation.controller;

import static com.example.waggle.global.annotation.api.PredefinedErrorStatus.ADMIN;
import static com.example.waggle.global.annotation.api.PredefinedErrorStatus.AUTH;
import static com.example.waggle.global.util.PageUtil.LATEST_SORTING;
import static com.example.waggle.global.util.PageUtil.SCHEDULE_SIZE;

import com.example.waggle.domain.member.persistence.entity.Member;
import com.example.waggle.domain.member.presentation.converter.MemberConverter;
import com.example.waggle.domain.member.presentation.dto.MemberResponse.MemberSummaryListDto;
Expand All @@ -20,22 +25,23 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

import static com.example.waggle.global.annotation.api.PredefinedErrorStatus.ADMIN;
import static com.example.waggle.global.annotation.api.PredefinedErrorStatus.AUTH;
import static com.example.waggle.global.util.PageUtil.LATEST_SORTING;
import static com.example.waggle.global.util.PageUtil.SCHEDULE_SIZE;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -113,7 +119,7 @@ public ApiResponseDto<Boolean> deleteScheduleByAdmin(@PathVariable("scheduleId")
}, status = AUTH)
@PutMapping("/{scheduleId}")
public ApiResponseDto<Long> updateSchedule(@PathVariable("scheduleId") Long scheduleId,
@RequestBody ScheduleRequest updateScheduleRequest,
@RequestBody @Valid ScheduleRequest updateScheduleRequest,
@AuthUser Member member) {
Long updatedScheduleId = scheduleCommandService.updateSchedule(scheduleId, updateScheduleRequest, member);
return ApiResponseDto.onSuccess(updatedScheduleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
Expand All @@ -37,7 +38,7 @@ public class TokenApiController {
ErrorStatus._INTERNAL_SERVER_ERROR
})
@PostMapping
public ApiResponseDto<JwtToken> login(@RequestBody MemberCredentialsDto loginRequest,
public ApiResponseDto<JwtToken> login(@RequestBody @Valid MemberCredentialsDto loginRequest,
HttpServletResponse response) {
JwtToken jwtToken = tokenService.login(loginRequest);
CookieUtil.addCookie(response, "refresh_token", jwtToken.getRefreshToken(), week);
Expand Down Expand Up @@ -66,7 +67,8 @@ public ApiResponseDto<CookieStatus> logout(HttpServletRequest request, HttpServl
Optional<String> refreshToken = CookieUtil.getCookie(request, "refresh_token")
.map(cookie -> cookie.getValue());
refreshToken.ifPresent(token -> removeRefreshInRedis(request, response, token));
CookieStatus cookieStatus = refreshToken.isPresent() ? CookieStatus.EXIST_REFRESH : CookieStatus.NOT_EXIST_REFRESH;
CookieStatus cookieStatus =
refreshToken.isPresent() ? CookieStatus.EXIST_REFRESH : CookieStatus.NOT_EXIST_REFRESH;
return ApiResponseDto.onSuccess(cookieStatus);
}

Expand Down

0 comments on commit e34cb6d

Please sign in to comment.