Skip to content

Commit

Permalink
Merge pull request #92 from AR-TTUBEOG/refactor/87
Browse files Browse the repository at this point in the history
[Refactor] 전체 파일 응답 호출방법 수정
  • Loading branch information
choeun7 authored Mar 22, 2024
2 parents bf73fcd + 7d40f65 commit ea12807
Show file tree
Hide file tree
Showing 23 changed files with 283 additions and 559 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
import com.ttubeog.domain.member.domain.repository.MemberRepository;
import com.ttubeog.domain.member.exception.InvalidMemberException;
import com.ttubeog.domain.store.domain.repository.StoreRepository;
import com.ttubeog.global.payload.ApiResponse;
import com.ttubeog.global.payload.CommonDto;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -41,7 +40,7 @@ public class BenefitService {

//게임 성공 후 혜택 저장
@Transactional
public ApiResponse saveBenefit(HttpServletRequest request, Long benefitId) throws JsonProcessingException {
public CommonDto saveBenefit(HttpServletRequest request, Long benefitId) throws JsonProcessingException {
Long memberId = jwtTokenProvider.getMemberId(request);
Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new);
Benefit benefit = benefitRepository.findById(benefitId).orElseThrow(NonExistentBenefitException::new);
Expand Down Expand Up @@ -73,13 +72,13 @@ public ApiResponse saveBenefit(HttpServletRequest request, Long benefitId) throw
.createdAt(memberBenefit.getCreatedAt())
.build();

return new ApiResponse(true, saveBenefitRes);
return new CommonDto(true, saveBenefitRes);
}


//혜택 사용
@Transactional
public ApiResponse useBenefit(HttpServletRequest request, Long benefitId) throws JsonProcessingException {
public CommonDto useBenefit(HttpServletRequest request, Long benefitId) throws JsonProcessingException {
Long memberId = jwtTokenProvider.getMemberId(request);
Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new);
Benefit benefit = benefitRepository.findById(benefitId).orElseThrow(NonExistentBenefitException::new);
Expand Down Expand Up @@ -107,11 +106,11 @@ public ApiResponse useBenefit(HttpServletRequest request, Long benefitId) throws
.type(benefit.getType())
.build();

return new ApiResponse(true, saveBenefitRes);
return new CommonDto(true, saveBenefitRes);
}

//혜택 조회(사용 가능, 사용 완료, 만료 혜택 모두 조회)
public ApiResponse findMyBenefit(HttpServletRequest request, Integer page) throws JsonProcessingException {
public CommonDto findMyBenefit(HttpServletRequest request, Integer page) throws JsonProcessingException {
Long memberId = jwtTokenProvider.getMemberId(request);
Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new);

Expand All @@ -131,7 +130,7 @@ public ApiResponse findMyBenefit(HttpServletRequest request, Integer page) throw
.build()
).toList();

return new ApiResponse(true, saveBenefitRes);
return new CommonDto(true, saveBenefitRes);
}

