Skip to content

Commit

Permalink
Merge pull request #80 from tukcomCD2024/feat#78/unify-response
Browse files Browse the repository at this point in the history
  • Loading branch information
ggamD00 authored May 7, 2024
2 parents 6a653f2 + 903871a commit 9bb3c8a
Show file tree
Hide file tree
Showing 45 changed files with 856 additions and 614 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.example.memetory.domain.comment.controller;

import com.example.memetory.domain.comment.dto.request.GenerateCommentRequest;
import com.example.memetory.global.response.ResultResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;

import org.springframework.http.ResponseEntity;

@Tag(name = "Comment")
Expand All @@ -25,7 +27,7 @@ public interface CommentApi {
description = "댓글 생성!"
)
})
ResponseEntity<HttpStatus> register(
ResponseEntity<ResultResponse> register(
@Parameter(hidden = true) String email,
GenerateCommentRequest generateCommentRequest
);
Expand All @@ -41,7 +43,7 @@ ResponseEntity<HttpStatus> register(
description = "댓글 삭제!"
)
})
ResponseEntity<HttpStatus> delete(
ResponseEntity<ResultResponse> delete(
@Parameter(in = ParameterIn.PATH, description = "댓글 아이디", required = true) Long commentId
);
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
package com.example.memetory.domain.comment.controller;

import static com.example.memetory.global.response.ResultCode.*;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.memetory.domain.comment.dto.CommentServiceDto;
import com.example.memetory.domain.comment.dto.request.GenerateCommentRequest;
import com.example.memetory.domain.comment.service.CommentService;
import com.example.memetory.global.annotation.LoginMemberEmail;
import com.example.memetory.global.response.ResultResponse;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comments")
@RequiredArgsConstructor
public class CommentController implements CommentApi{
public class CommentController implements CommentApi {

private final CommentService commentService;
private final CommentService commentService;

@PostMapping
@Override
public ResponseEntity<HttpStatus> register(@LoginMemberEmail String email, @RequestBody GenerateCommentRequest generateCommentRequest) {
CommentServiceDto newCommentServiceDto = generateCommentRequest.toServiceDto(email);
commentService.register(newCommentServiceDto);
@PostMapping
@Override
public ResponseEntity<ResultResponse> register(@LoginMemberEmail String email,
@RequestBody GenerateCommentRequest generateCommentRequest) {
CommentServiceDto newCommentServiceDto = generateCommentRequest.toServiceDto(email);
commentService.register(newCommentServiceDto);

return ResponseEntity.status(HttpStatus.CREATED).build();
}
return ResponseEntity.status(HttpStatus.CREATED).body(ResultResponse.of(CREATE_COMMENT_SUCCESS));
}

@DeleteMapping("/{commentId}")
@Override
public ResponseEntity<HttpStatus> delete(@PathVariable Long commentId) {
CommentServiceDto newCommentServiceDto = CommentServiceDto.create(commentId);
commentService.delete(newCommentServiceDto);
@DeleteMapping("/{commentId}")
@Override
public ResponseEntity<ResultResponse> delete(@PathVariable Long commentId) {
CommentServiceDto newCommentServiceDto = CommentServiceDto.create(commentId);
commentService.delete(newCommentServiceDto);

return ResponseEntity.status(HttpStatus.OK).build();
}
return ResponseEntity.ok(ResultResponse.of(DELETE_COMMENT_SUCCESS));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.example.memetory.domain.comment.exception;

import com.example.memetory.global.exception.BusinessException;
import com.example.memetory.global.response.ErrorCode;

public class NotFoundCommentException extends RuntimeException {
public NotFoundCommentException() {}

public NotFoundCommentException(String message) {
super(message);
}

public NotFoundCommentException(String message, Throwable cause) {
super(message, cause);
public class NotFoundCommentException extends BusinessException {
public NotFoundCommentException() {
super(ErrorCode.COMMENT_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.example.memetory.domain.complain.controller;

import com.example.memetory.domain.complain.dto.request.GenerateComplainRequest;
import com.example.memetory.global.response.ResultResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;

import org.springframework.http.ResponseEntity;

@Tag(name = "Complain")
Expand All @@ -24,7 +26,7 @@ public interface ComplainApi {
description = "신고 생성!"
)
})
ResponseEntity<HttpStatus> register(
ResponseEntity<ResultResponse> register(
@Parameter(hidden = true) String email,
GenerateComplainRequest generateComplainRequest
);
Expand All @@ -40,7 +42,7 @@ ResponseEntity<HttpStatus> register(
description = "신고 삭제!"
)
})
ResponseEntity<HttpStatus> delete(
ResponseEntity<ResultResponse> delete(
@Parameter(in = ParameterIn.PATH, description = "신고 아이디", required = true) Long complainId
);
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
package com.example.memetory.domain.complain.controller;

import static com.example.memetory.global.response.ResultCode.*;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.memetory.domain.complain.dto.ComplainServiceDto;
import com.example.memetory.domain.complain.dto.request.GenerateComplainRequest;
import com.example.memetory.domain.complain.service.ComplainService;
import com.example.memetory.global.annotation.LoginMemberEmail;
import com.example.memetory.global.response.ResultResponse;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/complains")
public class ComplainController implements ComplainApi{
private final ComplainService complainService;

@PostMapping
@Override
public ResponseEntity<HttpStatus> register(@LoginMemberEmail String email, @RequestBody GenerateComplainRequest generateComplainRequest) {
ComplainServiceDto newComplainServiceDto = generateComplainRequest.toServiceDto(email);
complainService.register(newComplainServiceDto);

return ResponseEntity.status(HttpStatus.CREATED).build();
}

@DeleteMapping("/{complainId}")
@Override
public ResponseEntity<HttpStatus> delete(@PathVariable Long complainId) {
ComplainServiceDto newComplainServiceDto = ComplainServiceDto.create(complainId);
complainService.delete(newComplainServiceDto);

return ResponseEntity.status(HttpStatus.OK).build();
}
public class ComplainController implements ComplainApi {
private final ComplainService complainService;

@PostMapping
@Override
public ResponseEntity<ResultResponse> register(@LoginMemberEmail String email,
@RequestBody GenerateComplainRequest generateComplainRequest) {
ComplainServiceDto newComplainServiceDto = generateComplainRequest.toServiceDto(email);
complainService.register(newComplainServiceDto);

return ResponseEntity.status(HttpStatus.CREATED).body(ResultResponse.of(CREATE_COMPLAIN_SUCCESS));
}

@DeleteMapping("/{complainId}")
@Override
public ResponseEntity<ResultResponse> delete(@PathVariable Long complainId) {
ComplainServiceDto newComplainServiceDto = ComplainServiceDto.create(complainId);
complainService.delete(newComplainServiceDto);

return ResponseEntity.ok(ResultResponse.of(DELETE_COMMENT_SUCCESS));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.example.memetory.domain.complain.exception;

public class NotFoundComplainException extends RuntimeException{
public NotFoundComplainException() {}
import com.example.memetory.global.exception.BusinessException;
import com.example.memetory.global.response.ErrorCode;

public NotFoundComplainException(String message) {
super(message);
}

public NotFoundComplainException(String message, Throwable cause) {
super(message, cause);
public class NotFoundComplainException extends BusinessException {
public NotFoundComplainException() {
super(ErrorCode.COMPLAIN_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;

import com.example.memetory.global.response.ResultResponse;

@Tag(name = "Like")
public interface LikeApi {

Expand All @@ -23,7 +25,7 @@ public interface LikeApi {
description = "좋아요 등록!"
)
})
ResponseEntity<String> register(
ResponseEntity<ResultResponse> register(
@Parameter(hidden = true) String email,
@Parameter(in = ParameterIn.PATH, description = "밈스 아이디", required = true)
Long memesId
Expand All @@ -40,7 +42,7 @@ ResponseEntity<String> register(
description = "좋아요 취소!"
)
})
ResponseEntity<String> cancel(
ResponseEntity<ResultResponse> cancel(
@Parameter(hidden = true) String email,
@Parameter(in = ParameterIn.PATH, description = "밈스 아이디", required = true)
Long memesId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
package com.example.memetory.domain.like.controller;

import static com.example.memetory.global.response.ResultCode.*;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.memetory.domain.like.dto.LikeServiceDto;
import com.example.memetory.domain.like.service.LikeService;
import com.example.memetory.global.annotation.LoginMemberEmail;
import com.example.memetory.global.response.ResultResponse;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/memes")
public class LikeController implements LikeApi {
private final LikeService likeService;
private final LikeService likeService;

@PostMapping("/{memesId}/like")
@Override
public ResponseEntity<String> register(@LoginMemberEmail String email, @PathVariable Long memesId) {
LikeServiceDto likeServiceDto = LikeServiceDto.create(email, memesId);
likeService.register(likeServiceDto);
@PostMapping("/{memesId}/like")
@Override
public ResponseEntity<ResultResponse> register(@LoginMemberEmail String email, @PathVariable Long memesId) {
LikeServiceDto likeServiceDto = LikeServiceDto.create(email, memesId);
likeService.register(likeServiceDto);

return ResponseEntity.status(HttpStatus.CREATED).build();
}
return ResponseEntity.status(HttpStatus.CREATED).body(ResultResponse.of(CREATE_LIKE_SUCCESS));
}

@DeleteMapping("/{memesId}/like")
@Override
public ResponseEntity<String> cancel(@LoginMemberEmail String email, @PathVariable Long memesId) {
LikeServiceDto likeServiceDto = LikeServiceDto.create(email, memesId);
likeService.cancel(likeServiceDto);
@DeleteMapping("/{memesId}/like")
@Override
public ResponseEntity<ResultResponse> cancel(@LoginMemberEmail String email, @PathVariable Long memesId) {
LikeServiceDto likeServiceDto = LikeServiceDto.create(email, memesId);
likeService.cancel(likeServiceDto);

return ResponseEntity.status(HttpStatus.OK).build();
}
return ResponseEntity.ok(ResultResponse.of(DELETE_LIKE_SUCCESS));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.example.memetory.domain.like.exception;

public class NotFoundLikeException extends RuntimeException {
public NotFoundLikeException(){}
import com.example.memetory.global.exception.BusinessException;
import com.example.memetory.global.response.ErrorCode;

public NotFoundLikeException(String message) {
super(message);
}

public NotFoundLikeException(String message, Throwable cause) {
super(message, cause);
}
public class NotFoundLikeException extends BusinessException {
public NotFoundLikeException() {
super(ErrorCode.LIKE_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.example.memetory.domain.member.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import com.example.memetory.domain.member.dto.MemberUpdateDto;
import com.example.memetory.global.response.ResultResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -30,5 +30,5 @@ public interface MemberApi {
description = "닉네임 중복"
)}
)
ResponseEntity<HttpStatus> updateMember(@Parameter(hidden = true) String email, MemberUpdateDto memberUpdateDto);
ResponseEntity<ResultResponse> updateMember(@Parameter(hidden = true) String email, MemberUpdateDto memberUpdateDto);
}
Loading

0 comments on commit 9bb3c8a

Please sign in to comment.