-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix/favorite 55 - response의 id type을 Long -> String으로 변환 #56
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7662009
chore : 변수명 오타 수정
KwonYeKyeong d4eda80
fix : 즐겨찾기 추가 api response 수정
KwonYeKyeong a9a99a8
test : 즐겨찾기 추가 api 테스트코드 작성
KwonYeKyeong a571a3e
chore : swagger 정보 추가
KwonYeKyeong 9802d7c
refactor : (court_id, user_id) 중복 저장 불가능하게 제한
KwonYeKyeong 1d92c6d
fix : 즐겨찾기 조회 api 수정
KwonYeKyeong cc3e6cd
test : 즐겨찾기 조회 api 테스트코드 작성
KwonYeKyeong 08dd127
chore : swagger 정보 추가
KwonYeKyeong 7b2372f
feat : 즐겨찾기가 없을 때 발생하는 구체적인 에러클래스 생성
KwonYeKyeong ba3416c
fix : 즐겨찾기 삭제(취소) api response 삭제
KwonYeKyeong e9b06ad
test : 즐겨찾기 삭제(취소) api 테스트코드 작성
KwonYeKyeong 1d03b59
chore : swagger 정보 추가
KwonYeKyeong 786a10b
chore : 코드 포맷팅
KwonYeKyeong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 54 additions & 46 deletions
100
src/main/java/org/slams/server/favorite/controller/FavoriteController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,74 @@ | ||
package org.slams.server.favorite.controller; | ||
|
||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.slams.server.common.api.TokenGetId; | ||
import org.slams.server.favorite.dto.request.FavoriteInsertRequestDto; | ||
import org.slams.server.favorite.dto.response.FavoriteDeleteResponseDto; | ||
import org.slams.server.favorite.dto.response.FavoriteInsertResponseDto; | ||
import org.slams.server.common.error.ErrorResponse; | ||
import org.slams.server.favorite.dto.request.FavoriteInsertRequest; | ||
import org.slams.server.favorite.dto.response.FavoriteInsertResponse; | ||
import org.slams.server.favorite.dto.response.FavoriteLookUpResponse; | ||
import org.slams.server.favorite.service.FavoriteService; | ||
import org.slams.server.user.oauth.jwt.Jwt; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(value = "/api/v1/favorites") | ||
public class FavoriteController { | ||
private final FavoriteService favoriteService; | ||
private final Jwt jwt; | ||
|
||
@PostMapping() | ||
public ResponseEntity<FavoriteInsertResponseDto> insert(@RequestBody FavoriteInsertRequestDto favoriteInsertRequestDto , HttpServletRequest request) { | ||
|
||
TokenGetId token=new TokenGetId(request,jwt); | ||
Long userId=token.getUserId(); | ||
|
||
return new ResponseEntity<FavoriteInsertResponseDto>(favoriteService.insert(favoriteInsertRequestDto, userId), HttpStatus.CREATED); | ||
} | ||
|
||
@GetMapping() | ||
public ResponseEntity<Map<String,Object>> getAll(HttpServletRequest request) { | ||
|
||
// 여기에 추가로 header 토큰 정보가 들어가야 함. | ||
// 내가 즐겨찾기 한 코트를 찾아야 함. | ||
TokenGetId token=new TokenGetId(request,jwt); | ||
Long userId=token.getUserId(); | ||
|
||
Map<String,Object>result=new HashMap<>(); | ||
result.put("favorites",favoriteService.getAll(userId)); | ||
|
||
return ResponseEntity.ok().body(result); | ||
} | ||
|
||
|
||
@DeleteMapping("{favoriteId}") | ||
public ResponseEntity<FavoriteDeleteResponseDto> delete(@PathVariable Long favoriteId, HttpServletRequest request) { | ||
TokenGetId token=new TokenGetId(request,jwt); | ||
Long userId=token.getUserId(); | ||
|
||
return new ResponseEntity<FavoriteDeleteResponseDto>(favoriteService.delete(userId, favoriteId), HttpStatus.ACCEPTED); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
private final FavoriteService favoriteService; | ||
private final Jwt jwt; | ||
|
||
@ApiOperation("즐겨찾기 추가") | ||
@ApiResponses({ | ||
@ApiResponse( | ||
code = 201, message = "추가 성공" | ||
), | ||
@ApiResponse( | ||
code = 400 | ||
, message = "존재하지 않는 농구장에 접근" | ||
, response = ErrorResponse.class | ||
) | ||
}) | ||
@PostMapping() | ||
public ResponseEntity<FavoriteInsertResponse> insert(@RequestBody FavoriteInsertRequest favoriteInsertRequest, HttpServletRequest request) { | ||
|
||
TokenGetId token = new TokenGetId(request, jwt); | ||
Long userId = token.getUserId(); | ||
|
||
return new ResponseEntity<FavoriteInsertResponse>( | ||
favoriteService.insert(favoriteInsertRequest, userId), HttpStatus.CREATED); | ||
} | ||
|
||
@ApiOperation("즐겨칮기 목록 조회") | ||
@GetMapping() | ||
public ResponseEntity<List<FavoriteLookUpResponse>> getAll(HttpServletRequest request) { | ||
TokenGetId token = new TokenGetId(request, jwt); | ||
Long userId = token.getUserId(); | ||
|
||
return ResponseEntity.ok().body(favoriteService.getAll(userId)); | ||
} | ||
|
||
@ApiOperation("즐겨찾기 삭제(취소)") | ||
@ApiResponses({ | ||
@ApiResponse(code = 204, message = "삭제(취소) 성공") | ||
}) | ||
@DeleteMapping("{favoriteId}") | ||
public ResponseEntity<Void> delete(@PathVariable Long favoriteId, HttpServletRequest request) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분이 ResponseEntity가 응답이 204고 응답 객체이 없어진 걸 말하는 거죠? 이 부분 이따 같이 상의하면 좋을 거 같아요 |
||
TokenGetId token = new TokenGetId(request, jwt); | ||
Long userId = token.getUserId(); | ||
|
||
favoriteService.delete(favoriteId); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/slams/server/favorite/dto/request/FavoriteInsertRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.slams.server.favorite.dto.request; | ||
|
||
import lombok.*; | ||
import org.slams.server.court.entity.Court; | ||
import org.slams.server.favorite.entity.Favorite; | ||
import org.slams.server.user.entity.User; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class FavoriteInsertRequest { | ||
|
||
private String courtId; | ||
|
||
@Builder | ||
public FavoriteInsertRequest(String courtId) { | ||
this.courtId = courtId; | ||
} | ||
|
||
public Favorite toEntity(Court court, User user) { | ||
return new Favorite(court, user); | ||
} | ||
|
||
} |
21 changes: 0 additions & 21 deletions
21
src/main/java/org/slams/server/favorite/dto/request/FavoriteInsertRequestDto.java
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
src/main/java/org/slams/server/favorite/dto/response/FavoriteDeleteResponseDto.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/main/java/org/slams/server/favorite/dto/response/FavoriteInsertResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.slams.server.favorite.dto.response; | ||
|
||
import lombok.Getter; | ||
import org.slams.server.common.api.BaseResponse; | ||
import org.slams.server.court.dto.response.CourtInMapDto; | ||
import org.slams.server.favorite.entity.Favorite; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
public class FavoriteInsertResponse extends BaseResponse { | ||
|
||
private String id; | ||
private CourtInMapDto court; | ||
|
||
private FavoriteInsertResponse(LocalDateTime createdAt, LocalDateTime updatedAt, String id, CourtInMapDto court) { | ||
super(createdAt, updatedAt); | ||
this.id = id; | ||
this.court = court; | ||
} | ||
|
||
public static FavoriteInsertResponse toResponse(Favorite favorite) { | ||
return new FavoriteInsertResponse( | ||
favorite.getCreatedAt(), favorite.getUpdatedAt(), favorite.getId().toString(), CourtInMapDto.toDto(favorite.getCourt())); | ||
} | ||
|
||
} |
30 changes: 0 additions & 30 deletions
30
src/main/java/org/slams/server/favorite/dto/response/FavoriteInsertResponseDto.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오타 수정 굿👍