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

fix/favorite 55 - response의 id type을 Long -> String으로 변환 #56

Merged
merged 13 commits into from
Jun 19, 2022
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
Expand Up @@ -44,7 +44,7 @@ public ChatContentsResponse toDto(ChatContents chatContents){
.build()
)
.createdAt(chatContents.getCreatedAt())
.updatedAt(chatContents.getUpdateAt())
.updatedAt(chatContents.getUpdatedAt())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오타 수정 굿👍

.build();
}
if (chatContents.getChatContentType().equals(ChatContentType.LOUDSPEAKER)){
Expand All @@ -64,7 +64,7 @@ public ChatContentsResponse toDto(ChatContents chatContents){
.startTime(chatContents.getChatLoudSpeakerContent().getStartTime())
.build())
.createdAt(chatContents.getCreatedAt())
.updatedAt(chatContents.getUpdateAt())
.updatedAt(chatContents.getUpdatedAt())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ChatroomResponse toDto(UserChatroomMapping userChatroomMapping){
.courtId(userChatroomMapping.getCourtChatroomMapping().getCourt().getId())
.courtName(userChatroomMapping.getCourtChatroomMapping().getCourt().getName())
.createdAt(userChatroomMapping.getCreatedAt())
.updatedAt(userChatroomMapping.getCourtChatroomMapping().getUpdateAt())
.updatedAt(userChatroomMapping.getCourtChatroomMapping().getUpdatedAt())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface CourtChatroomMappingRepository extends JpaRepository<CourtChatr

@Transactional
@Modifying()
@Query("UPDATE CourtChatroomMapping c SET c.updateAt = current_timestamp WHERE c.court.id =:courtId")
@Query("UPDATE CourtChatroomMapping c SET c.updatedAt = current_timestamp WHERE c.court.id =:courtId")
void updateUpdatedAtByCourtId(
@Param("courtId") Long courtId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
public interface UserChatroomMappingRepository extends JpaRepository<UserChatroomMapping, Long> {

@Query("SELECT u FROM UserChatroomMapping u WHERE u.user.id = :userId AND u.id >= :lastId ORDER BY u.courtChatroomMapping.updateAt ASC")
@Query("SELECT u FROM UserChatroomMapping u WHERE u.user.id = :userId AND u.id >= :lastId ORDER BY u.courtChatroomMapping.updatedAt ASC")
List<UserChatroomMapping> findAllByUserIdMoreThenLastIdByCreated(
@Param("userId") Long userId,
@Param("lastId") Long lastId,
Pageable pageable
);

@Query("SELECT u FROM UserChatroomMapping u WHERE u.user.id = :userId ORDER BY u.courtChatroomMapping.updateAt DESC")
@Query("SELECT u FROM UserChatroomMapping u WHERE u.user.id = :userId ORDER BY u.courtChatroomMapping.updatedAt DESC")
List<UserChatroomMapping> findAllByUserIdByCreated(
@Param("userId") Long userId,
Pageable pageable
Expand All @@ -36,14 +36,14 @@ void deleteUserChatRoomByCourtId(
@Param("userId") Long userId
);

@Query("SELECT u.id FROM UserChatroomMapping u WHERE u.user.id = :userId AND u.id >= :lastId ORDER BY u.courtChatroomMapping.updateAt ASC")
@Query("SELECT u.id FROM UserChatroomMapping u WHERE u.user.id = :userId AND u.id >= :lastId ORDER BY u.courtChatroomMapping.updatedAt ASC")
List<String> findIdByUserIdMoreThenLastIdByCreated(
@Param("userId") Long userId,
@Param("lastId") Long lastId,
Pageable pageable
);

@Query("SELECT u.id FROM UserChatroomMapping u WHERE u.user.id = :userId ORDER BY u.courtChatroomMapping.updateAt DESC")
@Query("SELECT u.id FROM UserChatroomMapping u WHERE u.user.id = :userId ORDER BY u.courtChatroomMapping.updatedAt DESC")
List<String> findIdByUserIdByCreated(
@Param("userId") Long userId,
Pageable pageable
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/slams/server/common/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public abstract class BaseEntity {

@LastModifiedDate
@Column(name = "updated_at") // entity 변경할때 시간이 자동 저장
private LocalDateTime updateAt;
private LocalDateTime updatedAt;

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public enum ErrorCode {
NOT_FORBIDDEN_RESERVATION(403,"권한이 없습니다"),

// Favorite
NOT_EXIST_FAVORITE(404,"존재하지 않는 즐겨찾기입니다."),

FAVORITE_NOT_FOUND(400,"Favorite Not Found"),

// Follow
FOLLOW_ALREADY_EXIST(400, "Follow Already Exists"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private CourtDetailDto(String id, String name, double latitude, double longitude

public static CourtDetailDto toDto(Court court) {
return new CourtDetailDto(court.getId().toString(), court.getName(), court.getLatitude(), court.getLongitude(),
court.getImage(), court.getBasketCount(), court.getTexture(), court.getCreatedAt(), court.getUpdateAt());
court.getImage(), court.getBasketCount(), court.getTexture(), court.getCreatedAt(), court.getUpdatedAt());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.*;
import org.slams.server.common.api.BaseResponse;
import org.slams.server.court.entity.Court;
import org.slams.server.court.entity.Texture;

import java.time.LocalDateTime;

Expand All @@ -25,7 +24,7 @@ private CourtInMapDto(String id, String name, double latitude, double longitude,

public static CourtInMapDto toDto(Court court) {
return new CourtInMapDto(court.getId().toString(), court.getName(), court.getLatitude(), court.getLongitude(),
court.getCreatedAt(), court.getUpdateAt());
court.getCreatedAt(), court.getUpdatedAt());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private NewCourtDto(String id, String name, double latitude, double longitude,
public static NewCourtDto toDto(NewCourt newCourt) {
return new NewCourtDto(newCourt.getId().toString(), newCourt.getName(), newCourt.getLatitude(), newCourt.getLongitude(),
newCourt.getImage(), newCourt.getTexture(), newCourt.getBasketCount(), newCourt.getStatus(),
newCourt.getCreatedAt(), newCourt.getUpdateAt());
newCourt.getCreatedAt(), newCourt.getUpdatedAt());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private NewCourtResponse(String id, String name, double latitude, double longitu
public static NewCourtResponse toResponse(NewCourt newCourt, User supervisor) {
return new NewCourtResponse(newCourt.getId().toString(), newCourt.getName(), newCourt.getLatitude(), newCourt.getLongitude(),
newCourt.getImage(), newCourt.getTexture(), newCourt.getBasketCount(), newCourt.getStatus(),
newCourt.getCreatedAt(), newCourt.getUpdateAt(), SupervisorDto.toDto(supervisor));
newCourt.getCreatedAt(), newCourt.getUpdatedAt(), SupervisorDto.toDto(supervisor));
}

}
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) {

Choose a reason for hiding this comment

The 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();
}

}
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);
}

}

This file was deleted.

This file was deleted.

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()));
}

}

This file was deleted.

Loading