Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

*/application.yml
*/application-jwt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public ApiResponse<CardFeedResponse> getCardFeed(@PathVariable Long cardId) {
return ApiResponse.onSuccess(cardService.getCardFeed(cardId, userId));
}


@GetMapping("/profile/{userId}/cards")
@Operation(summary = "프로필 화면 피드 미리보기", description = "공유한 카드의 번호와 이미지 url 조회 API")
public ApiResponse<CardResponse.profileCardListDTO> getProfileCardsList(@PathVariable Long userId,
@RequestParam(required = false) Long cursor,
@RequestParam(defaultValue = "15") int size) {
return ApiResponse.onSuccess(cardService.getProfileCardList(userId,size,cursor));

return ApiResponse.onSuccess(cardService.getProfileCardList(userId, size, cursor));
}

@DeleteMapping("/{cardId}")
@Operation(summary = "카드 삭제", description = "카드를 소프트 삭제 처리합니다.")
public ApiResponse<Void> deleteCard(@PathVariable Long cardId) {
Expand All @@ -100,14 +100,12 @@ public ApiResponse<List<TodayCardResponse>> getTodayCards(
}

@Operation(summary = "픽카드 수정", description = "카드의 메모, 레시피, 위치 정보 등을 수정합니다.")
@PutMapping("/api/cards/{cardId}")
@PutMapping("/{cardId}")
public ResponseEntity<ApiResponse<CardDetailResponse>> updateCard(
@Parameter(description = "수정할 카드 ID", example = "12")
@PathVariable Long cardId,
@RequestBody CardUpdateRequest request)
{
@RequestBody CardUpdateRequest request) {
Long userId = 1L;
return ResponseEntity.ok(ApiResponse.onSuccess(cardService.updateCard(cardId, userId, request)));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public static CardResponse.profileCardListDTO toProfileCardList(Long userId, Sli
.map(CardConverter::toProfileCardDto)
.toList())
.build();
}

public static TodayCardResponse toTodayCard(Card card) {
return TodayCardResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ public static class ProfileCardDTO {
private Long cardId;
private String cardImageUrl;
}



@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Schema(title = "TodayCardResponse: 오늘의 식사(카드) 현황 응답 dto")
public static class TodayCardResponse {
@Schema(description = "카드 ID", example = "12")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public interface CardService {
CardResponse.CreateCardResponse createNewCard(CardCreateRequest.CreateCardRequest request, Long userId);
CardDetailResponse getCardDetail(Long cardId, Long userId);
CardFeedResponse getCardFeed(Long cardId, Long userId)
CardFeedResponse getCardFeed(Long cardId, Long userId);
CardResponse.profileCardListDTO getProfileCardList(Long userId, int size, Long cursor);
void deleteCard(Long cardId, Long userId);
List<TodayCardResponse> getTodayCards(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import EatPic.spring.domain.bookmark.repository.BookmarkRepository;
import EatPic.spring.domain.card.converter.CardConverter;
import EatPic.spring.domain.card.dto.request.CardCreateRequest;
import EatPic.spring.domain.card.dto.request.CardCreateRequest.CardUpdateRequest;
import EatPic.spring.domain.card.dto.response.CardResponse;
import EatPic.spring.domain.card.dto.response.CardResponse.CardDetailResponse;
import EatPic.spring.domain.card.dto.response.CardResponse.CardFeedResponse;
import EatPic.spring.domain.card.dto.response.CardResponse.TodayCardResponse;
import EatPic.spring.domain.card.entity.Card;
import EatPic.spring.domain.card.mapping.CardHashtag;
import EatPic.spring.domain.card.repository.CardHashtagRepository;
Expand All @@ -24,6 +22,7 @@
import java.time.LocalTime;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -161,11 +160,13 @@ public CardResponse.profileCardListDTO getProfileCardList(Long userId, int size,
cardSlice = cardRepository.findByUserIdAndIsSharedTrueAndIdLessThanOrderByIdDesc(userId, cursor, pageable);
}
return CardConverter.toProfileCardList(userId, cardSlice);
}

@Override
@Transactional
public void deleteCard(Long cardId, Long userId) {
Card card = cardRepository.findByIdAndIsDeletedFalse(cardId)
.orElseThrow(() -> new ExceptionHandler(ErrorStatus.CARD_NOT_FOUND));
.orElseThrow(() -> new ExceptionHandler(ErrorStatus.CARD_NOT_FOUND));

if (!card.getUser().getId().equals(userId)) {
throw new ExceptionHandler(ErrorStatus.CARD_DELETE_FORBIDDEN);
Expand All @@ -176,40 +177,41 @@ public void deleteCard(Long cardId, Long userId) {

@Override
@Transactional
public List<TodayCardResponse> getTodayCards(Long userId) {
public List<CardResponse.TodayCardResponse> getTodayCards(Long userId) {
User user = userRepository.findUserById(userId);
LocalDate today = LocalDate.now();
List<Card> todayCards = cardRepository.findAllByUserAndCreatedAtBetween(
user,
today.atStartOfDay(),
today.plusDays(1).atStartOfDay()
user,
today.atStartOfDay(),
today.plusDays(1).atStartOfDay()
);

return todayCards.stream()
.map(CardConverter::toTodayCard)
.collect(Collectors.toList());
.map(CardConverter::toTodayCard)
.collect(Collectors.toList());
}

@Override
@Transactional
public CardDetailResponse updateCard(Long cardId, Long userId, CardUpdateRequest request) {
public CardDetailResponse updateCard(Long cardId, Long userId, CardCreateRequest.CardUpdateRequest request) {
Card card = cardRepository.findById(cardId)
.orElseThrow(() -> new ExceptionHandler(ErrorStatus.CARD_NOT_FOUND));
.orElseThrow(() -> new ExceptionHandler(ErrorStatus.CARD_NOT_FOUND));

if (!card.getUser().getId().equals(userId)) {
throw new ExceptionHandler(ErrorStatus.CARD_UPDATE_FORBIDDEN);
}

card.update(
request.getMemo(),
request.getRecipe(),
request.getRecipeUrl(),
request.getLatitude(),
request.getLongitude(),
request.getLocationText(),
request.getIsShared()
request.getMemo(),
request.getRecipe(),
request.getRecipeUrl(),
request.getLatitude(),
request.getLongitude(),
request.getLocationText(),
request.getIsShared()
);
// 수정 후 최신 데이터로 응답
return CardConverter.toCardDetailResponse(card, null); // nextCardId는 수정 시점에는 null로
}


}