From 02fe3331de5f14a03ab5f28013c3351b39809f25 Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Fri, 8 Mar 2024 18:11:34 +0900 Subject: [PATCH 01/13] =?UTF-8?q?*=201=EC=B0=A8=20=EB=B2=A0=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kernel360/bbs/code/BBSBusinessCode.java | 33 +++++++ .../com/kernel360/bbs/code/BBSErrorCode.java | 31 ++++++ .../bbs/controller/BBSController.java | 43 +++++++++ .../java/com/kernel360/bbs/dto/BBSDto.java | 73 ++++++++++++++ .../com/kernel360/bbs/enumset/BBSType.java | 10 ++ .../bbs/repository/BBSRepository.java | 11 +++ .../bbs/repository/BBSRepositoryDSL.java | 4 + .../bbs/repository/BBSRepositoryDSLImpl.java | 95 +++++++++++++++++++ .../com/kernel360/bbs/service/BBSService.java | 19 ++++ .../config/AuditConfig.java | 4 +- .../java/com/kernel360/bbs/entity/BBS.java | 50 ++++++++++ .../bbs/repository/BBSRepositoryJPA.java | 8 ++ 12 files changed, 379 insertions(+), 2 deletions(-) create mode 100644 module-api/src/main/java/com/kernel360/bbs/code/BBSBusinessCode.java create mode 100644 module-api/src/main/java/com/kernel360/bbs/code/BBSErrorCode.java create mode 100644 module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java create mode 100644 module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java create mode 100644 module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java create mode 100644 module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java create mode 100644 module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java create mode 100644 module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java create mode 100644 module-api/src/main/java/com/kernel360/bbs/service/BBSService.java rename module-api/src/main/java/com/kernel360/{member => global}/config/AuditConfig.java (91%) create mode 100644 module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java create mode 100644 module-domain/src/main/java/com/kernel360/bbs/repository/BBSRepositoryJPA.java diff --git a/module-api/src/main/java/com/kernel360/bbs/code/BBSBusinessCode.java b/module-api/src/main/java/com/kernel360/bbs/code/BBSBusinessCode.java new file mode 100644 index 00000000..4efccfbc --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/code/BBSBusinessCode.java @@ -0,0 +1,33 @@ +package com.kernel360.bbs.code; + +import com.kernel360.code.BusinessCode; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@RequiredArgsConstructor +public enum BBSBusinessCode implements BusinessCode { + + SUCCESS_REQUEST_GET_BBS(HttpStatus.OK.value(), "BBC001", "게시판 목록 조회 성공"), + SUCCESS_REQUEST_CREATED_BBS(HttpStatus.CREATED.value(), "BBC002", "게시글 작성 성공"), + SUCCESS_REQUEST_MODIFIED_BBS(HttpStatus.OK.value(), "BBC003", "게시글 수정 성공"), + SUCCESS_REQUEST_DELETE_BBS(HttpStatus.OK.value(), "BBC004", "게시글 삭제 성공"); + + private final int status; + private final String code; + private final String message; + + @Override + public int getStatus() { + return 0; + } + + @Override + public String getCode() { + return null; + } + + @Override + public String getMessage() { + return null; + } +} diff --git a/module-api/src/main/java/com/kernel360/bbs/code/BBSErrorCode.java b/module-api/src/main/java/com/kernel360/bbs/code/BBSErrorCode.java new file mode 100644 index 00000000..e7b0780d --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/code/BBSErrorCode.java @@ -0,0 +1,31 @@ +package com.kernel360.bbs.code; + +import com.kernel360.code.ErrorCode; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@RequiredArgsConstructor +public enum BBSErrorCode implements ErrorCode { + + FAILED_GET_BBS_LIST(HttpStatus.NO_CONTENT.value(), "BMC001", "게시판 목록을 찾을 수 없음."), + FAILED_GET_BBS_ONE(HttpStatus.NO_CONTENT.value(), "BMC002", "게시글을 찾을 수 없음."); + + private final int status; + private final String code; + private final String message; + + @Override + public int getStatus() { + return 0; + } + + @Override + public String getCode() { + return null; + } + + @Override + public String getMessage() { + return null; + } +} diff --git a/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java b/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java new file mode 100644 index 00000000..e7afb361 --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java @@ -0,0 +1,43 @@ +package com.kernel360.bbs.controller; + +import com.kernel360.bbs.code.BBSBusinessCode; +import com.kernel360.bbs.dto.BBSDto; +import com.kernel360.bbs.service.BBSService; +import com.kernel360.response.ApiResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController("/bbs") +@RequiredArgsConstructor +public class BBSController { + private final BBSService bbsService; + + @GetMapping("") + public ResponseEntity>> getBBS( + @RequestParam(value = "sortType", defaultValue = "latest")String sortType, + @RequestParam(value = "keyword", required = false) String keyword, Pageable pageable + ){ + + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS, bbsService.getBBSWithCondition(sortType, keyword, pageable)); + } + + @PostMapping("/save") + public ResponseEntity> saveBBS(@RequestBody BBSDto bbsDto){ + + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); + } + + @PatchMapping("/modifiy") + public ResponseEntity> modifyBBS(@RequestBody BBSDto bbsDto){ + + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); + } + + @DeleteMapping("/delete") + public ResponseEntity> deleteBBS(@RequestBody BBSDto bbsDto){ + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); + } +} diff --git a/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java b/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java new file mode 100644 index 00000000..01e93ef8 --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java @@ -0,0 +1,73 @@ +package com.kernel360.bbs.dto; + +import com.kernel360.bbs.entity.BBS; +import com.kernel360.member.entity.Member; +import org.springframework.cglib.core.Local; + +import java.io.Serializable; +import java.time.LocalDate; + +/** + * DTO for {@link com.kernel360.bbs.entity.BBS} + */ +public record BBSDto( + Long bbsNo, + Long upperNo, + String type, + String title, + String contents, + Boolean isVisible, + LocalDate createdAt, + String createdBy, + LocalDate modifiedAt, + String modifiedBy, + Long viewCount, + Member member + ) { + public static BBSDto of( + Long bbsNo, + Long upperNo, + String type, + String title, + String contents, + Boolean isVisible, + LocalDate createdAt, + String createdBy, + LocalDate modifiedAt, + String modifiedBy, + Long viewConut, + Member member + ){ + return new BBSDto( + bbsNo, + upperNo, + type, + title, + contents, + isVisible, + createdAt, + createdBy, + modifiedAt, + modifiedBy, + viewConut, + member + ); + } + + public static BBSDto from(BBS entity){ + return new BBSDto( + entity.getBbsNo(), + entity.getUpperNo(), + entity.getType(), + entity.getTitle(), + entity.getContents(), + entity.getIsVisible(), + entity.getCreatedAt(), + entity.getCreatedBy(), + entity.getModifiedAt(), + entity.getModifiedBy(), + entity.getViewConut(), + entity.getMember() + ); + } +} \ No newline at end of file diff --git a/module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java b/module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java new file mode 100644 index 00000000..8957fd93 --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java @@ -0,0 +1,10 @@ +package com.kernel360.bbs.enumset; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum BBSType { + QNA, FREE, BOAST, RECOMMAND, NOTICE; + + String type; +} diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java new file mode 100644 index 00000000..67b4d428 --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java @@ -0,0 +1,11 @@ +package com.kernel360.bbs.repository; + +import com.kernel360.bbs.dto.BBSDto; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Repository; + +@Repository +public interface BBSRepository { + Page getBBSWithCondition(String sortType, String keyword, Pageable pageable); +} diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java new file mode 100644 index 00000000..5d07b90e --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java @@ -0,0 +1,4 @@ +package com.kernel360.bbs.repository; + +public interface BBSRepositoryDSL extends BBSRepository { +} diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java new file mode 100644 index 00000000..21662261 --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java @@ -0,0 +1,95 @@ +package com.kernel360.bbs.repository; + +import com.kernel360.bbs.dto.BBSDto; +import com.kernel360.bbs.entity.BBS; +import com.kernel360.file.entity.FileReferType; +import com.kernel360.review.dto.ReviewSearchDto; +import com.kernel360.review.dto.ReviewSearchResult; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQuery; +import com.querydsl.jpa.impl.JPAQueryFactory; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.support.PageableExecutionUtils; + +import java.util.List; + +import static com.kernel360.member.entity.QMember.member; +import static com.kernel360.product.entity.QProduct.product; +import static com.kernel360.review.entity.QReview.review; +import static com.querydsl.core.types.ExpressionUtils.orderBy; +import static com.querydsl.core.types.dsl.Expressions.stringTemplate; + +@RequiredArgsConstructor +public class BBSRepositoryDSLImpl implements BBSRepositoryDSL { + + private final JPAQueryFactory queryFactory; + + @Override + public Page getBBSWithCondition(String sortType, String keyword, Pageable pageable) { + + List bbs = getBBSWithMember(). + where( + titleLike + ). + .orderBy(sort(sortType)) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + JPAQuery totalCountQuery = queryFactory + .select(bbs.count()) + .from(bbs) + .where( + bbs.isVisible.eq(true) + ); + + return PageableExecutionUtils.getPage(bbs, pageable, totalCountQuery::fetchOne); + } + + @Override + public Page findAllByCondition(ReviewSearchDto condition, Pageable pageable) { + List reviews = + getJoinedResults() + .where( + productNoEq(condition.productNo()), // 조건절 메서드 별도 생성 + memberNoEq(condition.memberNo()) + ) + .groupBy(review.reviewNo, member.memberNo, member.id, member.age, member.gender, product.productNo) + .orderBy(sort(condition.sortBy())) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); + + JPAQuery totalCountQuery = queryFactory + .select(review.count()) + .from(review) + .where( + review.isVisible.eq(true), + productNoEq(condition.productNo()), + memberNoEq(condition.memberNo()) + ); + + return PageableExecutionUtils.getPage(reviews, pageable, totalCountQuery::fetchOne); + } + + private JPAQuery getBBSWithMember() { + return queryFactory + .select(Projections.fields(BBSDto.class, + bbs.bbsNo, + bbs.title, + bbs.contents, + bbs.createdAt, + bbs.createdBy, + bbs.modifiedAt, + bbs.modifiedBy, + member.memberNo, + member.id, + member.age, + member.gender + )) + .from(bbs) + .join(member); + } +} diff --git a/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java b/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java new file mode 100644 index 00000000..7247d5eb --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java @@ -0,0 +1,19 @@ +package com.kernel360.bbs.service; + +import com.kernel360.bbs.dto.BBSDto; +import com.kernel360.bbs.repository.BBSRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class BBSService { + private final BBSRepository bbsRepository; + + public Page getBBSWithCondition(String sortType, String keyword, Pageable pageable) { + + return bbsRepository.getBBSWithCondition(sortType, keyword, pageable); + } +} diff --git a/module-api/src/main/java/com/kernel360/member/config/AuditConfig.java b/module-api/src/main/java/com/kernel360/global/config/AuditConfig.java similarity index 91% rename from module-api/src/main/java/com/kernel360/member/config/AuditConfig.java rename to module-api/src/main/java/com/kernel360/global/config/AuditConfig.java index 802402cf..5764e5ce 100644 --- a/module-api/src/main/java/com/kernel360/member/config/AuditConfig.java +++ b/module-api/src/main/java/com/kernel360/global/config/AuditConfig.java @@ -1,4 +1,4 @@ -package com.kernel360.member.config; +package com.kernel360.global.config; import jakarta.servlet.http.HttpServletRequest; import org.springframework.context.annotation.Configuration; @@ -13,7 +13,7 @@ public class AuditConfig implements AuditorAware { @Override public Optional getCurrentAuditor() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); - String createId = Optional.ofNullable(request.getParameter("id")).orElse("admin"); + String createId = Optional.ofNullable(request.getParameter("Id")).orElse("admin"); return Optional.of(createId); } diff --git a/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java b/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java new file mode 100644 index 00000000..6d1f2f2e --- /dev/null +++ b/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java @@ -0,0 +1,50 @@ +package com.kernel360.bbs.entity; + +import com.kernel360.base.BaseEntity; +import com.kernel360.member.entity.Member; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Entity +@Table(name = "bbs") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class BBS extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "bbs_id_gen") + @SequenceGenerator(name = "bbs_id_gen", sequenceName = "bbs_no_seq") + private Long bbsNo; + + private Long upperNo; + + private String type; + + private String title; + + private String contents; + + private Boolean isVisible; + + private Long viewConut; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "member_no", nullable = false, updatable = false) + private Member member; + + public BBS(Long bbsNo, Long upperNo, String type, String title, String contents, Boolean isVisible, Long viewConut, Member member) { + this.bbsNo = bbsNo; + this.upperNo = upperNo; + this.type = type; + this.title = title; + this.contents = contents; + this.isVisible = isVisible; + this.member = member; + this.viewConut = viewConut; + } + + public BBS of (Long bbsNo, Long upperNo, String type, String title, String contents, Boolean isVisible, Long viewConut, Member member){ + return new BBS (bbsNo, upperNo, type, title, contents, isVisible, viewConut, member); + } +} diff --git a/module-domain/src/main/java/com/kernel360/bbs/repository/BBSRepositoryJPA.java b/module-domain/src/main/java/com/kernel360/bbs/repository/BBSRepositoryJPA.java new file mode 100644 index 00000000..2a6fb006 --- /dev/null +++ b/module-domain/src/main/java/com/kernel360/bbs/repository/BBSRepositoryJPA.java @@ -0,0 +1,8 @@ +package com.kernel360.bbs.repository; + +import com.kernel360.bbs.entity.BBS; +import jakarta.persistence.Id; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BBSRepositoryJPA extends JpaRepository { +} From efc1278fbad1064fdd39c3a19f81fc837277fe99 Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Fri, 8 Mar 2024 22:01:54 +0900 Subject: [PATCH 02/13] =?UTF-8?q?*=202=EC=B0=A8=20=EB=B2=A0=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bbs/controller/BBSController.java | 15 ++- .../java/com/kernel360/bbs/dto/BBSDto.java | 17 +-- .../bbs/repository/BBSRepository.java | 8 +- .../bbs/repository/BBSRepositoryDSL.java | 7 +- .../bbs/repository/BBSRepositoryDSLImpl.java | 101 +++++++----------- .../com/kernel360/bbs/service/BBSService.java | 4 +- .../db/migration/V1.0.11__create_BBS.sql | 17 +++ .../java/com/kernel360/bbs/entity/BBS.java | 4 +- 8 files changed, 85 insertions(+), 88 deletions(-) create mode 100644 module-api/src/main/resources/db/migration/V1.0.11__create_BBS.sql diff --git a/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java b/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java index e7afb361..21feece0 100644 --- a/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java +++ b/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java @@ -10,33 +10,32 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -@RestController("/bbs") +@RestController @RequiredArgsConstructor public class BBSController { private final BBSService bbsService; - @GetMapping("") + @GetMapping("/bbs") public ResponseEntity>> getBBS( - @RequestParam(value = "sortType", defaultValue = "latest")String sortType, + @RequestParam(value = "bbsType", defaultValue = "")String bbsType, @RequestParam(value = "keyword", required = false) String keyword, Pageable pageable ){ - - return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS, bbsService.getBBSWithCondition(sortType, keyword, pageable)); + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS, bbsService.getBBSWithCondition(bbsType, keyword, pageable)); } - @PostMapping("/save") + @PostMapping("/bbs") public ResponseEntity> saveBBS(@RequestBody BBSDto bbsDto){ return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); } - @PatchMapping("/modifiy") + @PatchMapping("/bbs") public ResponseEntity> modifyBBS(@RequestBody BBSDto bbsDto){ return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); } - @DeleteMapping("/delete") + @DeleteMapping("/bbs") public ResponseEntity> deleteBBS(@RequestBody BBSDto bbsDto){ return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); } diff --git a/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java b/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java index 01e93ef8..ee60679e 100644 --- a/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java +++ b/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java @@ -1,6 +1,7 @@ package com.kernel360.bbs.dto; import com.kernel360.bbs.entity.BBS; +import com.kernel360.member.dto.MemberDto; import com.kernel360.member.entity.Member; import org.springframework.cglib.core.Local; @@ -22,8 +23,9 @@ public record BBSDto( LocalDate modifiedAt, String modifiedBy, Long viewCount, - Member member + MemberDto memberDto ) { + public static BBSDto of( Long bbsNo, Long upperNo, @@ -35,8 +37,8 @@ public static BBSDto of( String createdBy, LocalDate modifiedAt, String modifiedBy, - Long viewConut, - Member member + Long viewCount, + MemberDto memberDto ){ return new BBSDto( bbsNo, @@ -49,8 +51,8 @@ public static BBSDto of( createdBy, modifiedAt, modifiedBy, - viewConut, - member + viewCount, + memberDto ); } @@ -66,8 +68,9 @@ public static BBSDto from(BBS entity){ entity.getCreatedBy(), entity.getModifiedAt(), entity.getModifiedBy(), - entity.getViewConut(), - entity.getMember() + entity.getViewCount(), + MemberDto.from(entity.getMember()) ); } + } \ No newline at end of file diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java index 67b4d428..f6133f9c 100644 --- a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java @@ -1,11 +1,9 @@ package com.kernel360.bbs.repository; -import com.kernel360.bbs.dto.BBSDto; +import com.kernel360.bbs.entity.BBS; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Repository; -@Repository -public interface BBSRepository { - Page getBBSWithCondition(String sortType, String keyword, Pageable pageable); +public interface BBSRepository extends BBSRepositoryJPA, BBSRepositoryDSL { + Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable); } diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java index 5d07b90e..2c5973be 100644 --- a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java @@ -1,4 +1,9 @@ package com.kernel360.bbs.repository; -public interface BBSRepositoryDSL extends BBSRepository { +import com.kernel360.bbs.entity.BBS; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +public interface BBSRepositoryDSL { + Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable); } diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java index 21662261..393bed26 100644 --- a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java @@ -2,24 +2,23 @@ import com.kernel360.bbs.dto.BBSDto; import com.kernel360.bbs.entity.BBS; -import com.kernel360.file.entity.FileReferType; -import com.kernel360.review.dto.ReviewSearchDto; -import com.kernel360.review.dto.ReviewSearchResult; +import com.kernel360.bbs.enumset.BBSType; +import com.querydsl.core.types.Predicate; import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; import org.springframework.data.support.PageableExecutionUtils; import java.util.List; +import static com.kernel360.bbs.entity.QBBS.bBS; import static com.kernel360.member.entity.QMember.member; -import static com.kernel360.product.entity.QProduct.product; -import static com.kernel360.review.entity.QReview.review; -import static com.querydsl.core.types.ExpressionUtils.orderBy; -import static com.querydsl.core.types.dsl.Expressions.stringTemplate; +import static org.springframework.util.StringUtils.hasText; @RequiredArgsConstructor public class BBSRepositoryDSLImpl implements BBSRepositoryDSL { @@ -27,69 +26,45 @@ public class BBSRepositoryDSLImpl implements BBSRepositoryDSL { private final JPAQueryFactory queryFactory; @Override - public Page getBBSWithCondition(String sortType, String keyword, Pageable pageable) { + public Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable) { - List bbs = getBBSWithMember(). - where( - titleLike - ). - .orderBy(sort(sortType)) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .fetch(); + Predicate finalPredicate = bBS.isVisible.eq(true) + .and(bBS.type.eq(BBSType.valueOf(bbsType).name())) + .and(keywordContains(keyword)); - JPAQuery totalCountQuery = queryFactory - .select(bbs.count()) - .from(bbs) - .where( - bbs.isVisible.eq(true) - ); - - return PageableExecutionUtils.getPage(bbs, pageable, totalCountQuery::fetchOne); - } - - @Override - public Page findAllByCondition(ReviewSearchDto condition, Pageable pageable) { - List reviews = - getJoinedResults() - .where( - productNoEq(condition.productNo()), // 조건절 메서드 별도 생성 - memberNoEq(condition.memberNo()) - ) - .groupBy(review.reviewNo, member.memberNo, member.id, member.age, member.gender, product.productNo) - .orderBy(sort(condition.sortBy())) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize()) - .fetch(); + List bbs = getBBSWithMember(). + where(finalPredicate) + .orderBy(bBS.createdAt.desc()) + .offset(pageable.getOffset()) + .limit(pageable.getPageSize()) + .fetch(); - JPAQuery totalCountQuery = queryFactory - .select(review.count()) - .from(review) + Long totalCount = queryFactory + .select(bBS.count()) + .from(bBS) .where( - review.isVisible.eq(true), - productNoEq(condition.productNo()), - memberNoEq(condition.memberNo()) - ); + keywordContains(keyword), + bBS.isVisible.eq(true) + ) + .fetchOne(); - return PageableExecutionUtils.getPage(reviews, pageable, totalCountQuery::fetchOne); + return new PageImpl<>(bbs, pageable, totalCount); + //return PageableExecutionUtils.getPage(bbs, pageable, totalCount); } - private JPAQuery getBBSWithMember() { + private JPAQuery getBBSWithMember() { return queryFactory - .select(Projections.fields(BBSDto.class, - bbs.bbsNo, - bbs.title, - bbs.contents, - bbs.createdAt, - bbs.createdBy, - bbs.modifiedAt, - bbs.modifiedBy, - member.memberNo, - member.id, - member.age, - member.gender - )) - .from(bbs) - .join(member); + .select(bBS) + .from(bBS) + .join(member).on(bBS.member.memberNo.eq(member.memberNo)); + } + + private BooleanExpression keywordContains(String keyword) { + return hasText(keyword) ? + bBS.title.contains(keyword) + .or(bBS.contents.contains(keyword)) + .or(bBS.member.id.eq(keyword)) + : null; } + } diff --git a/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java b/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java index 7247d5eb..33bc5f68 100644 --- a/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java +++ b/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java @@ -12,8 +12,8 @@ public class BBSService { private final BBSRepository bbsRepository; - public Page getBBSWithCondition(String sortType, String keyword, Pageable pageable) { + public Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable) { - return bbsRepository.getBBSWithCondition(sortType, keyword, pageable); + return bbsRepository.getBBSWithCondition(bbsType, keyword, pageable).map(BBSDto::from); } } diff --git a/module-api/src/main/resources/db/migration/V1.0.11__create_BBS.sql b/module-api/src/main/resources/db/migration/V1.0.11__create_BBS.sql new file mode 100644 index 00000000..7b5c0bb6 --- /dev/null +++ b/module-api/src/main/resources/db/migration/V1.0.11__create_BBS.sql @@ -0,0 +1,17 @@ +CREATE TABLE IF NOT EXISTS bbs ( + bbs_no BIGSERIAL PRIMARY KEY, + upper_no BIGINT, + member_no BIGINT NOT NULL, + type VARCHAR NOT NULL, + title VARCHAR NOT NULL, + contents VARCHAR NOT NULL, + is_visible BOOL NOT NULL DEFAULT TRUE, + view_count BIGINT NOT NULL, + created_at DATE NOT NULL, + created_by VARCHAR NOT NULL, + modified_at DATE, + modified_by VARCHAR, + FOREIGN KEY (member_no) REFERENCES Member (member_no) + ); + +AlTER SEQUENCE bbs_bbs_no_seq increment by 50; diff --git a/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java b/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java index 6d1f2f2e..80cd9e29 100644 --- a/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java +++ b/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java @@ -27,7 +27,7 @@ public class BBS extends BaseEntity { private Boolean isVisible; - private Long viewConut; + private Long viewCount; @ManyToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "member_no", nullable = false, updatable = false) @@ -41,7 +41,7 @@ public BBS(Long bbsNo, Long upperNo, String type, String title, String contents, this.contents = contents; this.isVisible = isVisible; this.member = member; - this.viewConut = viewConut; + this.viewCount = viewConut; } public BBS of (Long bbsNo, Long upperNo, String type, String title, String contents, Boolean isVisible, Long viewConut, Member member){ From 2d2fa09753e6bf3aeb7dea3b32dccbd035f3a777 Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:39:18 +0900 Subject: [PATCH 03/13] =?UTF-8?q?*=20Repository=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bbs/repository/BBSRepository.java | 9 +++- .../bbs/repository/BBSRepositoryDSL.java | 4 +- .../bbs/repository/BBSRepositoryDSLImpl.java | 43 ++++++++++++------- .../bbs/repository/BBSRepositoryJPA.java | 8 ++++ 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java index f6133f9c..b60ae6c4 100644 --- a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepository.java @@ -1,9 +1,16 @@ package com.kernel360.bbs.repository; +import com.kernel360.bbs.dto.BBSListDto; import com.kernel360.bbs.entity.BBS; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; public interface BBSRepository extends BBSRepositoryJPA, BBSRepositoryDSL { - Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable); + Page getBBSWithCondition(String type, String keyword, Pageable pageable); + + BBS findOneByBbsNo(Long bbsNo); + + Page findAllByUpperNo(Long upperNo, Pageable pageable); + + void deleteByBbsNo(Long bbsNo); } diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java index 2c5973be..6adfa692 100644 --- a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSL.java @@ -1,9 +1,9 @@ package com.kernel360.bbs.repository; -import com.kernel360.bbs.entity.BBS; +import com.kernel360.bbs.dto.BBSListDto; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; public interface BBSRepositoryDSL { - Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable); + Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable); } diff --git a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java index 393bed26..c6b2d1d3 100644 --- a/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java +++ b/module-api/src/main/java/com/kernel360/bbs/repository/BBSRepositoryDSLImpl.java @@ -1,10 +1,8 @@ package com.kernel360.bbs.repository; -import com.kernel360.bbs.dto.BBSDto; -import com.kernel360.bbs.entity.BBS; +import com.kernel360.bbs.dto.BBSListDto; import com.kernel360.bbs.enumset.BBSType; import com.querydsl.core.types.Predicate; -import com.querydsl.core.types.Projections; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -12,12 +10,13 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; -import org.springframework.data.support.PageableExecutionUtils; import java.util.List; +import java.util.Objects; import static com.kernel360.bbs.entity.QBBS.bBS; import static com.kernel360.member.entity.QMember.member; +import static com.querydsl.core.types.Projections.fields; import static org.springframework.util.StringUtils.hasText; @RequiredArgsConstructor @@ -26,14 +25,16 @@ public class BBSRepositoryDSLImpl implements BBSRepositoryDSL { private final JPAQueryFactory queryFactory; @Override - public Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable) { + public Page getBBSWithCondition(String type, String keyword, Pageable pageable) { Predicate finalPredicate = bBS.isVisible.eq(true) - .and(bBS.type.eq(BBSType.valueOf(bbsType).name())) - .and(keywordContains(keyword)); + .and(bBS.type.eq(BBSType.valueOf(type).name())); - List bbs = getBBSWithMember(). - where(finalPredicate) + List bbs = getBBSListWithMember(). + where( + finalPredicate, + keywordContains(keyword) + ) .orderBy(bBS.createdAt.desc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) @@ -43,27 +44,37 @@ public Page getBBSWithCondition(String bbsType, String keyword, Pageable pa .select(bBS.count()) .from(bBS) .where( - keywordContains(keyword), - bBS.isVisible.eq(true) + finalPredicate, + keywordContains(keyword) ) .fetchOne(); return new PageImpl<>(bbs, pageable, totalCount); - //return PageableExecutionUtils.getPage(bbs, pageable, totalCount); } - private JPAQuery getBBSWithMember() { + private JPAQuery getBBSListWithMember() { return queryFactory - .select(bBS) + .select(fields(BBSListDto.class, + bBS.bbsNo, + bBS.title, + bBS.type, + bBS.createdAt, + bBS.createdBy, + bBS.viewCount, + bBS.member.memberNo, + bBS.member.id + ) + + ) .from(bBS) .join(member).on(bBS.member.memberNo.eq(member.memberNo)); } - private BooleanExpression keywordContains(String keyword) { + private BooleanExpression keywordContains(String keyword) { //우선 참이 된다면 하위 조건 결과는 포함 안됨. return hasText(keyword) ? bBS.title.contains(keyword) .or(bBS.contents.contains(keyword)) - .or(bBS.member.id.eq(keyword)) + .or(bBS.createdBy.eq(keyword)) : null; } diff --git a/module-domain/src/main/java/com/kernel360/bbs/repository/BBSRepositoryJPA.java b/module-domain/src/main/java/com/kernel360/bbs/repository/BBSRepositoryJPA.java index 2a6fb006..b8d0a451 100644 --- a/module-domain/src/main/java/com/kernel360/bbs/repository/BBSRepositoryJPA.java +++ b/module-domain/src/main/java/com/kernel360/bbs/repository/BBSRepositoryJPA.java @@ -2,7 +2,15 @@ import com.kernel360.bbs.entity.BBS; import jakarta.persistence.Id; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface BBSRepositoryJPA extends JpaRepository { + BBS findOneByBbsNo(Long bbsNo); + + Page findAllByUpperNo(Long upperNo, Pageable pageable); + + + void deleteByBbsNo(Long bbsNo); } From 46670762efb27f9ebff8aa9fac1bbda661379c08 Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:39:38 +0900 Subject: [PATCH 04/13] =?UTF-8?q?*=20=EC=9E=91=EC=84=B1=EC=9E=90,=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=EC=9E=90=20=ED=97=A4=EB=8D=94=20Id=EB=A1=9C?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/kernel360/global/config/AuditConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module-api/src/main/java/com/kernel360/global/config/AuditConfig.java b/module-api/src/main/java/com/kernel360/global/config/AuditConfig.java index 5764e5ce..20589539 100644 --- a/module-api/src/main/java/com/kernel360/global/config/AuditConfig.java +++ b/module-api/src/main/java/com/kernel360/global/config/AuditConfig.java @@ -13,7 +13,7 @@ public class AuditConfig implements AuditorAware { @Override public Optional getCurrentAuditor() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); - String createId = Optional.ofNullable(request.getParameter("Id")).orElse("admin"); + String createId = Optional.ofNullable(request.getHeader("Id")).orElse("admin"); return Optional.of(createId); } From 2a78d5468dc25a2cbf9992a971fdb39cc3e0ec45 Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:39:49 +0900 Subject: [PATCH 05/13] =?UTF-8?q?*=20Entity=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/kernel360/bbs/entity/BBS.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java b/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java index 80cd9e29..d250ce54 100644 --- a/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java +++ b/module-domain/src/main/java/com/kernel360/bbs/entity/BBS.java @@ -14,7 +14,7 @@ public class BBS extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "bbs_id_gen") - @SequenceGenerator(name = "bbs_id_gen", sequenceName = "bbs_no_seq") + @SequenceGenerator(name = "bbs_id_gen", sequenceName = "bbs_bbs_no_seq") private Long bbsNo; private Long upperNo; @@ -33,7 +33,7 @@ public class BBS extends BaseEntity { @JoinColumn(name = "member_no", nullable = false, updatable = false) private Member member; - public BBS(Long bbsNo, Long upperNo, String type, String title, String contents, Boolean isVisible, Long viewConut, Member member) { + private BBS(Long bbsNo, Long upperNo, String type, String title, String contents, Boolean isVisible, Long viewConut, Member member) { this.bbsNo = bbsNo; this.upperNo = upperNo; this.type = type; @@ -44,7 +44,9 @@ public BBS(Long bbsNo, Long upperNo, String type, String title, String contents, this.viewCount = viewConut; } - public BBS of (Long bbsNo, Long upperNo, String type, String title, String contents, Boolean isVisible, Long viewConut, Member member){ - return new BBS (bbsNo, upperNo, type, title, contents, isVisible, viewConut, member); + public static BBS save(Long bbsNo, Long upperNo, String type, String title, String contents, Boolean isVisible, Long viewCount, Member member){ + + return new BBS (bbsNo, upperNo, type, title, contents, isVisible, viewCount, member); } + } From 3088c6f540c4ec07663b2c06a70262d9cb6e4e16 Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:40:54 +0900 Subject: [PATCH 06/13] =?UTF-8?q?*=20BBS=20=EC=9D=91=EB=8B=B5=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kernel360/bbs/code/BBSBusinessCode.java | 15 +++++++-------- .../java/com/kernel360/bbs/code/BBSErrorCode.java | 8 ++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/module-api/src/main/java/com/kernel360/bbs/code/BBSBusinessCode.java b/module-api/src/main/java/com/kernel360/bbs/code/BBSBusinessCode.java index 4efccfbc..e6989293 100644 --- a/module-api/src/main/java/com/kernel360/bbs/code/BBSBusinessCode.java +++ b/module-api/src/main/java/com/kernel360/bbs/code/BBSBusinessCode.java @@ -8,9 +8,10 @@ public enum BBSBusinessCode implements BusinessCode { SUCCESS_REQUEST_GET_BBS(HttpStatus.OK.value(), "BBC001", "게시판 목록 조회 성공"), - SUCCESS_REQUEST_CREATED_BBS(HttpStatus.CREATED.value(), "BBC002", "게시글 작성 성공"), - SUCCESS_REQUEST_MODIFIED_BBS(HttpStatus.OK.value(), "BBC003", "게시글 수정 성공"), - SUCCESS_REQUEST_DELETE_BBS(HttpStatus.OK.value(), "BBC004", "게시글 삭제 성공"); + SUCCESS_REQUEST_GET_BBS_VIEW(HttpStatus.OK.value(), "BBC002", "게시판 상세 조회 성공"), + SUCCESS_REQUEST_CREATED_BBS(HttpStatus.CREATED.value(), "BBC003", "게시글 작성 성공"), + SUCCESS_REQUEST_MODIFIED_BBS(HttpStatus.OK.value(), "BBC004", "게시글 수정 성공"), + SUCCESS_REQUEST_DELETE_BBS(HttpStatus.OK.value(), "BBC005", "게시글 삭제 성공"); private final int status; private final String code; @@ -18,16 +19,14 @@ public enum BBSBusinessCode implements BusinessCode { @Override public int getStatus() { - return 0; + return status; } @Override - public String getCode() { - return null; - } + public String getCode() { return code; } @Override public String getMessage() { - return null; + return message; } } diff --git a/module-api/src/main/java/com/kernel360/bbs/code/BBSErrorCode.java b/module-api/src/main/java/com/kernel360/bbs/code/BBSErrorCode.java index e7b0780d..93574ada 100644 --- a/module-api/src/main/java/com/kernel360/bbs/code/BBSErrorCode.java +++ b/module-api/src/main/java/com/kernel360/bbs/code/BBSErrorCode.java @@ -8,7 +8,7 @@ public enum BBSErrorCode implements ErrorCode { FAILED_GET_BBS_LIST(HttpStatus.NO_CONTENT.value(), "BMC001", "게시판 목록을 찾을 수 없음."), - FAILED_GET_BBS_ONE(HttpStatus.NO_CONTENT.value(), "BMC002", "게시글을 찾을 수 없음."); + FAILED_GET_BBS_VIEW(HttpStatus.NO_CONTENT.value(), "BMC002", "게시글을 찾을 수 없음."); private final int status; private final String code; @@ -16,16 +16,16 @@ public enum BBSErrorCode implements ErrorCode { @Override public int getStatus() { - return 0; + return status; } @Override public String getCode() { - return null; + return code; } @Override public String getMessage() { - return null; + return message; } } From 35b8a55d0952212d2751471d80d9c60ca0db92aa Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:41:15 +0900 Subject: [PATCH 07/13] =?UTF-8?q?*=20BBS=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=9E=91=EC=84=B1,=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EB=93=B1=EB=A1=9D=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bbs/controller/BBSController.java | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java b/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java index 21feece0..4c65732d 100644 --- a/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java +++ b/module-api/src/main/java/com/kernel360/bbs/controller/BBSController.java @@ -2,6 +2,7 @@ import com.kernel360.bbs.code.BBSBusinessCode; import com.kernel360.bbs.dto.BBSDto; +import com.kernel360.bbs.dto.BBSListDto; import com.kernel360.bbs.service.BBSService; import com.kernel360.response.ApiResponse; import lombok.RequiredArgsConstructor; @@ -16,27 +17,48 @@ public class BBSController { private final BBSService bbsService; @GetMapping("/bbs") - public ResponseEntity>> getBBS( - @RequestParam(value = "bbsType", defaultValue = "")String bbsType, + public ResponseEntity>> getBBS( + @RequestParam(value = "type", defaultValue = "") String type, @RequestParam(value = "keyword", required = false) String keyword, Pageable pageable ){ - return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS, bbsService.getBBSWithCondition(bbsType, keyword, pageable)); + Page result = bbsService.getBBSWithCondition(type, keyword, pageable); + + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS, result); + } + + @GetMapping("/bbs/{bbsNo}") + public ResponseEntity> getBBSView(@PathVariable Long bbsNo){ + + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS_VIEW, bbsService.getBBSView(bbsNo)); + } + + @GetMapping("/bbs/reply") + public ResponseEntity>> getBBSReply(@RequestParam Long upperNo, Pageable pageable){ + + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS_VIEW, bbsService.getBBSReply(upperNo, pageable)); } @PostMapping("/bbs") - public ResponseEntity> saveBBS(@RequestBody BBSDto bbsDto){ + public ResponseEntity> saveBBS(@RequestBody BBSDto bbsDto, @RequestHeader("Id") String id){ + + bbsService.saveBBS(bbsDto, id); - return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_CREATED_BBS); } @PatchMapping("/bbs") - public ResponseEntity> modifyBBS(@RequestBody BBSDto bbsDto){ + public ResponseEntity> modifyBBS(@RequestBody BBSDto bbsDto, @RequestHeader("Id") String id){ + + bbsService.saveBBS(bbsDto, id); - return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_MODIFIED_BBS); } @DeleteMapping("/bbs") - public ResponseEntity> deleteBBS(@RequestBody BBSDto bbsDto){ - return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_GET_BBS); + public ResponseEntity> deleteBBS(@RequestParam Long bbsNo){ + + bbsService.deleteBBS(bbsNo); + + return ApiResponse.toResponseEntity(BBSBusinessCode.SUCCESS_REQUEST_DELETE_BBS); } } From a2cdfac1dfc1669e3e29a28a0002c7d0450e148b Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:42:14 +0900 Subject: [PATCH 08/13] =?UTF-8?q?*=20BBS=20=EB=B2=94=EC=9A=A9=20DTO=20?= =?UTF-8?q?=EB=B0=8F=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=A0=84?= =?UTF-8?q?=EC=9A=A9=20DTO=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/kernel360/bbs/dto/BBSDto.java | 16 +++++++++++++--- .../com/kernel360/bbs/dto/BBSListDto.java | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 module-api/src/main/java/com/kernel360/bbs/dto/BBSListDto.java diff --git a/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java b/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java index ee60679e..ad391e5c 100644 --- a/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java +++ b/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java @@ -2,10 +2,7 @@ import com.kernel360.bbs.entity.BBS; import com.kernel360.member.dto.MemberDto; -import com.kernel360.member.entity.Member; -import org.springframework.cglib.core.Local; -import java.io.Serializable; import java.time.LocalDate; /** @@ -73,4 +70,17 @@ public static BBSDto from(BBS entity){ ); } + +// public BBS toEntity() { +// return BBS.create( +// this.bbsNo(), +// this.upperNo(), +// this.title(), +// this.contents() +// +// ); +// } + + + } \ No newline at end of file diff --git a/module-api/src/main/java/com/kernel360/bbs/dto/BBSListDto.java b/module-api/src/main/java/com/kernel360/bbs/dto/BBSListDto.java new file mode 100644 index 00000000..256bc7bb --- /dev/null +++ b/module-api/src/main/java/com/kernel360/bbs/dto/BBSListDto.java @@ -0,0 +1,19 @@ +package com.kernel360.bbs.dto; + +import lombok.Data; +import lombok.RequiredArgsConstructor; + +import java.time.LocalDate; + +@Data +@RequiredArgsConstructor +public class BBSListDto { + Long bbsNo; + String type; + String title; + LocalDate createdAt; + String createdBy; + Long viewCount; + Long memberNo; + String id; +} From 68f011b49bb042d3917b65ecb8f3f001c190e9e7 Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:42:31 +0900 Subject: [PATCH 09/13] =?UTF-8?q?*=20BBS=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=EC=A0=95=EC=9D=98=20ENUM=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java b/module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java index 8957fd93..54fceb00 100644 --- a/module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java +++ b/module-api/src/main/java/com/kernel360/bbs/enumset/BBSType.java @@ -4,7 +4,7 @@ @RequiredArgsConstructor public enum BBSType { - QNA, FREE, BOAST, RECOMMAND, NOTICE; + QNA, FREE, BOAST, RECOMMAND, NOTICE, REPLY; String type; } From 5f04159e5c1e345d2f9c3eb16c39a4ff2a65e05a Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:43:07 +0900 Subject: [PATCH 10/13] =?UTF-8?q?*=20BBS=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kernel360/bbs/service/BBSService.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java b/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java index 33bc5f68..bab40728 100644 --- a/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java +++ b/module-api/src/main/java/com/kernel360/bbs/service/BBSService.java @@ -1,19 +1,48 @@ package com.kernel360.bbs.service; import com.kernel360.bbs.dto.BBSDto; +import com.kernel360.bbs.dto.BBSListDto; +import com.kernel360.bbs.entity.BBS; import com.kernel360.bbs.repository.BBSRepository; +import com.kernel360.member.dto.MemberDto; +import com.kernel360.member.service.MemberService; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor public class BBSService { private final BBSRepository bbsRepository; + private final MemberService memberService; - public Page getBBSWithCondition(String bbsType, String keyword, Pageable pageable) { + public Page getBBSWithCondition(String type, String keyword, Pageable pageable) { - return bbsRepository.getBBSWithCondition(bbsType, keyword, pageable).map(BBSDto::from); + return bbsRepository.getBBSWithCondition(type, keyword, pageable); + } + + public BBSDto getBBSView(Long bbsNo) { + + return BBSDto.from(bbsRepository.findOneByBbsNo(bbsNo)); + } + + public Page getBBSReply(Long upperNo, Pageable pageable) { + + return bbsRepository.findAllByUpperNo(upperNo, pageable).map(BBSDto::from); + } + + @Transactional + public void saveBBS(BBSDto bbsDto, String id) { + + MemberDto memberDto = memberService.findByMemberId(id); + + bbsRepository.save(BBS.save(bbsDto.bbsNo(), bbsDto.upperNo(), bbsDto.type(), bbsDto.title(), bbsDto.contents(), true, 0L, memberDto.toEntity())); + } + + @Transactional + public void deleteBBS(Long bbsNo) { + bbsRepository.deleteByBbsNo(bbsNo); } } From 6765f91f5e5f380cddb9962a0c1b9c1c4efb481d Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 18:45:21 +0900 Subject: [PATCH 11/13] =?UTF-8?q?*=20=EA=B8=B0=EC=A1=B4=20findByMemberId?= =?UTF-8?q?=EB=A5=BC=20=EB=8B=A4=EB=A5=B8=20=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=EC=97=90=EC=84=9C=20IoC=20=EC=9B=90=EC=B9=99=20=EB=B0=8F=20?= =?UTF-8?q?=EC=9A=A9=EB=8F=84=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EC=93=B0?= =?UTF-8?q?=EA=B8=B0=20=EC=9C=84=ED=95=B4=20findOneByIdForAccountTypeByPla?= =?UTF-8?q?tform=EB=A1=9C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20*=20=EC=A0=84=EC=B2=B4=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EB=8C=80=EC=83=81=EC=9C=BC=EB=A1=9C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=ED=95=98=EB=8A=94=20findByMemberId=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kernel360/member/controller/MemberController.java | 2 +- .../java/com/kernel360/member/service/MemberService.java | 7 ++++++- .../kernel360/member/controller/MemberControllerTest.java | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/module-api/src/main/java/com/kernel360/member/controller/MemberController.java b/module-api/src/main/java/com/kernel360/member/controller/MemberController.java index 531537a4..f6249e25 100644 --- a/module-api/src/main/java/com/kernel360/member/controller/MemberController.java +++ b/module-api/src/main/java/com/kernel360/member/controller/MemberController.java @@ -92,7 +92,7 @@ public ResponseEntity> sendMemberIdByEmail(@RequestBody Memb @PostMapping("/find-password") public ResponseEntity> sendPasswordResetUriByEmail(@RequestBody MemberCredentialDto dto) { //--입력받은 아이디를 데이터베이스에 조회, 없으면 예외 발생--/ - MemberDto memberDto = memberService.findByMemberId(dto.memberId()); + MemberDto memberDto = memberService.findOneByIdForAccountTypeByPlatform(dto.memberId()); //--유효성이 검증된 아이디에 대해서 만료시간이 있는 비밀번호 초기화 (호스트 + UUID) 링크 생성 --// String resetUri = findCredentialService.generatePasswordResetPageUri(memberDto); //-- 가입시 입력한 이메일로 비밀번호 초기화 이메일 발송 --// diff --git a/module-api/src/main/java/com/kernel360/member/service/MemberService.java b/module-api/src/main/java/com/kernel360/member/service/MemberService.java index d833f3e8..0792169d 100644 --- a/module-api/src/main/java/com/kernel360/member/service/MemberService.java +++ b/module-api/src/main/java/com/kernel360/member/service/MemberService.java @@ -238,7 +238,7 @@ public MemberDto findByEmail(String email) { } @Transactional(readOnly = true) - public MemberDto findByMemberId(String memberId) { + public MemberDto findOneByIdForAccountTypeByPlatform(String memberId) { Member member = memberRepository.findOneByIdForAccountTypeByPlatform(memberId); if (member == null) { throw new BusinessException(MemberErrorCode.FAILED_FIND_MEMBER_INFO); @@ -284,4 +284,9 @@ public boolean validatePassword(String password, String token) { return member.getPassword().equals(ConvertSHA256.convertToSHA256(password)); } + + public MemberDto findByMemberId(String id) { + Member member = memberRepository.findOneById(id); + return MemberDto.from(member); + } } diff --git a/module-api/src/test/java/com/kernel360/member/controller/MemberControllerTest.java b/module-api/src/test/java/com/kernel360/member/controller/MemberControllerTest.java index c8352c07..64ae8894 100644 --- a/module-api/src/test/java/com/kernel360/member/controller/MemberControllerTest.java +++ b/module-api/src/test/java/com/kernel360/member/controller/MemberControllerTest.java @@ -151,7 +151,7 @@ class MemberControllerTest extends ControllerTest { MemberCredentialDto credentialDto = MemberCredentialDto.of(null, null, "kernel360", null); MemberDto memberDto = MemberDto.of("testMemberId", "testPassword001"); - given(memberService.findByMemberId(credentialDto.memberId())).willReturn(memberDto); + given(memberService.findOneByIdForAccountTypeByPlatform(credentialDto.memberId())).willReturn(memberDto); given(findCredentialService.generatePasswordResetPageUri(memberDto)).willReturn("테스트 URI"); ObjectMapper objectMapper = new ObjectMapper(); From dc6a1558b52fc4e9fb87e4d2d9c10b43b3891101 Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Tue, 12 Mar 2024 19:01:37 +0900 Subject: [PATCH 12/13] =?UTF-8?q?*=20LocalDate=20->=20LocalDateTime=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/kernel360/bbs/dto/BBSDto.java | 10 +++++----- .../main/java/com/kernel360/bbs/dto/BBSListDto.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java b/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java index ad391e5c..fc3f7b33 100644 --- a/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java +++ b/module-api/src/main/java/com/kernel360/bbs/dto/BBSDto.java @@ -3,7 +3,7 @@ import com.kernel360.bbs.entity.BBS; import com.kernel360.member.dto.MemberDto; -import java.time.LocalDate; +import java.time.LocalDateTime; /** * DTO for {@link com.kernel360.bbs.entity.BBS} @@ -15,9 +15,9 @@ public record BBSDto( String title, String contents, Boolean isVisible, - LocalDate createdAt, + LocalDateTime createdAt, String createdBy, - LocalDate modifiedAt, + LocalDateTime modifiedAt, String modifiedBy, Long viewCount, MemberDto memberDto @@ -30,9 +30,9 @@ public static BBSDto of( String title, String contents, Boolean isVisible, - LocalDate createdAt, + LocalDateTime createdAt, String createdBy, - LocalDate modifiedAt, + LocalDateTime modifiedAt, String modifiedBy, Long viewCount, MemberDto memberDto diff --git a/module-api/src/main/java/com/kernel360/bbs/dto/BBSListDto.java b/module-api/src/main/java/com/kernel360/bbs/dto/BBSListDto.java index 256bc7bb..ca905667 100644 --- a/module-api/src/main/java/com/kernel360/bbs/dto/BBSListDto.java +++ b/module-api/src/main/java/com/kernel360/bbs/dto/BBSListDto.java @@ -3,7 +3,7 @@ import lombok.Data; import lombok.RequiredArgsConstructor; -import java.time.LocalDate; +import java.time.LocalDateTime; @Data @RequiredArgsConstructor @@ -11,7 +11,7 @@ public class BBSListDto { Long bbsNo; String type; String title; - LocalDate createdAt; + LocalDateTime createdAt; String createdBy; Long viewCount; Long memberNo; From 2abe9fbedfa600dc8eaa30c7415e4482267c5b0a Mon Sep 17 00:00:00 2001 From: gunsight1 Date: Wed, 13 Mar 2024 15:12:20 +0900 Subject: [PATCH 13/13] =?UTF-8?q?*=20=ED=8C=8C=EC=9D=BC=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20DATE=20->=20TIMESTAMP=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{V1.0.11__create_BBS.sql => V1.0.15__create_BBS.sql} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename module-api/src/main/resources/db/migration/{V1.0.11__create_BBS.sql => V1.0.15__create_BBS.sql} (88%) diff --git a/module-api/src/main/resources/db/migration/V1.0.11__create_BBS.sql b/module-api/src/main/resources/db/migration/V1.0.15__create_BBS.sql similarity index 88% rename from module-api/src/main/resources/db/migration/V1.0.11__create_BBS.sql rename to module-api/src/main/resources/db/migration/V1.0.15__create_BBS.sql index 7b5c0bb6..8384b6e9 100644 --- a/module-api/src/main/resources/db/migration/V1.0.11__create_BBS.sql +++ b/module-api/src/main/resources/db/migration/V1.0.15__create_BBS.sql @@ -7,9 +7,9 @@ CREATE TABLE IF NOT EXISTS bbs ( contents VARCHAR NOT NULL, is_visible BOOL NOT NULL DEFAULT TRUE, view_count BIGINT NOT NULL, - created_at DATE NOT NULL, + created_at TIMESTAMP NOT NULL, created_by VARCHAR NOT NULL, - modified_at DATE, + modified_at TIMESTAMP, modified_by VARCHAR, FOREIGN KEY (member_no) REFERENCES Member (member_no) );