Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "refactor: Api Response 타입 통일 [user제외]" #99

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.petmatz.api.match.controller;

import com.petmatz.api.global.dto.Response;
import com.petmatz.api.match.request.PenaltyScore;
import com.petmatz.domain.match.dto.response.PaginatedMatchResponse;
import com.petmatz.domain.match.service.MatchScoreService;
import com.petmatz.domain.match.service.MatchService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -20,18 +18,22 @@ public class MatchController {


@GetMapping("/showmetz")
public Response<PaginatedMatchResponse> getPageDetails(
public ResponseEntity<PaginatedMatchResponse> getPageDetails(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size) {
matchScoreService.calculateTotalScore();
PaginatedMatchResponse userDetails = matchService.getPageUserDetailsFromRedis(page, size);
return Response.success(userDetails);

if (userDetails.matchResults().isEmpty()) {
return ResponseEntity.noContent().build();
}
return ResponseEntity.ok(userDetails);
}

@PostMapping("/matchfail")
public Response<Void> matchFail(@RequestBody PenaltyScore penaltyScore) {
public ResponseEntity<Void> matchFail(@RequestBody PenaltyScore penaltyScore) {
matchScoreService.decreaseScore(penaltyScore.targetId());
return Response.success();
return ResponseEntity.ok().build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public void calculateTotalScore() {
}

@PostMapping("/get-users")
public Response<List<UserResponse>> getUsersWithinBoundingBox(@RequestBody UserIdRequest userId) {
List<UserResponse> usersWithinBoundingBox = matchScoreService.getUsersWithinBoundingBox(userId.userId());
return Response.success(usersWithinBoundingBox);
public List<UserResponse> getUsersWithinBoundingBox(@RequestBody UserIdRequest userId) {
return matchScoreService.getUsersWithinBoundingBox(userId.userId());
}
}

16 changes: 8 additions & 8 deletions src/main/java/com/petmatz/api/pet/PetController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,42 @@ public class PetController {
// 동물등록번호 조회
@PostMapping("/fetch")
@Operation(summary = "동물등록번호 조회", description = "외부 API를 통해 동물등록번호 정보를 조회합니다.")
public Response<PetInfoDto> fetchPetInfo(@RequestBody PetApiRequest request) {
public ResponseEntity<Response<PetInfoDto>> fetchPetInfo(@RequestBody PetApiRequest request) {
PetServiceDto serviceDto = PetApiRequest.toServiceDto(request);
PetServiceDto fetchedServiceDto = petServiceImpl.fetchPetInfo(serviceDto.dogRegNo(), serviceDto.ownerNm());
PetInfoDto responseDto = PetInfoDto.of(fetchedServiceDto);
return Response.success(responseDto);
return ResponseEntity.ok(Response.success(responseDto));
}

// 댕댕이 정보 등록
@PostMapping("/register")
@Operation(summary = "반려동물 등록", description = "사용자의 반려동물 정보를 등록합니다.")
public Response<PetSaveResponse> registerPet(@RequestBody PetRequest request) throws MalformedURLException {
public ResponseEntity<Response<PetSaveResponse>> registerPet(@RequestBody PetRequest request) throws MalformedURLException {
User user = getAuthenticatedUser();
PetServiceDto serviceDto = PetRequest.toServiceDto(request);
PetSaveResponse petSaveResponse = petServiceImpl.savePet(user, serviceDto);
return Response.success(petSaveResponse);
return ResponseEntity.ok(Response.success(petSaveResponse));
}

// 댕댕이 정보 수정
@PutMapping("/{id}")
@Operation(summary = "반려동물 정보 수정", description = "기존 반려동물 정보를 수정합니다.")
@Parameter(name = "id", description = "반려동물 ID", example = "1")
public Response<PetUpdateResponse> updatePet(@PathVariable Long id, @RequestBody PetRequest updatedRequest) {
public ResponseEntity<Response<PetUpdateResponse>> updatePet(@PathVariable Long id, @RequestBody PetRequest updatedRequest) {
User user = getAuthenticatedUser();
PetServiceDto updatedServiceDto = PetServiceDto.of(updatedRequest);
PetUpdateResponse petUpdateResponse = petServiceImpl.updatePet(id, user, updatedServiceDto);
return Response.success(petUpdateResponse);
return ResponseEntity.ok(Response.success(petUpdateResponse));
}

// 댕댕이 정보 삭제
@DeleteMapping("/{id}")
@Operation(summary = "반려동물 삭제", description = "등록된 반려동물을 삭제합니다.")
@Parameter(name = "id", description = "반려동물 ID", example = "1")
public Response<Void> deletePet(@PathVariable Long id) {
public ResponseEntity<Response<Void>> deletePet(@PathVariable Long id) {
User user = getAuthenticatedUser();
petServiceImpl.deletePet(id, user);
return Response.success("댕댕이 정보가 성공적으로 삭제되었습니다.");
return ResponseEntity.ok(Response.success("댕댕이 정보가 성공적으로 삭제되었습니다."));
}

private User getAuthenticatedUser() {
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/com/petmatz/api/sosboard/SosBoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class SosBoardController {
@Parameter(name = "pageNum", description = "조회할 페이지 번호 (1부터 시작)", example = "1"),
@Parameter(name = "size", description = "가져올 게시글 개수", example = "10")
})
public Response<PageResponseDto<SosBoardResponseDto>> getAllSosBoards(
public ResponseEntity<Response<PageResponseDto<SosBoardResponseDto>>> getAllSosBoards(
@RequestParam(required = false) String region,
@RequestParam(defaultValue = "1") int pageNum, // 페이지 번호 기본값 1
@RequestParam(defaultValue = "10") int size) { // 페이지 크기 기본값 10
Expand All @@ -60,38 +60,38 @@ public Response<PageResponseDto<SosBoardResponseDto>> getAllSosBoards(
serviceDtoPageResponse.currentPage()
);

return Response.success(responseDtoPageResponse);
return ResponseEntity.ok(Response.success(responseDtoPageResponse));
}


// 2. 돌봄 SOS 페이지 게시글 작성
@PostMapping
@Operation(summary = "SOS 게시글 작성", description = "SOS 게시판에 새로운 게시글을 작성합니다.")
public Response<SosBoardResponseDto> createSosBoard(@RequestBody SosBoardCreateRequestDto requestDto) {
public ResponseEntity<Response<SosBoardResponseDto>> createSosBoard(@RequestBody SosBoardCreateRequestDto requestDto) {
User user = getAuthenticatedUser(); // 인증된 사용자 가져오기
SosBoardServiceDto serviceDto = requestDto.toServiceDto(user); // 프레젠테이션 DTO → 서비스 DTO 변환
// 서비스 계층 호출
SosBoardServiceDto createdBoard = sosBoardServiceImpl.createSosBoard(serviceDto);
SosBoardResponseDto responseDto = SosBoardResponseDto.fromServiceDto(createdBoard);
return Response.success(responseDto);
return ResponseEntity.ok(Response.success(responseDto));
}

//돌봄 SOS 페이지 특정 게시글 조회
@GetMapping("/{id}")
@Operation(summary = "특정 SOS 게시글 조회", description = "게시글 ID를 통해 특정 SOS 게시글을 조회합니다.")
@Parameter(name = "id", description = "조회할 게시글의 ID", example = "1")
public Response<SosBoardResponseDto> getSosBoardById(@PathVariable Long id) {
public ResponseEntity<Response<SosBoardResponseDto>> getSosBoardById(@PathVariable Long id) {
SosBoardServiceDto serviceDto = sosBoardServiceImpl.getSosBoardById(id);

SosBoardResponseDto responseDto = SosBoardResponseDto.fromServiceDto(serviceDto);

return Response.success(responseDto);
return ResponseEntity.ok(Response.success(responseDto));
}

// 돌봄 SOS 페이지 글 수정
@PutMapping("/{id}")
@Operation(summary = "SOS 게시글 수정", description = "SOS 게시판의 게시글을 수정합니다.")
public Response<SosBoardResponseDto> updateSosBoard(
public ResponseEntity<Response<SosBoardResponseDto>> updateSosBoard(
@PathVariable Long id,
@RequestBody SosBoardCreateRequestDto requestDto) {

Expand All @@ -100,26 +100,25 @@ public Response<SosBoardResponseDto> updateSosBoard(
SosBoardServiceDto updatedBoard = sosBoardServiceImpl.updateSosBoard(id, serviceDto, user);
SosBoardResponseDto responseDto = SosBoardResponseDto.fromServiceDto(updatedBoard);

return Response.success(responseDto);
return ResponseEntity.ok(Response.success(responseDto));
}

// // 돌봄 SOS 페이지 글 삭제
@DeleteMapping("/{id}")
@Operation(summary = "SOS 게시글 삭제", description = "SOS 게시판의 게시글을 삭제합니다.")
public Response<Void> deleteSosBoard(@PathVariable Long id) {
public ResponseEntity<Response<Void>> deleteSosBoard(@PathVariable Long id) {
User user = getAuthenticatedUser(); // 인증된 사용자 가져오기
sosBoardServiceImpl.deleteSosBoard(id, user);
return Response.success("게시글이 성공적으로 삭제되었습니다.");
return ResponseEntity.ok(Response.success("게시글이 성공적으로 삭제되었습니다."));
}


// 해당 User의 펫 정보 불러오기
@GetMapping("/pets/{userId}")
@Operation(summary = "사용자 반려동물 조회", description = "사용자의 모든 반려동물 정보를 조회합니다.")
@Parameter(name = "userId", description = "사용자 ID", example = "1")
public Response<List<PetResponse>> getUserPets(@PathVariable Long userId) {
List<PetResponse> userPets = sosBoardServiceImpl.getUserPets(userId);
return Response.success(userPets);
public List<PetResponse> getUserPets(@PathVariable Long userId) {
return sosBoardServiceImpl.getUserPets(userId);
}

// 자신이 작성한 게시글 조회 API
Expand All @@ -130,7 +129,7 @@ public Response<List<PetResponse>> getUserPets(@PathVariable Long userId) {
@Parameter(name = "pageNum", description = "페이지 번호", example = "1"),
@Parameter(name = "size", description = "가져올 게시글 개수", example = "10")
})
public Response<PageResponseDto<SosBoardResponseDto>> getUserSosBoardsByNickname(
public ResponseEntity<Response<PageResponseDto<SosBoardResponseDto>>> getUserSosBoardsByNickname(
@PathVariable String nickname,
@RequestParam(defaultValue = "1") int pageNum,
@RequestParam(defaultValue = "10") int size) {
Expand All @@ -153,7 +152,7 @@ public Response<PageResponseDto<SosBoardResponseDto>> getUserSosBoardsByNickname
serviceDtoPageResponse.currentPage()
);

return Response.success(responseDtoPageResponse);
return ResponseEntity.ok(Response.success(responseDtoPageResponse));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.petmatz.api.user.controller;

import co.elastic.clients.elasticsearch._types.Rank;
import com.petmatz.api.global.dto.Response;
import com.petmatz.domain.user.response.RankUserResponse;
import com.petmatz.domain.user.service.RankService;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,9 +18,9 @@ public class RankController {
private final RankService rankService;

@GetMapping("/api/top-rankings")
public Response<List<RankUserResponse>> getTopRankings() {
public ResponseEntity<List<RankUserResponse>> getTopRankings() {
List<RankUserResponse> topRankings = rankService.getTopRankingsByRegion();
return Response.success(topRankings);
return ResponseEntity.ok(topRankings);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.petmatz.infra.redis.component.RedisMatchComponent;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.webjars.NotFoundException;

import java.util.List;

Expand Down Expand Up @@ -38,12 +37,7 @@ public PaginatedMatchResponse getPageUserDetailsFromRedis(int page, int size) {
long totalElements = matchScores.size();
int totalPages = matchScoreProcessor.calculateTotalPages(totalElements, size);

PaginatedMatchResponse paginatedMatchResponse = new PaginatedMatchResponse(detailedMatchResults, totalPages);
if (paginatedMatchResponse.matchResults().isEmpty()) {
throw new NotFoundException("매치 결과가 없습니다.");
}

return paginatedMatchResponse;
return new PaginatedMatchResponse(detailedMatchResults, totalPages);
}
}

1 change: 1 addition & 0 deletions src/main/java/com/petmatz/domain/pet/PetServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class PetServiceImpl implements PetService{
private final PetRepository repository;
private final UserRepository userRepository;
private final ObjectMapper objectMapper = new ObjectMapper();
private final String uploadDir = System.getProperty("user.dir") + "/uploads/";

// 동물 등록 정보를 외부 API로 가져오는 메서드
public PetServiceDto fetchPetInfo(String dogRegNo, String ownerNm) {
Expand Down

This file was deleted.

This file was deleted.

Loading