Skip to content

Commit

Permalink
Merge pull request #136 from Team-Shaka/feature/133
Browse files Browse the repository at this point in the history
Feature/133 : Scrap API 응닡 λ³€κ²½
  • Loading branch information
swa07016 authored Jan 1, 2024
2 parents 43dc199 + f44395a commit 8b7e018
Show file tree
Hide file tree
Showing 23 changed files with 587 additions and 217 deletions.
49 changes: 0 additions & 49 deletions src/main/java/briefing/briefing/api/BriefingApi.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package briefing.briefing.api;

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

Expand All @@ -13,15 +11,13 @@
import briefing.briefing.application.BriefingQueryService;
import briefing.briefing.application.dto.*;
import briefing.briefing.domain.Briefing;
import briefing.briefing.domain.BriefingType;
import briefing.common.enums.APIVersion;
import briefing.common.response.CommonResponse;
import briefing.member.domain.Member;
import briefing.scrap.application.ScrapQueryService;
import briefing.security.handler.annotation.AuthMember;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

Expand All @@ -34,15 +30,6 @@ public class BriefingApi {
private final BriefingCommandService briefingCommandService;
private final ScrapQueryService scrapQueryService;

@GetMapping("/v2/briefings")
@Operation(summary = "03-01Briefing \uD83D\uDCF0 λΈŒλ¦¬ν•‘ λͺ©λ‘ 쑰회 V2", description = "")
public CommonResponse<BriefingResponseDTO.BriefingPreviewListDTOV2> findBriefingsV2(
@ParameterObject @ModelAttribute BriefingRequestParam.BriefingPreviewListParam params) {
List<Briefing> briefingList = briefingQueryService.findBriefings(params, APIVersion.V2);
return CommonResponse.onSuccess(
BriefingConverter.toBriefingPreviewListDTOV2(params.getDate(), briefingList));
}

@GetMapping("/briefings")
@Parameter(name = "timeOfDay", hidden = true)
@Operation(summary = "03-01Briefing \uD83D\uDCF0 λΈŒλ¦¬ν•‘ λͺ©λ‘ 쑰회 V1", description = "")
Expand All @@ -54,42 +41,6 @@ public CommonResponse<BriefingResponseDTO.BriefingPreviewListDTO> findBriefings(
BriefingConverter.toBriefingPreviewListDTO(params.getDate(), briefingList));
}

@Deprecated
@Operation(
summary = "ν‚€μ›Œλ“œ 전달 V2 μž„μ‹œ API",
description = "ν‚€μ›Œλ“œ 전달 V2 μž„μ‹œ API μž…λ‹ˆλ‹€. 응닡은 무쑰건 λ™μΌν•©λ‹ˆλ‹€. type만 μ£Όμ‹ κ±Έ λ‹΄μ•„μ„œ λ“œλ¦½λ‹ˆλ‹€.")
@ApiResponse(responseCode = "1000", description = "OK, 성곡")
@GetMapping("/briefings/temp")
public CommonResponse<BriefingResponseDTO.BriefingV2PreviewListDTO> findBriefingsV2Temp(
@RequestParam("type") final BriefingType type,
@RequestParam("date") final LocalDate date) {
List<Long> idList = Arrays.asList(346L, 347L, 348L, 349L, 350L);
return CommonResponse.onSuccess(
BriefingConverter.toBriefingPreviewV2TempListDTO(date, idList, type));
}

@GetMapping("/v2/briefings/{id}")
@Operation(summary = "03-02Briefing \uD83D\uDCF0 λΈŒλ¦¬ν•‘ 단건 쑰회 V2", description = "")
@Parameter(name = "member", hidden = true)
public CommonResponse<BriefingResponseDTO.BriefingDetailDTOV2> findBriefingV2(
@PathVariable final Long id, @AuthMember Member member) {

Boolean isScrap =
Optional.ofNullable(member)
.map(m -> scrapQueryService.existsByMemberIdAndBriefingId(m.getId(), id))
.orElseGet(() -> Boolean.FALSE);

Boolean isBriefingOpen = false;
Boolean isWarning = false;

return CommonResponse.onSuccess(
BriefingConverter.toBriefingDetailDTOV2(
briefingQueryService.findBriefing(id, APIVersion.V2),
isScrap,
isBriefingOpen,
isWarning));
}

@GetMapping("/briefings/{id}")
@Parameter(name = "member", hidden = true)
@Operation(summary = "03-02Briefing \uD83D\uDCF0 λΈŒλ¦¬ν•‘ 단건 쑰회 V1", description = "")
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/briefing/briefing/api/BriefingV2Api.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package briefing.briefing.api;

