From 1f167c0ab7147cd42c2a34197ace64e56350d056 Mon Sep 17 00:00:00 2001 From: ksj000625 Date: Tue, 19 Nov 2024 22:18:11 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[fix]=20Jwt=20Builder=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiserver/common/utils/jwt/JWTUtil.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/site/billbill/apiserver/common/utils/jwt/JWTUtil.java b/src/main/java/site/billbill/apiserver/common/utils/jwt/JWTUtil.java index 36f2061..5e5f368 100644 --- a/src/main/java/site/billbill/apiserver/common/utils/jwt/JWTUtil.java +++ b/src/main/java/site/billbill/apiserver/common/utils/jwt/JWTUtil.java @@ -42,8 +42,8 @@ public JWTUtil( public JwtDto generateJwtDto(String userId, UserRole role) { Date now = new Date(); - Date accessTokenExpiresIn = new Date(now.getTime() + ACCESS_TOKEN_EXPIRE_TIME*1000); - Date refreshTokenExpiresIn = new Date(now.getTime() + REFRESH_TOKEN_EXPIRE_TIME*1000); + Date accessTokenExpiresIn = new Date(now.getTime() + ACCESS_TOKEN_EXPIRE_TIME * 1000); + Date refreshTokenExpiresIn = new Date(now.getTime() + REFRESH_TOKEN_EXPIRE_TIME * 1000); String issuer = "BillBillServer"; @@ -69,12 +69,18 @@ public JwtDto generateJwtDto(String userId, UserRole role) { .claim("type", "RT") .compact(); - return new JwtDto(accessToken, refreshToken, "Bearer", accessTokenExpiresIn.getTime() / 1000, role.name()); + return JwtDto.builder() + .accessToken(accessToken) + .refreshToken(refreshToken) + .grantType("Bearer") + .expiresIn(accessTokenExpiresIn.getTime() / 1000) + .role(role.name()) + .build(); } public boolean isValidAccessToken(String token) { try { - if(getClaims(token).get("type").equals("AT")) return true; + if (getClaims(token).get("type").equals("AT")) return true; } catch (ExpiredJwtException e) { log.error("Bill Access 토큰 시간이 만료 되었습니다. {}", e.getMessage()); return false; @@ -95,7 +101,7 @@ public Claims getClaims(String token) { } public String putUserMDC(Claims claims) { - String userId= claims.getSubject(); + String userId = claims.getSubject(); String role = claims.get("role", String.class); MDC.put(MDC_USER_ID, userId); @@ -119,13 +125,13 @@ public boolean isExpired(String token) { public UserRole getUserRole(String token) { Claims claims = getClaims(token); - String role = claims.get("role", String.class); - return UserRole.valueOf(role); + String role = claims.get("role", String.class); + return UserRole.valueOf(role); } public boolean isValidRefreshToken(String token) { try { - if(getClaims(token).get("type").equals("RT")) return true; + if (getClaims(token).get("type").equals("RT")) return true; } catch (ExpiredJwtException e) { log.error("Bill Refresh 토큰 시간이 만료 되었습니다. {}", e.getMessage()); throw new CustomException(ErrorCode.BadRequest, "Bill Refresh 토큰 시간이 만료되었습니다. ", HttpStatus.BAD_REQUEST); From 3f090bcb6e9165bba3551abda4daf4bfc2f6f0f2 Mon Sep 17 00:00:00 2001 From: ksj000625 Date: Sun, 24 Nov 2024 15:19:14 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[feat]=20=EB=82=B4=20=EA=B8=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/users/controller/UserController.java | 12 +++++ .../dto/response/PostHistoryResponse.java | 40 ++++++++++++++++ .../api/users/service/UserService.java | 3 ++ .../api/users/service/UserServiceImpl.java | 10 ++++ .../common/utils/posts/ItemType.java | 6 +++ .../model/chat/ChatChannelJpaEntity.java | 32 +++++++++++++ .../borrowPosts/ItemDslRepository.java | 5 ++ .../borrowPosts/ItemDslRepositoryImpl.java | 47 ++++++++++++++++--- 8 files changed, 148 insertions(+), 7 deletions(-) create mode 100644 src/main/java/site/billbill/apiserver/api/users/dto/response/PostHistoryResponse.java create mode 100644 src/main/java/site/billbill/apiserver/common/utils/posts/ItemType.java create mode 100644 src/main/java/site/billbill/apiserver/model/chat/ChatChannelJpaEntity.java diff --git a/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java b/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java index 50bc545..1235967 100644 --- a/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java +++ b/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.*; import site.billbill.apiserver.api.users.dto.request.BlacklistRequest; import site.billbill.apiserver.api.users.dto.response.BlacklistResponse; +import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; import site.billbill.apiserver.api.users.dto.response.ProfileResponse; import site.billbill.apiserver.api.users.service.UserService; import site.billbill.apiserver.common.response.BaseResponse; @@ -81,4 +82,15 @@ public BaseResponse withdraw() { userService.withdraw(); return new BaseResponse<>(null); } + + @Operation(summary = "대여중인 글 조회", description = "대여중인 글 조회 API") + @ResponseStatus(HttpStatus.OK) + @GetMapping("/posts/borrowPosts") + public BaseResponse> postsHistory( + @RequestParam(name = "size", defaultValue = "20") int size, + @RequestParam(name = "page", defaultValue = "1") int page + ) { + Pageable pageable = PageRequest.of((page < 1 ? 0 : page - 1), size); + return new BaseResponse<>(userService.getPostHistory(pageable)); + } } diff --git a/src/main/java/site/billbill/apiserver/api/users/dto/response/PostHistoryResponse.java b/src/main/java/site/billbill/apiserver/api/users/dto/response/PostHistoryResponse.java new file mode 100644 index 0000000..891bcb3 --- /dev/null +++ b/src/main/java/site/billbill/apiserver/api/users/dto/response/PostHistoryResponse.java @@ -0,0 +1,40 @@ +package site.billbill.apiserver.api.users.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.AllArgsConstructor; +import lombok.Data; +import site.billbill.apiserver.common.utils.posts.ItemType; + +import java.time.OffsetDateTime; +import java.util.List; + +@Data +@AllArgsConstructor +public class PostHistoryResponse { + @Schema(description = "물품 ID", example = "ITEM-XXXXX...") + private String itemId; +// @Enumerated(EnumType.STRING) +// @Schema(description = "물품 타입", example = "BORROW") +// private ItemType type; + @Schema(description = "물품 이미지 리스트", example = "[\"image\", \"image\"") + private List itemImages; + @Schema(description = "물품 이름", example = "Pronto600 폴라로이드 카메라") + private String title; + @Schema(description = "아이템 상태", example = "3") + private int itemStatus; + @Schema(description = "좋아요 수", example = "12") + private long likeCount; + @Schema(description = "채팅 수", example = "1") + private long chatCount; + @Schema(description = "조회 수", example = "12") + private int viewCount; + @Schema(description = "생성일시", example = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul") + private OffsetDateTime createdAt; + @Schema(description = "수정일시", example = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul") + private OffsetDateTime updatedAt; +} diff --git a/src/main/java/site/billbill/apiserver/api/users/service/UserService.java b/src/main/java/site/billbill/apiserver/api/users/service/UserService.java index 3151a45..ee31287 100644 --- a/src/main/java/site/billbill/apiserver/api/users/service/UserService.java +++ b/src/main/java/site/billbill/apiserver/api/users/service/UserService.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Pageable; import site.billbill.apiserver.api.users.dto.response.BlacklistResponse; +import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; import site.billbill.apiserver.api.users.dto.response.ProfileResponse; import java.util.List; @@ -18,4 +19,6 @@ public interface UserService { void blockCancel(String userId); void withdraw(); + + List getPostHistory(Pageable pageable); } diff --git a/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java b/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java index 85423a8..3249c62 100644 --- a/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java @@ -8,6 +8,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import site.billbill.apiserver.api.users.dto.response.BlacklistResponse; +import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; import site.billbill.apiserver.api.users.dto.response.ProfileResponse; import site.billbill.apiserver.common.enums.exception.ErrorCode; import site.billbill.apiserver.common.utils.jwt.JWTUtil; @@ -15,6 +16,7 @@ import site.billbill.apiserver.model.user.UserBlacklistJpaEntity; import site.billbill.apiserver.model.user.UserIdentityJpaEntity; import site.billbill.apiserver.model.user.UserJpaEntity; +import site.billbill.apiserver.repository.borrowPosts.ItemsRepository; import site.billbill.apiserver.repository.user.UserBlacklistRepository; import site.billbill.apiserver.repository.user.UserIdentityRepository; import site.billbill.apiserver.repository.user.UserRepository; @@ -29,6 +31,7 @@ public class UserServiceImpl implements UserService { private final UserRepository userRepository; private final UserIdentityRepository userIdentityRepository; private final UserBlacklistRepository userBlacklistRepository; + private final ItemsRepository itemsRepository; private final JWTUtil jWTUtil; @Override @@ -98,4 +101,11 @@ public void withdraw() { userRepository.withdrawUserById(userId); } + + @Override + public List getPostHistory(Pageable pageable) { + String userId = MDC.get(JWTUtil.MDC_USER_ID); + + return itemsRepository.getPostHistory(userId, pageable); + } } diff --git a/src/main/java/site/billbill/apiserver/common/utils/posts/ItemType.java b/src/main/java/site/billbill/apiserver/common/utils/posts/ItemType.java new file mode 100644 index 0000000..308bb7d --- /dev/null +++ b/src/main/java/site/billbill/apiserver/common/utils/posts/ItemType.java @@ -0,0 +1,6 @@ +package site.billbill.apiserver.common.utils.posts; + +public enum ItemType { + BORROW, + EXCHANGE +} diff --git a/src/main/java/site/billbill/apiserver/model/chat/ChatChannelJpaEntity.java b/src/main/java/site/billbill/apiserver/model/chat/ChatChannelJpaEntity.java new file mode 100644 index 0000000..f270210 --- /dev/null +++ b/src/main/java/site/billbill/apiserver/model/chat/ChatChannelJpaEntity.java @@ -0,0 +1,32 @@ +package site.billbill.apiserver.model.chat; + + +import jakarta.persistence.*; +import lombok.*; +import site.billbill.apiserver.common.converter.BooleanConverter; +import site.billbill.apiserver.model.BaseTime; +import site.billbill.apiserver.model.post.ItemsJpaEntity; +import site.billbill.apiserver.model.user.UserJpaEntity; + +@Entity @Builder +@Table(name = "chat_channel") +@Getter @Setter +@NoArgsConstructor +@AllArgsConstructor +public class ChatChannelJpaEntity extends BaseTime { + @Id + @Column(name = "channel_id", nullable = false) + private String channelId; + @ManyToOne + @JoinColumn(name="item_id") + private ItemsJpaEntity item; + @ManyToOne + @JoinColumn(name="owner_id") + private UserJpaEntity owner; + @ManyToOne + @JoinColumn(name="contact_id") + private UserJpaEntity contact; + @Column(name = "del_yn", nullable = false) + @Convert(converter = BooleanConverter.class) + private boolean delYn = false; +} diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepository.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepository.java index 2b8251d..6cec925 100644 --- a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepository.java @@ -2,8 +2,13 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; import site.billbill.apiserver.model.post.ItemsJpaEntity; +import java.util.List; + public interface ItemDslRepository { Page findItemsWithConditions(String category, Pageable pageable, String sortField); + + List getPostHistory(String userId, Pageable pageable); } diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java index a9722b9..13a3e84 100644 --- a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java @@ -1,6 +1,9 @@ package site.billbill.apiserver.repository.borrowPosts; import com.querydsl.core.types.OrderSpecifier; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.JPAExpressions; +import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -9,15 +12,15 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; -import site.billbill.apiserver.model.post.ItemsJpaEntity; -import site.billbill.apiserver.model.post.QItemsBorrowJpaEntity; -import site.billbill.apiserver.model.post.QItemsCategoryJpaEntity; -import site.billbill.apiserver.model.post.QItemsJpaEntity; +import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; +import site.billbill.apiserver.model.chat.QChatChannelJpaEntity; +import site.billbill.apiserver.model.post.*; import java.util.List; + @Slf4j @RequiredArgsConstructor -public class ItemDslRepositoryImpl implements ItemDslRepository{ +public class ItemDslRepositoryImpl implements ItemDslRepository { private final JPAQueryFactory queryFactory; @Override @@ -53,7 +56,7 @@ public Page findItemsWithConditions(String category, Pageable pa } else { log.warn("Invalid sort field: {}, no sorting applied.", sortField); } -} + } // 페이징 처리 List content = query.offset(pageable.getOffset()) @@ -95,5 +98,35 @@ private OrderSpecifier getOrderSpecifier(String sortField, Sort.Order sortOrd } } - + @Override + public List getPostHistory(String userId, Pageable pageable) { + QItemsJpaEntity qItems = QItemsJpaEntity.itemsJpaEntity; + QitemsLikeJpaEntity qLike = QitemsLikeJpaEntity.itemsLikeJpaEntity; + QChatChannelJpaEntity qChatChannel = QChatChannelJpaEntity.chatChannelJpaEntity; + + JPAQuery qb = queryFactory.select( + Projections.constructor( + PostHistoryResponse.class, + qItems.id, + qItems.images, + qItems.title, + qItems.itemStatus, + qLike.countDistinct().as("likeCount"), // 좋아요 수 + qChatChannel.countDistinct().as("chatCount"), // 채팅 수 + qItems.viewCount, + qItems.createdAt, + qItems.updatedAt + ) + ) + .from(qItems) + .leftJoin(qLike).on(qItems.id.eq(qLike.items.id).and(qLike.delYn.isFalse())) + .leftJoin(qChatChannel).on(qItems.id.eq(qChatChannel.item.id).and(qChatChannel.delYn.isFalse())) + .where(qItems.owner.userId.eq(userId) + .and(qItems.delYn.isFalse())) + .groupBy(qItems.id) // 그룹핑 필요 + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()); + + return qb.fetch(); + } } From ff1b6c03cbc4caec5a76058b5c5f0277d7523864 Mon Sep 17 00:00:00 2001 From: ksj000625 Date: Sun, 24 Nov 2024 18:39:05 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[feat]=20=EB=8C=80=EC=97=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/users/controller/UserController.java | 19 ++++++- .../dto/response/BorrowHistoryResponse.java | 54 ++++++++++++++++++ .../dto/response/PostHistoryResponse.java | 8 ++- .../api/users/service/UserService.java | 4 ++ .../api/users/service/UserServiceImpl.java | 23 +++++++- .../common/utils/posts/ItemHistoryType.java | 7 +++ .../model/post/BorrowHistJapEntity.java | 38 +++++++++++++ .../borrowPosts/ItemDslRepository.java | 4 ++ .../borrowPosts/ItemDslRepositoryImpl.java | 55 +++++++++++++++++-- 9 files changed, 203 insertions(+), 9 deletions(-) create mode 100644 src/main/java/site/billbill/apiserver/api/users/dto/response/BorrowHistoryResponse.java create mode 100644 src/main/java/site/billbill/apiserver/common/utils/posts/ItemHistoryType.java create mode 100644 src/main/java/site/billbill/apiserver/model/post/BorrowHistJapEntity.java diff --git a/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java b/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java index 1235967..4432899 100644 --- a/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java +++ b/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java @@ -5,6 +5,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.PageRequest; @@ -13,10 +14,12 @@ import org.springframework.web.bind.annotation.*; import site.billbill.apiserver.api.users.dto.request.BlacklistRequest; import site.billbill.apiserver.api.users.dto.response.BlacklistResponse; +import site.billbill.apiserver.api.users.dto.response.BorrowHistoryResponse; import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; import site.billbill.apiserver.api.users.dto.response.ProfileResponse; import site.billbill.apiserver.api.users.service.UserService; import site.billbill.apiserver.common.response.BaseResponse; +import site.billbill.apiserver.common.utils.posts.ItemHistoryType; import java.util.List; @@ -83,9 +86,9 @@ public BaseResponse withdraw() { return new BaseResponse<>(null); } - @Operation(summary = "대여중인 글 조회", description = "대여중인 글 조회 API") + @Operation(summary = "내 글 조회", description = "대여중인 글 조회 API") @ResponseStatus(HttpStatus.OK) - @GetMapping("/posts/borrowPosts") + @GetMapping("/history/posts") public BaseResponse> postsHistory( @RequestParam(name = "size", defaultValue = "20") int size, @RequestParam(name = "page", defaultValue = "1") int page @@ -93,4 +96,16 @@ public BaseResponse> postsHistory( Pageable pageable = PageRequest.of((page < 1 ? 0 : page - 1), size); return new BaseResponse<>(userService.getPostHistory(pageable)); } + + @Operation(summary = "내 대여 기록 보기", description = "내 대여기록 보기 API") + @ResponseStatus(HttpStatus.OK) + @GetMapping("/history/{type}") + public BaseResponse> postsHistory( + @RequestParam(name = "size", defaultValue = "20") int size, + @RequestParam(name = "page", defaultValue = "1") int page, + @PathVariable ItemHistoryType type + ) { + Pageable pageable = PageRequest.of((page < 1 ? 0 : page - 1), size); + return new BaseResponse<>(userService.getPostHistory(pageable, type)); + } } diff --git a/src/main/java/site/billbill/apiserver/api/users/dto/response/BorrowHistoryResponse.java b/src/main/java/site/billbill/apiserver/api/users/dto/response/BorrowHistoryResponse.java new file mode 100644 index 0000000..44e037b --- /dev/null +++ b/src/main/java/site/billbill/apiserver/api/users/dto/response/BorrowHistoryResponse.java @@ -0,0 +1,54 @@ +package site.billbill.apiserver.api.users.dto.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.AllArgsConstructor; +import lombok.Data; +import site.billbill.apiserver.common.utils.posts.ItemHistoryType; + +import java.time.OffsetDateTime; +import java.util.List; + +@Data +@AllArgsConstructor +public class BorrowHistoryResponse { + @Schema(description = "대여 기록 번호", example = "2") + private long borrowSeq; + @Schema(description = "물품 ID", example = "ITEM-XXXXX...") + private String itemId; + @Schema(description = "대여자 ID", example = "USER-XXXXX...") + private String borrowerId; + @Enumerated(EnumType.STRING) + @Schema(description = "물품 타입", example = "BORROWING / BORROWED / EXCHANGE") + private ItemHistoryType type; + @Schema( + description = "물품 이미지 리스트", + type = "array", + example = "[\"image1.jpg\", \"image2.jpg\"]" + ) + private List itemImages; + @Schema(description = "물품 이름", example = "Pronto600 폴라로이드 카메라") + private String title; + @Schema(description = "대여 시작 일자", example = "yyyy-MM-dd") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + private OffsetDateTime startedAt; + @Schema(description = "대여 종료 일자", example = "yyyy-MM-dd") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + private OffsetDateTime endedAt; + @Schema(description = "아이템 상태", example = "3") + private int itemStatus; + @Schema(description = "좋아요 수", example = "12") + private long likeCount; + @Schema(description = "채팅 수", example = "1") + private long chatCount; + @Schema(description = "조회 수", example = "12") + private int viewCount; + @Schema(description = "생성일시", example = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul") + private OffsetDateTime createdAt; + @Schema(description = "수정일시", example = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Seoul") + private OffsetDateTime updatedAt; +} diff --git a/src/main/java/site/billbill/apiserver/api/users/dto/response/PostHistoryResponse.java b/src/main/java/site/billbill/apiserver/api/users/dto/response/PostHistoryResponse.java index 891bcb3..491ee0b 100644 --- a/src/main/java/site/billbill/apiserver/api/users/dto/response/PostHistoryResponse.java +++ b/src/main/java/site/billbill/apiserver/api/users/dto/response/PostHistoryResponse.java @@ -16,10 +16,14 @@ public class PostHistoryResponse { @Schema(description = "물품 ID", example = "ITEM-XXXXX...") private String itemId; -// @Enumerated(EnumType.STRING) + // @Enumerated(EnumType.STRING) // @Schema(description = "물품 타입", example = "BORROW") // private ItemType type; - @Schema(description = "물품 이미지 리스트", example = "[\"image\", \"image\"") + @Schema( + description = "물품 이미지 리스트", + type = "array", + example = "[\"image1.jpg\", \"image2.jpg\"]" + ) private List itemImages; @Schema(description = "물품 이름", example = "Pronto600 폴라로이드 카메라") private String title; diff --git a/src/main/java/site/billbill/apiserver/api/users/service/UserService.java b/src/main/java/site/billbill/apiserver/api/users/service/UserService.java index ee31287..a0c6977 100644 --- a/src/main/java/site/billbill/apiserver/api/users/service/UserService.java +++ b/src/main/java/site/billbill/apiserver/api/users/service/UserService.java @@ -2,8 +2,10 @@ import org.springframework.data.domain.Pageable; import site.billbill.apiserver.api.users.dto.response.BlacklistResponse; +import site.billbill.apiserver.api.users.dto.response.BorrowHistoryResponse; import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; import site.billbill.apiserver.api.users.dto.response.ProfileResponse; +import site.billbill.apiserver.common.utils.posts.ItemHistoryType; import java.util.List; @@ -21,4 +23,6 @@ public interface UserService { void withdraw(); List getPostHistory(Pageable pageable); + + List getPostHistory(Pageable pageable, ItemHistoryType type); } diff --git a/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java b/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java index 3249c62..5ad66d5 100644 --- a/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java @@ -8,10 +8,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import site.billbill.apiserver.api.users.dto.response.BlacklistResponse; +import site.billbill.apiserver.api.users.dto.response.BorrowHistoryResponse; import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; import site.billbill.apiserver.api.users.dto.response.ProfileResponse; import site.billbill.apiserver.common.enums.exception.ErrorCode; import site.billbill.apiserver.common.utils.jwt.JWTUtil; +import site.billbill.apiserver.common.utils.posts.ItemHistoryType; import site.billbill.apiserver.exception.CustomException; import site.billbill.apiserver.model.user.UserBlacklistJpaEntity; import site.billbill.apiserver.model.user.UserIdentityJpaEntity; @@ -97,7 +99,7 @@ public void withdraw() { Optional user = userRepository.findById(userId); - if(user.isEmpty()) throw new CustomException(ErrorCode.NotFound, "존재하지 않는 회원입니다.", HttpStatus.NOT_FOUND); + if (user.isEmpty()) throw new CustomException(ErrorCode.NotFound, "존재하지 않는 회원입니다.", HttpStatus.NOT_FOUND); userRepository.withdrawUserById(userId); } @@ -108,4 +110,23 @@ public List getPostHistory(Pageable pageable) { return itemsRepository.getPostHistory(userId, pageable); } + + @Override + public List getPostHistory(Pageable pageable, ItemHistoryType type) { + String userId = MDC.get(JWTUtil.MDC_USER_ID); + + List borrowHistoryList; + +// switch (type) { +// case BORROWED: +// borrowHistoryList = +// break; +// case BORROWING: +// break; +// case EXCHANGE: +// break; +// } + + return itemsRepository.getBorrowHistory(userId,pageable,type); + } } diff --git a/src/main/java/site/billbill/apiserver/common/utils/posts/ItemHistoryType.java b/src/main/java/site/billbill/apiserver/common/utils/posts/ItemHistoryType.java new file mode 100644 index 0000000..e558628 --- /dev/null +++ b/src/main/java/site/billbill/apiserver/common/utils/posts/ItemHistoryType.java @@ -0,0 +1,7 @@ +package site.billbill.apiserver.common.utils.posts; + +public enum ItemHistoryType { + BORROWING, + BORROWED, + EXCHANGE +} diff --git a/src/main/java/site/billbill/apiserver/model/post/BorrowHistJapEntity.java b/src/main/java/site/billbill/apiserver/model/post/BorrowHistJapEntity.java new file mode 100644 index 0000000..397857d --- /dev/null +++ b/src/main/java/site/billbill/apiserver/model/post/BorrowHistJapEntity.java @@ -0,0 +1,38 @@ +package site.billbill.apiserver.model.post; + +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.CreationTimestamp; +import site.billbill.apiserver.common.converter.BooleanConverter; +import site.billbill.apiserver.model.BaseTime; +import site.billbill.apiserver.model.user.UserJpaEntity; + +import java.time.OffsetDateTime; + +@Entity +@Builder +@Table(name = "borrow_hist") +@Getter @Setter +@NoArgsConstructor +@AllArgsConstructor +public class BorrowHistJapEntity extends BaseTime { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "borrow_seq", nullable = false) + private long borrowSeq; + @ManyToOne + @JoinColumn(name = "item_id", nullable = false) + private ItemsJpaEntity item; + @ManyToOne + @JoinColumn(name = "borrower_id", nullable = false) + private UserJpaEntity borrower; + @Column(name = "started_at", nullable = false) + private OffsetDateTime startedAt; + @Column(name = "ended_at", nullable = false) + private OffsetDateTime endedAt; + @Convert(converter = BooleanConverter.class) + @Column(name = "use_yn", nullable = false) + private boolean useYn = true; + @Convert(converter = BooleanConverter.class) + @Column(name = "del_yn", nullable = false) + private boolean delYn = false; +} diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepository.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepository.java index 6cec925..f41e5e7 100644 --- a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepository.java +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepository.java @@ -2,7 +2,9 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import site.billbill.apiserver.api.users.dto.response.BorrowHistoryResponse; import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; +import site.billbill.apiserver.common.utils.posts.ItemHistoryType; import site.billbill.apiserver.model.post.ItemsJpaEntity; import java.util.List; @@ -11,4 +13,6 @@ public interface ItemDslRepository { Page findItemsWithConditions(String category, Pageable pageable, String sortField); List getPostHistory(String userId, Pageable pageable); + + List getBorrowHistory(String userId, Pageable pageable, ItemHistoryType type); } diff --git a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java index 13a3e84..e09783a 100644 --- a/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java +++ b/src/main/java/site/billbill/apiserver/repository/borrowPosts/ItemDslRepositoryImpl.java @@ -2,8 +2,7 @@ import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.Projections; -import com.querydsl.jpa.JPAExpressions; -import com.querydsl.jpa.JPQLQuery; +import com.querydsl.core.types.dsl.Expressions; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; @@ -12,7 +11,9 @@ import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; +import site.billbill.apiserver.api.users.dto.response.BorrowHistoryResponse; import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse; +import site.billbill.apiserver.common.utils.posts.ItemHistoryType; import site.billbill.apiserver.model.chat.QChatChannelJpaEntity; import site.billbill.apiserver.model.post.*; @@ -111,8 +112,8 @@ public List getPostHistory(String userId, Pageable pageable qItems.images, qItems.title, qItems.itemStatus, - qLike.countDistinct().as("likeCount"), // 좋아요 수 - qChatChannel.countDistinct().as("chatCount"), // 채팅 수 + qLike.countDistinct().as("likeCount"), + qChatChannel.countDistinct().as("chatCount"), qItems.viewCount, qItems.createdAt, qItems.updatedAt @@ -129,4 +130,50 @@ public List getPostHistory(String userId, Pageable pageable return qb.fetch(); } + + @Override + public List getBorrowHistory(String userId, Pageable pageable, ItemHistoryType type) { + QItemsJpaEntity qItems = QItemsJpaEntity.itemsJpaEntity; + QitemsLikeJpaEntity qLike = QitemsLikeJpaEntity.itemsLikeJpaEntity; + QChatChannelJpaEntity qChatChannel = QChatChannelJpaEntity.chatChannelJpaEntity; + QBorrowHistJapEntity qBorrowHist = QBorrowHistJapEntity.borrowHistJapEntity; + + JPAQuery qb = queryFactory.select( + Projections.constructor( + BorrowHistoryResponse.class, + qBorrowHist.borrowSeq, + qItems.id, + qItems.owner.userId.as("borrowerId"), + Expressions.constant(type), + qItems.images, + qItems.title, + qBorrowHist.startedAt.as("startedAt"), + qBorrowHist.endedAt.as("endedAt"), + qItems.itemStatus, + qLike.countDistinct().as("likeCount"), + qChatChannel.countDistinct().as("chatCount"), + qItems.viewCount, + qItems.createdAt, + qItems.updatedAt + ) + ) + .from(qItems) + .leftJoin(qLike).on(qItems.id.eq(qLike.items.id).and(qLike.delYn.isFalse())) + .leftJoin(qChatChannel).on(qItems.id.eq(qChatChannel.item.id).and(qChatChannel.delYn.isFalse())) + .rightJoin(qBorrowHist).on(qItems.id.eq(qBorrowHist.item.id).and(qBorrowHist.delYn.isFalse())) + .where(qItems.delYn.isFalse()); + + switch (type) { + case BORROWED -> qb.where(qItems.owner.userId.eq(userId)); + case BORROWING -> qb.where(qBorrowHist.borrower.userId.eq(userId)); + case EXCHANGE -> { + } + } + + qb.groupBy(qItems.id) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()); + + return qb.fetch(); + } } From 18dfb7696461f569235f2f4df3f9435f5e380fc7 Mon Sep 17 00:00:00 2001 From: ksj000625 Date: Sun, 24 Nov 2024 18:40:22 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[fix]=20=EC=A4=91=EA=B0=84=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=EC=9A=A9=20=EC=A3=BC=EC=84=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../site/billbill/apiserver/common/utils/PortOneUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/site/billbill/apiserver/common/utils/PortOneUtil.java b/src/main/java/site/billbill/apiserver/common/utils/PortOneUtil.java index 440d4a9..a7f440b 100644 --- a/src/main/java/site/billbill/apiserver/common/utils/PortOneUtil.java +++ b/src/main/java/site/billbill/apiserver/common/utils/PortOneUtil.java @@ -13,8 +13,8 @@ @RequiredArgsConstructor @AllArgsConstructor public class PortOneUtil { - @Value("${portone.api-secret}") - private String apiSecret; +// @Value("${portone.api-secret}") +// private String apiSecret; private WebClient webClient = WebClient.builder().baseUrl("https://api.portone.io").build(); public boolean getIdentityVerification(IdentityVerificationRequest request) {