//한달지나면 expired true로 만들기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ttubeog.domain.benefit.application.BenefitService;
import com.ttubeog.domain.benefit.dto.response.SaveBenefitRes;
import com.ttubeog.global.payload.CommonDto;
import com.ttubeog.global.payload.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class BenefitController {
@ApiResponse(responseCode = "400", description = "혜택 저장 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
})
@PatchMapping("/{benefitId}")
public ResponseEntity<?> saveBenefit(
public ResponseEntity<CommonDto> saveBenefit(
HttpServletRequest request,
@PathVariable(value = "benefitId") Long benefitId
) throws JsonProcessingException {
Expand All @@ -44,7 +45,7 @@ public ResponseEntity<?> saveBenefit(
@ApiResponse(responseCode = "400", description = "혜택 사용 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
})
@PatchMapping("{benefitId}/use")
public ResponseEntity<?> useBenefit(
public ResponseEntity<CommonDto> useBenefit(
HttpServletRequest request,
@PathVariable(value = "benefitId") Long benefitId
) throws JsonProcessingException {
Expand All @@ -58,7 +59,7 @@ public ResponseEntity<?> useBenefit(
@ApiResponse(responseCode = "400", description = "혜택 조회 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ),
})
@GetMapping
public ResponseEntity<?> findMyBenefit(
public ResponseEntity<CommonDto> findMyBenefit(
HttpServletRequest request,
@RequestParam(name = "page") Integer page
) throws JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.ttubeog.domain.member.domain.Member;
import com.ttubeog.domain.member.domain.repository.MemberRepository;
import com.ttubeog.domain.member.exception.InvalidMemberException;
import com.ttubeog.global.payload.ApiResponse;
import com.ttubeog.global.payload.CommonDto;
import com.ttubeog.global.payload.Message;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
Expand All @@ -36,7 +36,7 @@ public class CommentService {

// 댓글 작성
@Transactional
public ResponseEntity<?> writeComment(HttpServletRequest request, WriteCommentReq writeCommentReq) {
public CommonDto writeComment(HttpServletRequest request, WriteCommentReq writeCommentReq) {

Long memberId = jwtTokenProvider.getMemberId(request);
Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new);
Expand All @@ -58,17 +58,12 @@ public ResponseEntity<?> writeComment(HttpServletRequest request, WriteCommentRe
.longitude(comment.getLongitude())
.build();

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(writeCommentRes)
.build();

return ResponseEntity.ok(apiResponse);
return new CommonDto(true, writeCommentRes);
}

// 댓글 수정
@Transactional
public ResponseEntity<?> updateComment(HttpServletRequest request, UpdateCommentReq updateCommentReq) {
public CommonDto updateComment(HttpServletRequest request, UpdateCommentReq updateCommentReq) {

Long memberId = jwtTokenProvider.getMemberId(request);
Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new);
Expand All @@ -86,37 +81,27 @@ public ResponseEntity<?> updateComment(HttpServletRequest request, UpdateComment
.content(comment.getContent())
.build();

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(updateCommentRes)
.build();

return ResponseEntity.ok(apiResponse);
return new CommonDto(true, updateCommentRes);
}

// 댓글 삭제
@Transactional
public ResponseEntity<?> deleteComment(HttpServletRequest request, Long commentId) {
public CommonDto deleteComment(HttpServletRequest request, Long commentId) {

Long memberId = jwtTokenProvider.getMemberId(request);
memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new);
Comment comment = commentRepository.findById(commentId).orElseThrow(NonExistentCommentException::new);
commentRepository.delete(comment);

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(Message.builder().message("댓글이 정상적으로 삭제되었습니다.").build())
.build();

return ResponseEntity.ok(apiResponse);
return new CommonDto(true, Message.builder().message("댓글이 정상적으로 삭제되었습니다.").build());
}

public List<Comment> getAllComments() {
return commentRepository.findAll();
}

// AR뷰를 위한 댓글 조회
public ResponseEntity<?> getCommentForAR(GetCommentReq getCommentReq) {
public CommonDto getCommentForAR(GetCommentReq getCommentReq) {

Double userLatitude = getCommentReq.getLatitude();
Double userLongitude = getCommentReq.getLongitude();
Expand Down Expand Up @@ -144,12 +129,7 @@ public ResponseEntity<?> getCommentForAR(GetCommentReq getCommentReq) {
}
}

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(showComments)
.build();

return ResponseEntity.ok(apiResponse);
return new CommonDto(true, showComments);
}

// 거리 계산
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.ttubeog.domain.comment.dto.response.GetCommentRes;
import com.ttubeog.domain.comment.dto.response.UpdateCommentRes;
import com.ttubeog.domain.comment.dto.response.WriteCommentRes;
import com.ttubeog.global.payload.CommonDto;
import com.ttubeog.global.payload.ErrorResponse;
import com.ttubeog.global.payload.Message;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -36,11 +37,11 @@ public class CommentController {
@ApiResponse(responseCode = "400", description = "댓글 작성 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))})
})
@PostMapping
public ResponseEntity<?> writeComment(
public ResponseEntity<CommonDto> writeComment(
HttpServletRequest request,
@Valid @RequestBody WriteCommentReq writeCommentReq
) {
return commentService.writeComment(request, writeCommentReq);
return ResponseEntity.ok(commentService.writeComment(request, writeCommentReq));
}

// 댓글 수정
Expand All @@ -50,11 +51,11 @@ public ResponseEntity<?> writeComment(
@ApiResponse(responseCode = "400", description = "댓글 수정 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))})
})
@PatchMapping
public ResponseEntity<?> updateComment(
public ResponseEntity<CommonDto> updateComment(
HttpServletRequest request,
@Valid @RequestBody UpdateCommentReq updateCommentReq
) {
return commentService.updateComment(request, updateCommentReq);
return ResponseEntity.ok(commentService.updateComment(request, updateCommentReq));
}

// 댓글 삭제
Expand All @@ -64,11 +65,11 @@ public ResponseEntity<?> updateComment(
@ApiResponse(responseCode = "400", description = "댓글 삭제 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))})
})
@DeleteMapping("/{commentId}")
public ResponseEntity<?> deleteComment(
public ResponseEntity<CommonDto> deleteComment(
HttpServletRequest request,
@PathVariable Long commentId
) {
return commentService.deleteComment(request, commentId);
return ResponseEntity.ok(commentService.deleteComment(request, commentId));
}

// AR뷰 댓글 조회 (반경 이용)
Expand All @@ -78,9 +79,9 @@ public ResponseEntity<?> deleteComment(
@ApiResponse(responseCode = "400", description = "댓글 조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))})
})
@GetMapping
public ResponseEntity<?> getCommentForAR(
public ResponseEntity<CommonDto> getCommentForAR(
@Valid GetCommentReq getCommentReq
) {
return commentService.getCommentForAR(getCommentReq);
return ResponseEntity.ok(commentService.getCommentForAR(getCommentReq));
}
}
Loading

0 comments on commit ea12807

Please sign in to comment.