import java.util.List;
import java.util.Optional;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import briefing.briefing.application.BriefingCommandService;
import briefing.briefing.application.BriefingQueryService;
import briefing.briefing.application.dto.BriefingRequestParam;
import briefing.briefing.application.dto.BriefingResponseDTO;
import briefing.briefing.domain.Briefing;
import briefing.common.enums.APIVersion;
import briefing.common.response.CommonResponse;
import briefing.member.domain.Member;
import briefing.scrap.application.ScrapQueryService;
import briefing.security.handler.annotation.AuthMember;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@Tag(name = "03-Briefing V2 \uD83D\uDCF0", description = "λΈŒλ¦¬ν•‘ κ΄€λ ¨ API V2")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v2")
public class BriefingV2Api {
private final BriefingQueryService briefingQueryService;
private final BriefingCommandService briefingCommandService;
private final ScrapQueryService scrapQueryService;

@GetMapping("/briefings")
@Operation(summary = "03-01Briefing \uD83D\uDCF0 λΈŒλ¦¬ν•‘ λͺ©λ‘ 쑰회 V2", description = "")
public CommonResponse<BriefingResponseDTO.BriefingPreviewListDTOV2> findBriefingsV2(
@ParameterObject @ModelAttribute BriefingRequestParam.BriefingPreviewListParam params) {
List<Briefing> briefingList = briefingQueryService.findBriefings(params, APIVersion.V2);
return CommonResponse.onSuccess(
BriefingConverter.toBriefingPreviewListDTOV2(params.getDate(), briefingList));
}

@GetMapping("/briefings/{id}")
@Operation(summary = "03-02Briefing \uD83D\uDCF0 λΈŒλ¦¬ν•‘ 단건 쑰회 V2", description = "")
@Parameter(name = "member", hidden = true)
public CommonResponse<BriefingResponseDTO.BriefingDetailDTOV2> findBriefingV2(
@PathVariable final Long id, @AuthMember Member member) {

Boolean isScrap =
Optional.ofNullable(member)
.map(m -> scrapQueryService.existsByMemberIdAndBriefingId(m.getId(), id))
.orElseGet(() -> Boolean.FALSE);

Boolean isBriefingOpen = false;
Boolean isWarning = false;

return CommonResponse.onSuccess(
BriefingConverter.toBriefingDetailDTOV2(
briefingQueryService.findBriefing(id, APIVersion.V2),
isScrap,
isBriefingOpen,
isWarning));
}
}
4 changes: 2 additions & 2 deletions src/main/java/briefing/exception/ExceptionAdvice.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@RestControllerAdvice(annotations = {RestController.class})
public class ExceptionAdvice extends ResponseEntityExceptionHandler {

@org.springframework.web.bind.annotation.ExceptionHandler
@ExceptionHandler
public ResponseEntity<Object> validation(ConstraintViolationException e, WebRequest request) {
String errorMessage =
e.getConstraintViolations().stream()
Expand Down Expand Up @@ -73,7 +73,7 @@ public ResponseEntity<Object> handleMethodArgumentNotValid(
ex, HttpHeaders.EMPTY, ErrorCode.valueOf("_BAD_REQUEST"), request, errors);
}

@org.springframework.web.bind.annotation.ExceptionHandler
@ExceptionHandler
public ResponseEntity<Object> exception(Exception e, WebRequest request) {
e.printStackTrace();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ApiErrorResult {
public class ApiErrorResult {

private Boolean isSuccess;
private String code;
Expand Down
90 changes: 0 additions & 90 deletions src/main/java/briefing/member/api/MemberApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,6 @@ public CommonResponse<MemberResponse.LoginDTO> login(
MemberConverter.toLoginDTO(member, accessToken, refreshToken));
}

@Operation(summary = "02-01 Member\uD83D\uDC64 μ†Œμ…œ 둜그인 V2", description = "ꡬ글, μ• ν”Œ μ†Œμ…œλ‘œκ·ΈμΈ APIμž…λ‹ˆλ‹€.")
@PostMapping("/v2/members/auth/{socialType}")
public CommonResponse<MemberResponse.LoginDTO> loginV2(
@Parameter(description = "μ†Œμ…œλ‘œκ·ΈμΈ μ’…λ₯˜", example = "google") @PathVariable
final SocialType socialType,
@RequestBody final MemberRequest.LoginDTO request) {
Member member = memberCommandService.login(socialType, request);
String accessToken =
tokenProvider.createAccessToken(
member.getId(),
member.getSocialType().toString(),
member.getSocialId(),
List.of(new SimpleGrantedAuthority(MemberRole.ROLE_USER.name())));
String refreshToken =
redisService
.generateRefreshToken(member.getSocialId(), member.getSocialType())
.getToken();
return CommonResponse.onSuccess(
MemberConverter.toLoginDTO(member, accessToken, refreshToken));
}

@Operation(
summary = "02-01 Member\uD83D\uDC64 accessToken μž¬λ°œκΈ‰ λ°›κΈ° V1",
description = "accessToken 만료 μ‹œ refreshToken으둜 μž¬λ°œκΈ‰μ„ λ°›λŠ” API μž…λ‹ˆλ‹€.")
Expand Down Expand Up @@ -142,40 +121,6 @@ public CommonResponse<MemberResponse.ReIssueTokenDTO> reissueToken(
parsedMember.getId(), accessToken, refreshToken.getToken()));
}

@Operation(
summary = "02-01 Member\uD83D\uDC64 accessToken μž¬λ°œκΈ‰ λ°›κΈ° V2",
description = "accessToken 만료 μ‹œ refreshToken으둜 μž¬λ°œκΈ‰μ„ λ°›λŠ” API μž…λ‹ˆλ‹€.")
@ApiResponses({
@ApiResponse(responseCode = "1000", description = "OK, 성곡"),
@ApiResponse(
responseCode = "COMMON001",
description = "request body에 λ‹΄κΈΈ 값이 이상함, resultλ₯Ό ν™•μΈν•΄μ£Όμ„Έμš”!",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
@ApiResponse(
responseCode = "AUTH005",
description = "λ¦¬ν”„λ ˆμ‹œ 토큰도 만료, λ‹€μ‹œ 둜그인",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
@ApiResponse(
responseCode = "AUTH009",
description = "λ¦¬ν”„λ ˆμ‹œ 토큰 λͺ¨μ–‘이 잘λͺ» 됨",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
})
@PostMapping("/v2/members/auth/token")
public CommonResponse<MemberResponse.ReIssueTokenDTO> reissueTokenV2(
@Valid @RequestBody MemberRequest.ReissueDTO request) {
RefreshToken refreshToken = redisService.reGenerateRefreshToken(request);
Member parsedMember = memberCommandService.parseRefreshToken(refreshToken);
String accessToken =
tokenProvider.createAccessToken(
parsedMember.getId(),
parsedMember.getSocialType().toString(),
parsedMember.getSocialId(),
List.of(new SimpleGrantedAuthority(parsedMember.getRole().toString())));
return CommonResponse.onSuccess(
MemberConverter.toReIssueTokenDTO(
parsedMember.getId(), accessToken, refreshToken.getToken()));
}

@Operation(summary = "02-01 Member\uD83D\uDC64 νšŒμ› νƒˆν‡΄ V1", description = "νšŒμ› νƒˆν‡΄ API μž…λ‹ˆλ‹€.")
@DeleteMapping("/members/{memberId}")
@Parameters({
Expand Down Expand Up @@ -210,39 +155,4 @@ public CommonResponse<MemberResponse.QuitDTO> quitMember(
memberCommandService.deleteMember(memberId);
return CommonResponse.onSuccess(MemberConverter.toQuitDTO());
}

@Operation(summary = "02-01 Member\uD83D\uDC64 νšŒμ› νƒˆν‡΄ V2", description = "νšŒμ› νƒˆν‡΄ API μž…λ‹ˆλ‹€.")
@DeleteMapping("/v2/members/{memberId}")
@Parameters({
@Parameter(name = "member", hidden = true),
@Parameter(name = "memberId", description = "μ‚­μ œ λŒ€μƒ 멀버아이디")
})
@ApiResponses({
@ApiResponse(responseCode = "1000", description = "OK, 성곡"),
@ApiResponse(
responseCode = "AUTH003",
description = "access 토큰을 μ£Όμ„Έμš”!",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
@ApiResponse(
responseCode = "AUTH004",
description = "acess 토큰 만료",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
@ApiResponse(
responseCode = "AUTH006",
description = "acess 토큰 λͺ¨μ–‘이 이상함",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
@ApiResponse(
responseCode = "MEMBER_001",
description = "μ‚¬μš©μžκ°€ μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
@ApiResponse(
responseCode = "MEMBER_002",
description = "둜그인 ν•œ μ‚¬μš©μžμ™€ νƒˆν‡΄ λŒ€μƒμ΄ λ™μΌν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
})
public CommonResponse<MemberResponse.QuitDTO> quitMemberV2(
@AuthMember Member member, @CheckSameMember @PathVariable Long memberId) {
memberCommandService.deleteMember(memberId);
return CommonResponse.onSuccess(MemberConverter.toQuitDTO());
}
}
Loading

0 comments on commit 8b7e018

Please sign in to comment.