Skip to content

Commit

Permalink
refactor: Like Controller return값 리팩터링 (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
ariimo authored and lja3723 committed Nov 8, 2024
1 parent 11bf54d commit 5dc4edb
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.ktc2.cokaen.wouldyouin.like.api;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.ktc2.cokaen.wouldyouin._common.api.ApiResponse;
import org.ktc2.cokaen.wouldyouin._common.api.ApiResponseBody;
import org.ktc2.cokaen.wouldyouin.auth.Authorize;
import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier;
import org.ktc2.cokaen.wouldyouin.like.application.LikeResponse;
import org.ktc2.cokaen.wouldyouin.like.application.LikeServiceFactory;
import org.ktc2.cokaen.wouldyouin.member.persist.MemberType;
import org.springframework.http.HttpStatus;
Expand All @@ -28,18 +30,18 @@ public class LikeController {
// Todo: api 요청시 create, delete를 분리하지말고 토글방식으로 하면 어떨지

@GetMapping
public ResponseEntity<?> getLikes(@Authorize(MemberType.normal) MemberIdentifier identifier, @RequestParam("type") MemberType memberType) {
public ResponseEntity<ApiResponseBody<List<LikeResponse>>> getLikes(@Authorize(MemberType.normal) MemberIdentifier identifier, @RequestParam("type") MemberType memberType) {
return ApiResponse.ok(likeServiceFactory.getLikeServiceFrom(memberType).getLikes(identifier.id()));
}

@PostMapping("/{targetMemberId}")
public ResponseEntity<?> createLike(@Authorize(MemberType.normal) MemberIdentifier identifier, @PathVariable("targetMemberId") Long targetId) {
public ResponseEntity<ApiResponseBody<LikeResponse>> createLike(@Authorize(MemberType.normal) MemberIdentifier identifier, @PathVariable("targetMemberId") Long targetId) {
return ApiResponse.created(likeServiceFactory.getLikeServiceFrom(targetId).create(identifier.id(), targetId));
}

@DeleteMapping("/{targetMemberId}")
public ResponseEntity<?> deleteLike(@Authorize(MemberType.normal) MemberIdentifier identifier, @PathVariable("targetMemberId") Long targetId) {
public ResponseEntity<ApiResponseBody<Void>> deleteLike(@Authorize(MemberType.normal) MemberIdentifier identifier, @PathVariable("targetMemberId") Long targetId) {
likeServiceFactory.getLikeServiceFrom(targetId).delete(identifier.id(), targetId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(new ApiResponseBody<>(true, null));
return ApiResponse.noContent();
}
}

0 comments on commit 5dc4edb

Please sign in to comment.