Skip to content

Commit

Permalink
Merge pull request #33 from depromeet/feature/#25
Browse files Browse the repository at this point in the history
[Feature][#25] 카드 메모 api, 카드 api 수정
  • Loading branch information
sejoon00 authored Aug 6, 2024
2 parents acdc2cf + 95c9446 commit 8fbe954
Show file tree
Hide file tree
Showing 40 changed files with 1,237 additions and 1,361 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ dependencies {
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// queryDSL
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

//s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.server.bbo_gak.domain.card.controller;

import com.server.bbo_gak.domain.card.dto.request.CardContentUpdateRequest;
import com.server.bbo_gak.domain.card.dto.request.CardCreateRequest;
import com.server.bbo_gak.domain.card.dto.request.CardTitleUpdateRequest;
import com.server.bbo_gak.domain.card.dto.response.CardCreateResponse;
import com.server.bbo_gak.domain.card.dto.response.CardGetResponse;
import com.server.bbo_gak.domain.card.dto.response.CardGetsResponse;
import com.server.bbo_gak.domain.card.dto.response.CardListGetResponse;
import com.server.bbo_gak.domain.card.dto.response.CardTypeCountGetResponse;
import com.server.bbo_gak.domain.card.service.CardService;
import com.server.bbo_gak.domain.user.entity.User;
Expand Down Expand Up @@ -43,7 +44,7 @@ public ResponseEntity<CardGetResponse> getCardDetail(
}

@GetMapping("/cards")
public ResponseEntity<List<CardGetsResponse>> getCardList(
public ResponseEntity<List<CardListGetResponse>> getCardList(
@AuthUser User user,
@RequestParam("type") String type) {

Expand All @@ -53,18 +54,9 @@ public ResponseEntity<List<CardGetsResponse>> getCardList(
@PostMapping("/card")
public ResponseEntity<CardCreateResponse> createCard(
@AuthUser User user,
@RequestParam("type") String type) {
@RequestBody CardCreateRequest cardCreateRequest) {

return ResponseEntity.ok(cardService.createCard(user, type));
}

@PostMapping("/cards/{card-id}/tag/{tag-id}")
public ResponseEntity<Void> addCardTag(
@AuthUser User user,
@PathVariable("card-id") Long cardId, @PathVariable("tag-id") Long tagId) {

cardService.addCardTag(user, cardId, tagId);
return ResponseEntity.ok().body(null);
return ResponseEntity.ok(cardService.createCard(user, cardCreateRequest));
}

@PutMapping("/cards/{card-id}/title")
Expand Down Expand Up @@ -98,16 +90,4 @@ public ResponseEntity<Void> deleteCard(
cardService.deleteCard(user, cardId);
return ResponseEntity.ok().body(null);
}

@DeleteMapping("/cards/{card-id}/tag/{tag-id}")
public ResponseEntity<Void> deleteCardTag(
@AuthUser User user,
@PathVariable("card-id") Long cardId, @PathVariable("tag-id") Long tagId
) {

cardService.deleteCardTag(user, cardId, tagId);
return ResponseEntity.ok().body(null);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.server.bbo_gak.domain.card.controller;

import com.server.bbo_gak.domain.card.dto.request.CardMemoContentUpdateRequest;
import com.server.bbo_gak.domain.card.dto.request.CardMemoCreateRequest;
import com.server.bbo_gak.domain.card.dto.response.CardMemoCreateResponse;
import com.server.bbo_gak.domain.card.dto.response.CardMemoGetResponse;
import com.server.bbo_gak.domain.card.service.CardMemoService;
import com.server.bbo_gak.domain.user.entity.User;
import com.server.bbo_gak.global.annotation.AuthUser;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/cards")
@RequiredArgsConstructor
public class CardMemoController {

private final CardMemoService cardMemoService;

@GetMapping("/{card-id}/card-memo")
public ResponseEntity<List<CardMemoGetResponse>> getCardMemoList(
@AuthUser User user,
@PathVariable("card-id") Long cardId) {

return ResponseEntity.ok(cardMemoService.getCardMemoList(user, cardId));
}

@PostMapping("/{card-id}/card-memo")
public ResponseEntity<CardMemoCreateResponse> createCardMemo(
@AuthUser User user,
@PathVariable("card-id") Long cardId,
@RequestBody CardMemoCreateRequest request) {

return ResponseEntity.ok(cardMemoService.createCardMemo(user, request, cardId));
}

@PutMapping("/{card-id}/card-momo/{card-memo-id}/content")
public ResponseEntity<Void> updateCardMemoContent(
@AuthUser User user,
@PathVariable("card-id") Long cardId,
@PathVariable("card-memo-id") Long cardMemoId,
@RequestBody CardMemoContentUpdateRequest request) {

cardMemoService.updateCardMemo(user, request, cardId, cardMemoId);
return ResponseEntity.ok().body(null);
}

@DeleteMapping("/{card-id}/card-memo/{card-memo-id}")
public ResponseEntity<Void> deleteCardMemo(
@AuthUser User user,
@PathVariable("card-id") Long cardId,
@PathVariable("card-memo-id") Long cardMemoId) {

cardMemoService.deleteCardMemo(user, cardId, cardMemoId);
return ResponseEntity.ok().body(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.server.bbo_gak.domain.card.controller;

import com.server.bbo_gak.domain.card.dto.response.TagGetResponse;
import com.server.bbo_gak.domain.card.service.TagService;
import com.server.bbo_gak.domain.user.entity.User;
import com.server.bbo_gak.global.annotation.AuthUser;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1")
@RequiredArgsConstructor
public class TagController {

private final TagService tagService;

@GetMapping("/tags")
public ResponseEntity<List<TagGetResponse>> getAllTagList() {
return ResponseEntity.ok(tagService.getAllTagList());
}

@GetMapping("/cards/{card-id}/tags")
public ResponseEntity<List<TagGetResponse>> getcCardTagList(
@AuthUser User user,
@PathVariable("card-id") Long cardId) {

return ResponseEntity.ok(tagService.getTagListInCard(user, cardId));
}

@PostMapping("/cards/{card-id}/tag/{tag-id}")
public ResponseEntity<Void> addCardTag(
@AuthUser User user,
@PathVariable("card-id") Long cardId, @PathVariable("tag-id") Long tagId) {

tagService.addTagToCard(user, cardId, tagId);
return ResponseEntity.ok(null);
}

@DeleteMapping("/cards/{card-id}/tag/{tag-id}")
public ResponseEntity<Void> deleteCardTag(
@AuthUser User user,
@PathVariable("card-id") Long cardId, @PathVariable("tag-id") Long tagId
) {

tagService.deleteTagFromCard(user, cardId, tagId);
return ResponseEntity.ok(null);
}


}
44 changes: 44 additions & 0 deletions src/main/java/com/server/bbo_gak/domain/card/dao/CardDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.server.bbo_gak.domain.card.dao;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.server.bbo_gak.domain.card.entity.Card;
import com.server.bbo_gak.domain.card.entity.CardTypeValue;
import com.server.bbo_gak.domain.card.entity.QCard;
import com.server.bbo_gak.domain.card.entity.QCardType;
import com.server.bbo_gak.domain.user.entity.User;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
@RequiredArgsConstructor
public class CardDao {

private final JPAQueryFactory query;

public List<Card> findAllByUserIdAndCardTypeValueList(User user, CardTypeValue[] cardTypeValueList) {

QCard qCard = QCard.card;
QCardType qCardType = QCardType.cardType;

return query.selectFrom(qCard)
.leftJoin(qCard.cardTypeList, qCardType).fetchJoin()
.where(qCard.user.id.eq(user.getId()).and(qCardType.cardTypeValue.in(cardTypeValueList))).distinct()
.fetch();
}

public List<Card> findAllByUserIdAndCardTypeValue(User user, CardTypeValue cardTypeValue) {

QCard qCard = QCard.card;
QCardType qCardType = QCardType.cardType;

return query.selectFrom(qCard)
.leftJoin(qCard.cardTypeList, qCardType).fetchJoin()
.where(qCard.user.id.eq(user.getId()).and(qCardType.cardTypeValue.eq(cardTypeValue))).distinct()
.fetch();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.server.bbo_gak.domain.card.dao;

import com.server.bbo_gak.domain.card.entity.Card;
import com.server.bbo_gak.domain.card.entity.CardMemo;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CardMemoRepository extends JpaRepository<CardMemo, Long> {

Optional<CardMemo> findByIdAndCard(Long id, Card card);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.server.bbo_gak.domain.card.dao;

import com.server.bbo_gak.domain.card.entity.Card;
import com.server.bbo_gak.domain.card.entity.CardType;
import com.server.bbo_gak.domain.user.entity.User;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CardRepository extends JpaRepository<Card, Long> {

Optional<Card> findByIdAndUserId(Long id, Long userId);
Optional<Card> findByIdAndUser(Long id, User user);

List<Card> findAllByUserId(Long userId);

List<Card> findAllByUserIdAndCardType(Long userId, CardType cardType);
List<Card> findAllByUser(User user);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.server.bbo_gak.domain.card.dao;

import com.server.bbo_gak.domain.card.entity.CardType;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CardTypeRepository extends JpaRepository<CardType, Long> {

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.server.bbo_gak.domain.card.dao;

import com.server.bbo_gak.domain.card.entity.Tag;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TagRepository extends JpaRepository<Tag, Long> {

List<Tag> findAllByIdIsNotIn(List<Long> idList);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.server.bbo_gak.domain.card.dto.request;

import jakarta.validation.constraints.Size;
import java.util.List;

public record CardCreateRequest(

@Size(min = 1, max = 3)
List<String> cardTypeValueList,

@Size(max = 3)
List<Long> tagIdList
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.server.bbo_gak.domain.card.dto.request;

public record CardMemoContentUpdateRequest(
String content
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.server.bbo_gak.domain.card.dto.request;

public record CardMemoCreateRequest(
String content
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

@Builder(access = AccessLevel.PRIVATE)
public record CardCreateResponse(
Long cardId,
String type
Long cardId
) {

public static CardCreateResponse of(Long cardId, String type) {
public static CardCreateResponse of(Long cardId) {
return CardCreateResponse.builder()
.cardId(cardId)
.type(type)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,27 @@
public record CardGetResponse(
String title,
String content,
String updateDate,
String type,
List<CardTagResponse> cardTagList
String updatedDate,
List<String> cardTypeValueList,
List<TagGetResponse> tagList
) {

public static CardGetResponse of(Card card, List<CardTag> cardTagList) {

List<TagGetResponse> tagGetResponseList = cardTagList.stream()
.map(cardTag -> TagGetResponse.from(cardTag.getTag()))
.toList();

List<String> cardTypeValueList = card.getCardTypeList().stream()
.map(cardType -> cardType.getCardTypeValue().getValue())
.toList();

return CardGetResponse.builder()
.title(card.getTitle())
.content(card.getContent())
.updateDate(card.getUpdatedDate().format(BaseDateTimeFormatter.getLocalDateTimeFormatter()))
.type(card.getCardType().getValue())
.cardTagList(cardTagList.stream().map(CardTagResponse::of).toList())
.updatedDate(card.getUpdatedDate().format(BaseDateTimeFormatter.getLocalDateTimeFormatter()))
.cardTypeValueList(cardTypeValueList)
.tagList(tagGetResponseList)
.build();
}

@Builder(access = AccessLevel.PRIVATE)
public record CardTagResponse(
Long id,
String name,
String type
) {

public static CardTagResponse of(CardTag cardTag) {
return CardTagResponse.builder()
.id(cardTag.getId())
.name(cardTag.getTag().getName())
.type(cardTag.getTag().getTagType().getValue())
.build();
}
}
}
Loading

0 comments on commit 8fbe954

Please sign in to comment.