diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/AccompanyBoardController.java b/src/main/java/com/dnd/accompany/domain/accompany/api/AccompanyBoardController.java index 6955a79..d09c400 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/AccompanyBoardController.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/AccompanyBoardController.java @@ -1,11 +1,7 @@ package com.dnd.accompany.domain.accompany.api; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -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; @@ -67,6 +63,15 @@ public ResponseEntity> readAll( return ResponseEntity.ok(accompanyBoardService.getAllBoards(request, region)); } + @Operation(summary = "동행 시작 여부에 따른 동행글 목록 조회") + @PostMapping("/all/by-started") + public ResponseEntity> readAllNotStarted( + @RequestBody @Valid PageRequest request, + @RequestParam(value = "region", required = false) Region region, + @RequestParam(value = "started") boolean started) { + return ResponseEntity.ok(accompanyBoardService.getAllBoards(request, region, started)); + } + @Operation(summary = "내가 쓴 동행글 목록 조회") @PostMapping("/mine") public ResponseEntity> readMine( diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/AccompanyRequestController.java b/src/main/java/com/dnd/accompany/domain/accompany/api/AccompanyRequestController.java index 4658c17..56926a6 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/AccompanyRequestController.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/AccompanyRequestController.java @@ -76,9 +76,9 @@ public ResponseEntity approve( @Operation(summary = "동행 신청 거절") @PostMapping("/decline/{id}") - public ResponseEntity decline( - @PathVariable("id") Long requestId, - @AuthenticationPrincipal JwtAuthentication user) { + public ResponseEntity decline( + @PathVariable("id") Long requestId, + @AuthenticationPrincipal JwtAuthentication user) { accompanyServiceFacade.declineRequest(requestId, user.getId()); return ResponseEntity.ok().build(); } diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/AccompanyRequestDetailInfo.java b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/AccompanyRequestDetailInfo.java index 0061bbb..7aee0bc 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/AccompanyRequestDetailInfo.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/AccompanyRequestDetailInfo.java @@ -15,7 +15,8 @@ public class AccompanyRequestDetailInfo { private boolean isReceived; @Builder - public AccompanyRequestDetailInfo(Long requestId, Long userId, String introduce, String chatLink, boolean isReceived) { + public AccompanyRequestDetailInfo(Long requestId, Long userId, String introduce, String chatLink, + boolean isReceived) { this.requestId = requestId; this.userId = userId; this.introduce = introduce; diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindBoardThumbnailsResult.java b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindBoardThumbnailsResult.java index 36e6ddd..0883102 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindBoardThumbnailsResult.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindBoardThumbnailsResult.java @@ -8,15 +8,12 @@ import com.dnd.accompany.domain.accompany.entity.enums.Region; -import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; @Getter @SuperBuilder -public class FindBoardThumbnailsResult extends FindSlicesResult{ +public class FindBoardThumbnailsResult extends FindSlicesResult { private final Long requestId; private final String title; private final Region region; diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindRecordThumbnailsResult.java b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindRecordThumbnailsResult.java index 100a94a..ac7c2cc 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindRecordThumbnailsResult.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindRecordThumbnailsResult.java @@ -8,15 +8,12 @@ import com.dnd.accompany.domain.accompany.entity.enums.Region; -import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; @Getter @SuperBuilder -public class FindRecordThumbnailsResult extends FindSlicesResult{ +public class FindRecordThumbnailsResult extends FindSlicesResult { private final Long requestId; private final String title; private final Region region; diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindSlicesResult.java b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindSlicesResult.java index a900769..69b20ff 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindSlicesResult.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/FindSlicesResult.java @@ -9,7 +9,6 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; @Getter @@ -19,7 +18,8 @@ public abstract class FindSlicesResult { private final String cursor; public static String getLastCursor(List result) { - if(result.isEmpty()) return null; + if (result.isEmpty()) + return null; return result.get(result.size() - 1).getCursor(); } diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/PageRequest.java b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/PageRequest.java index f181feb..8d14ba6 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/PageRequest.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/PageRequest.java @@ -2,14 +2,10 @@ import java.time.LocalDateTime; -import org.springframework.boot.context.properties.bind.DefaultValue; -import org.springframework.lang.Nullable; - import com.querydsl.core.BooleanBuilder; import com.querydsl.core.types.dsl.DateTimePath; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.core.types.dsl.NumberPath; -import com.querydsl.core.types.dsl.NumberTemplate; import com.querydsl.core.types.dsl.StringTemplate; import io.swagger.v3.oas.annotations.media.Schema; @@ -25,10 +21,12 @@ public record PageRequest( } } - public static BooleanBuilder cursorCondition(String cursor, DateTimePath updatedAt, NumberPath id) { + public static BooleanBuilder cursorCondition(String cursor, DateTimePath updatedAt, + NumberPath id) { BooleanBuilder builder = new BooleanBuilder(); - if (cursor == null) return builder; + if (cursor == null) + return builder; StringTemplate nextCursor = Expressions.stringTemplate( "CONCAT(DATE_FORMAT({0}, '%Y%m%d%H%i%S'), LPAD(CAST({1} AS STRING), 6, '0'))", diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/ReadAccompanyResponse.java b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/ReadAccompanyResponse.java index 6eaf7db..35ebb4f 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/ReadAccompanyResponse.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/ReadAccompanyResponse.java @@ -1,6 +1,5 @@ package com.dnd.accompany.domain.accompany.api.dto; - import com.dnd.accompany.domain.user.dto.UserProfileDetailResponse; public record ReadAccompanyResponse( diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/ReceivedAccompany.java b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/ReceivedAccompany.java index 565ef96..2e8859f 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/ReceivedAccompany.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/ReceivedAccompany.java @@ -32,14 +32,15 @@ public class ReceivedAccompany { private List userImageUrl; @Builder - public ReceivedAccompany(Long requestId, Long userId, String nickname, String provider, String profileImageUrl, String description, + public ReceivedAccompany(Long requestId, Long userId, String nickname, String provider, String profileImageUrl, + String description, Gender gender, int birthYear, String socialMediaUrl, Grade grade, List travelPreferences, List travelStyles, List foodPreferences, List userImageUrl) { this.requestId = requestId; this.userId = userId; - this.nickname = nickname; - this.provider = provider; - this.profileImageUrl = profileImageUrl; + this.nickname = nickname; + this.provider = provider; + this.profileImageUrl = profileImageUrl; this.description = description; this.gender = gender; this.birthYear = birthYear; diff --git a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/SendedAccompany.java b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/SendedAccompany.java index cca926d..6a86d1b 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/api/dto/SendedAccompany.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/api/dto/SendedAccompany.java @@ -23,7 +23,7 @@ public class SendedAccompany { @Builder public SendedAccompany(Long requestId, String title, Region region, LocalDateTime startDate, LocalDateTime endDate, - String nickname, List imageUrls) { + String nickname, List imageUrls) { this.requestId = requestId; this.title = title; this.region = region; diff --git a/src/main/java/com/dnd/accompany/domain/accompany/entity/AccompanyBoard.java b/src/main/java/com/dnd/accompany/domain/accompany/entity/AccompanyBoard.java index 1c7d400..a848211 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/entity/AccompanyBoard.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/entity/AccompanyBoard.java @@ -89,14 +89,14 @@ public class AccompanyBoard extends TimeBaseEntity { private boolean deleted = Boolean.FALSE; - public void remove(){ + public void remove() { this.boardStatus = REMOVED; } - public void addHeadCount(){ + public void addHeadCount() { headCount++; - if(headCount == capacity){ + if (headCount == capacity) { boardStatus = RECRUITMENT_COMPLETED; } } diff --git a/src/main/java/com/dnd/accompany/domain/accompany/entity/enums/Region.java b/src/main/java/com/dnd/accompany/domain/accompany/entity/enums/Region.java index 2defc28..4934207 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/entity/enums/Region.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/entity/enums/Region.java @@ -16,10 +16,6 @@ public enum Region { this.description = description; } - public String description() { - return description; - } - public static Region from(String keyword) { for (Region region : Region.values()) { if (region.description().contains(keyword)) { @@ -28,4 +24,8 @@ public static Region from(String keyword) { } return null; } + + public String description() { + return description; + } } diff --git a/src/main/java/com/dnd/accompany/domain/accompany/exception/accompanyrequest/AccompanyRequestNotFoundException.java b/src/main/java/com/dnd/accompany/domain/accompany/exception/accompanyrequest/AccompanyRequestNotFoundException.java index 6b105b5..74f187c 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/exception/accompanyrequest/AccompanyRequestNotFoundException.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/exception/accompanyrequest/AccompanyRequestNotFoundException.java @@ -4,5 +4,7 @@ import com.dnd.accompany.global.common.response.ErrorCode; public class AccompanyRequestNotFoundException extends BusinessException { - public AccompanyRequestNotFoundException(ErrorCode errorCode) {super(errorCode); } + public AccompanyRequestNotFoundException(ErrorCode errorCode) { + super(errorCode); + } } diff --git a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/AccompanyRequestRepository.java b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/AccompanyRequestRepository.java index 7f1a34f..63b6021 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/AccompanyRequestRepository.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/AccompanyRequestRepository.java @@ -8,7 +8,8 @@ import com.dnd.accompany.domain.accompany.entity.AccompanyRequest; import com.dnd.accompany.domain.accompany.infrastructure.querydsl.interfaces.AccompanyRequestRepositoryCustom; -public interface AccompanyRequestRepository extends JpaRepository, AccompanyRequestRepositoryCustom { +public interface AccompanyRequestRepository + extends JpaRepository, AccompanyRequestRepositoryCustom { void deleteByAccompanyBoardId(Long boardId); @Query("SELECT r FROM AccompanyRequest r WHERE r.accompanyBoard.id = :boardId AND r.user.id = :userId") diff --git a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/AccompanyUserRepository.java b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/AccompanyUserRepository.java index e42a756..783c854 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/AccompanyUserRepository.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/AccompanyUserRepository.java @@ -6,7 +6,6 @@ import org.springframework.data.jpa.repository.Query; import com.dnd.accompany.domain.accompany.entity.AccompanyUser; -import com.dnd.accompany.domain.accompany.entity.enums.Role; import com.dnd.accompany.domain.accompany.infrastructure.querydsl.interfaces.AccompanyUserRepositoryCustom; public interface AccompanyUserRepository extends JpaRepository, AccompanyUserRepositoryCustom { diff --git a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/AccompanyBoardRepositoryImpl.java b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/AccompanyBoardRepositoryImpl.java index f40335b..b798506 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/AccompanyBoardRepositoryImpl.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/AccompanyBoardRepositoryImpl.java @@ -4,25 +4,21 @@ import static com.dnd.accompany.domain.accompany.api.dto.PageRequest.*; import static com.dnd.accompany.domain.accompany.entity.QAccompanyBoard.*; import static com.dnd.accompany.domain.accompany.entity.QAccompanyImage.*; -import static com.dnd.accompany.domain.accompany.entity.QAccompanyRequest.*; import static com.dnd.accompany.domain.accompany.entity.QAccompanyTag.*; import static com.dnd.accompany.domain.accompany.entity.QAccompanyUser.*; -import static com.dnd.accompany.domain.accompany.entity.enums.Region.*; +import static com.dnd.accompany.domain.accompany.entity.enums.Region.from; import static com.dnd.accompany.domain.accompany.entity.enums.Role.*; import static com.dnd.accompany.domain.review.entity.QReview.*; import static com.dnd.accompany.domain.user.entity.QUser.*; +import static java.time.LocalDateTime.*; import java.util.List; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import org.springframework.data.domain.SliceImpl; import org.springframework.stereotype.Repository; import com.dnd.accompany.domain.accompany.api.dto.FindBoardThumbnailsResult; import com.dnd.accompany.domain.accompany.api.dto.FindRecordThumbnailsResult; -import com.dnd.accompany.domain.accompany.api.dto.FindSlicesResult; import com.dnd.accompany.domain.accompany.entity.enums.Region; import com.dnd.accompany.domain.accompany.infrastructure.querydsl.interfaces.AccompanyBoardRepositoryCustom; import com.querydsl.core.BooleanBuilder; @@ -106,6 +102,41 @@ public Slice findBoardThumbnails(String cursor, int s return createSlice(size, content); } + @Override + public Slice findBoardThumbnails(String cursor, int size, Region region, + boolean started) { + List content = queryFactory + .select(Projections.constructor(FindBoardThumbnailsResult.class, + accompanyBoard.id, + accompanyBoard.title, + accompanyBoard.region, + accompanyBoard.startDate, + accompanyBoard.endDate, + user.nickname, + Expressions.stringTemplate("GROUP_CONCAT(DISTINCT {0})", accompanyImage.imageUrl), + Expressions.stringTemplate( + "CONCAT(DATE_FORMAT({0}, '%Y%m%d%H%i%S'), LPAD(CAST({1} AS STRING), 6, '0'))", + accompanyBoard.updatedAt, + accompanyBoard.id + )) + ) + .from(accompanyUser) + .join(accompanyUser.accompanyBoard, accompanyBoard) + .join(accompanyUser.user, user) + .leftJoin(accompanyImage).on(accompanyImage.accompanyBoard.id.eq(accompanyBoard.id)) + .where(isHost()) + .where(isRegion(region)) + .where(isStarted(started)) + .where(cursorCondition(cursor, accompanyBoard.updatedAt, accompanyBoard.id)) + .groupBy(accompanyBoard.id, accompanyBoard.title, accompanyBoard.region, + accompanyBoard.startDate, accompanyBoard.endDate, user.nickname) + .orderBy(accompanyBoard.updatedAt.desc(), accompanyBoard.id.desc()) + .limit(size + 1) + .fetch(); + + return createSlice(size, content); + } + @Override public Slice findRecordThumbnails(String cursor, int size, Long userId) { List content = queryFactory @@ -204,7 +235,7 @@ private BooleanBuilder isRegion(Region region) { } public BooleanExpression isRegionKeyword(String keyword) { - if(from(keyword) == null) + if (from(keyword) == null) return accompanyBoard.region.isNull(); return accompanyBoard.region.eq(from(keyword)); @@ -224,4 +255,16 @@ private BooleanBuilder isContains(String keyword) { return booleanBuilder; } + + private BooleanBuilder isStarted(boolean started) { + BooleanBuilder clause = new BooleanBuilder(); + + if (started) { + clause.and(accompanyBoard.startDate.loe(now())); + return clause; + } + + clause.and(accompanyBoard.startDate.gt(now())); + return clause; + } } diff --git a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/interfaces/AccompanyBoardRepositoryCustom.java b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/interfaces/AccompanyBoardRepositoryCustom.java index ab5fa14..5a043c9 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/interfaces/AccompanyBoardRepositoryCustom.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/interfaces/AccompanyBoardRepositoryCustom.java @@ -7,13 +7,15 @@ import com.dnd.accompany.domain.accompany.entity.enums.Region; public interface AccompanyBoardRepositoryCustom { - + Slice findBoardThumbnails(String cursor, int size, Region region); + Slice findBoardThumbnails(String cursor, int size, Region region, boolean started); + Slice findRecordThumbnails(String cursor, int size, Long userId); Slice findBoardThumbnailsByHostId(String cursor, int size, Long userId); - + Slice findBoardThumbnailsByKeyword(String cursor, int size, String keyword); boolean isHostOfBoard(Long userId, Long boardId); diff --git a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/interfaces/AccompanyRequestRepositoryCustom.java b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/interfaces/AccompanyRequestRepositoryCustom.java index c347e20..5ab4f7f 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/interfaces/AccompanyRequestRepositoryCustom.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/infrastructure/querydsl/interfaces/AccompanyRequestRepositoryCustom.java @@ -1,12 +1,9 @@ package com.dnd.accompany.domain.accompany.infrastructure.querydsl.interfaces; -import java.util.Optional; - import org.springframework.data.domain.Slice; import com.dnd.accompany.domain.accompany.api.dto.FindApplicantDetailsResult; import com.dnd.accompany.domain.accompany.api.dto.FindBoardThumbnailsResult; -import com.dnd.accompany.domain.accompany.entity.AccompanyRequest; public interface AccompanyRequestRepositoryCustom { Slice findBoardThumbnails(String cursor, int size, Long applicantId); diff --git a/src/main/java/com/dnd/accompany/domain/accompany/service/AccompanyBoardService.java b/src/main/java/com/dnd/accompany/domain/accompany/service/AccompanyBoardService.java index 53799d1..139582c 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/service/AccompanyBoardService.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/service/AccompanyBoardService.java @@ -1,7 +1,6 @@ package com.dnd.accompany.domain.accompany.service; import static com.dnd.accompany.domain.accompany.api.dto.FindBoardThumbnailsResult.*; -import static com.dnd.accompany.domain.accompany.entity.AccompanyBoard.*; import java.util.List; @@ -15,7 +14,6 @@ import com.dnd.accompany.domain.accompany.api.dto.FindBoardThumbnailResult; import com.dnd.accompany.domain.accompany.api.dto.FindBoardThumbnailsResult; import com.dnd.accompany.domain.accompany.api.dto.FindRecordThumbnailsResult; - import com.dnd.accompany.domain.accompany.api.dto.PageRequest; import com.dnd.accompany.domain.accompany.api.dto.PageResponse; import com.dnd.accompany.domain.accompany.entity.AccompanyBoard; @@ -53,7 +51,8 @@ public AccompanyBoard save(CreateAccompanyBoardRequest request) { @Transactional(readOnly = true) public PageResponse getMyBoards(PageRequest request, Long userId) { - Slice sliceResult = accompanyBoardRepository.findBoardThumbnailsByHostId(request.cursor(), request.size(), userId); + Slice sliceResult = accompanyBoardRepository.findBoardThumbnailsByHostId( + request.cursor(), request.size(), userId); List thumbnails = getBoardThumbnails(sliceResult.getContent()); @@ -61,8 +60,9 @@ public PageResponse getMyBoards(PageRequest request, Lo } @Transactional(readOnly = true) - public PageResponse getMatchedBoards(PageRequest request, String keyword) { - Slice sliceResult = accompanyBoardRepository.findBoardThumbnailsByKeyword(request.cursor(), request.size(), keyword); + public PageResponse getMatchedBoards(PageRequest request, String keyword) { + Slice sliceResult = accompanyBoardRepository.findBoardThumbnailsByKeyword( + request.cursor(), request.size(), keyword); List thumbnails = getBoardThumbnails(sliceResult.getContent()); @@ -71,16 +71,28 @@ public PageResponse getMatchedBoards(PageRequest reques @Transactional(readOnly = true) public PageResponse getAllBoards(PageRequest request, Region region) { - Slice sliceResult = accompanyBoardRepository.findBoardThumbnails(request.cursor(), request.size(), region); - - List thumbnails = getBoardThumbnails(sliceResult.getContent()); + Slice sliceResult = accompanyBoardRepository.findBoardThumbnails(request.cursor(), + request.size(), region); + + List thumbnails = getBoardThumbnails(sliceResult.getContent()); return new PageResponse<>(sliceResult.hasNext(), thumbnails, getLastCursor(sliceResult.getContent())); - } + } + + @Transactional(readOnly = true) + public PageResponse getAllBoards(PageRequest request, Region region, boolean started) { + Slice sliceResult = accompanyBoardRepository.findBoardThumbnails(request.cursor(), + request.size(), region, started); + + List thumbnails = getBoardThumbnails(sliceResult.getContent()); + + return new PageResponse<>(sliceResult.hasNext(), thumbnails, getLastCursor(sliceResult.getContent())); + } @Transactional(readOnly = true) public PageResponse getAllRecords(PageRequest request, Long userId) { - Slice sliceResult = accompanyBoardRepository.findRecordThumbnails(request.cursor(), request.size(), userId); + Slice sliceResult = accompanyBoardRepository.findRecordThumbnails(request.cursor(), + request.size(), userId); List thumbnails = getRecordThumbnails(sliceResult.getContent()); @@ -122,29 +134,29 @@ private List getRecordThumbnails(List new AccompanyBoardNotFoundException(ErrorCode.ACCOMPANY_BOARD_NOT_FOUND)); } @Transactional(readOnly = true) - public boolean isHostOfBoard(Long userId, Long boardId){ + public boolean isHostOfBoard(Long userId, Long boardId) { return accompanyBoardRepository.isHostOfBoard(userId, boardId); } @Transactional(readOnly = true) - public AccompanyBoard getById(Long boardId){ + public AccompanyBoard getById(Long boardId) { return accompanyBoardRepository.findById(boardId) .orElseThrow(() -> new AccompanyBoardNotFoundException(ErrorCode.ACCOMPANY_BOARD_NOT_FOUND)); } @Transactional - public void deleteByBoardId(Long boardId){ + public void deleteByBoardId(Long boardId) { accompanyBoardRepository.deleteById(boardId); } @Transactional(readOnly = true) - public FindBoardThumbnailResult getBoardThumbnail(Long boardId){ + public FindBoardThumbnailResult getBoardThumbnail(Long boardId) { return accompanyBoardRepository.findBoardThumbnail(boardId) .orElseThrow(() -> new AccompanyBoardNotFoundException(ErrorCode.ACCOMPANY_BOARD_NOT_FOUND)); } diff --git a/src/main/java/com/dnd/accompany/domain/accompany/service/AccompanyRequestService.java b/src/main/java/com/dnd/accompany/domain/accompany/service/AccompanyRequestService.java index c037ec8..205764c 100644 --- a/src/main/java/com/dnd/accompany/domain/accompany/service/AccompanyRequestService.java +++ b/src/main/java/com/dnd/accompany/domain/accompany/service/AccompanyRequestService.java @@ -42,6 +42,53 @@ public class AccompanyRequestService { private final AccompanyRequestRepository accompanyRequestRepository; private final UserProfileRepository userProfileRepository; + /** + * imageUrls의 타입을 String -> List로 변환합니다. + */ + private static List getReceivedAccompanies(List results, + Map userProfileMap) { + return results.stream() + .map(result -> { + UserProfile userProfile = userProfileMap.get(result.getUserId()); + + return ReceivedAccompany.builder() + .requestId(result.getRequestId()) + .userId(result.getUserId()) + .nickname(result.getNickname()) + .provider(result.getProvider()) + .profileImageUrl(result.getProfileImageUrl()) + .description(userProfile.getDescription()) + .gender(userProfile.getGender()) + .birthYear(userProfile.getBirthYear()) + .socialMediaUrl(userProfile.getSocialMediaUrl()) + .grade(userProfile.getGrade()) + .travelPreferences(userProfile.getTravelPreferences()) + .travelStyles(userProfile.getTravelStyles()) + .foodPreferences(userProfile.getFoodPreferences()) + .userImageUrl(result.getImageUrlsAsList()) + .build(); + }) + .toList(); + } + + /** + * imageUrls의 타입을 String -> List로 변환합니다. + */ + private static List getSendedAccompanies(List results) { + List sendedAccompanies = results.stream() + .map(result -> SendedAccompany.builder() + .requestId(result.getRequestId()) + .title(result.getTitle()) + .region(result.getRegion()) + .startDate(result.getStartDate()) + .endDate(result.getEndDate()) + .nickname(result.getNickname()) + .imageUrls(result.getImageUrlsAsList()) + .build()) + .toList(); + return sendedAccompanies; + } + @Transactional public AccompanyRequest getAccompanyRequest(Long requestId) { return accompanyRequestRepository.findById(requestId) @@ -90,35 +137,6 @@ private Map getUserProfileMap(Set userIds) { .collect(Collectors.toMap(UserProfile::getUserId, userProfile -> userProfile)); } - /** - * imageUrls의 타입을 String -> List로 변환합니다. - */ - private static List getReceivedAccompanies(List results, - Map userProfileMap) { - return results.stream() - .map(result -> { - UserProfile userProfile = userProfileMap.get(result.getUserId()); - - return ReceivedAccompany.builder() - .requestId(result.getRequestId()) - .userId(result.getUserId()) - .nickname(result.getNickname()) - .provider(result.getProvider()) - .profileImageUrl(result.getProfileImageUrl()) - .description(userProfile.getDescription()) - .gender(userProfile.getGender()) - .birthYear(userProfile.getBirthYear()) - .socialMediaUrl(userProfile.getSocialMediaUrl()) - .grade(userProfile.getGrade()) - .travelPreferences(userProfile.getTravelPreferences()) - .travelStyles(userProfile.getTravelStyles()) - .foodPreferences(userProfile.getFoodPreferences()) - .userImageUrl(result.getImageUrlsAsList()) - .build(); - }) - .toList(); - } - @Transactional(readOnly = true) public PageResponse getAllSendedAccompanies(PageRequest request, Long applicantId) { Slice sliceResult = accompanyRequestRepository.findBoardThumbnails(request.cursor(), @@ -129,24 +147,6 @@ public PageResponse getAllSendedAccompanies(PageRequest request return new PageResponse<>(sliceResult.hasNext(), sendedAccompanies, getLastCursor(sliceResult.getContent())); } - /** - * imageUrls의 타입을 String -> List로 변환합니다. - */ - private static List getSendedAccompanies(List results) { - List sendedAccompanies = results.stream() - .map(result -> SendedAccompany.builder() - .requestId(result.getRequestId()) - .title(result.getTitle()) - .region(result.getRegion()) - .startDate(result.getStartDate()) - .endDate(result.getEndDate()) - .nickname(result.getNickname()) - .imageUrls(result.getImageUrlsAsList()) - .build()) - .toList(); - return sendedAccompanies; - } - @Transactional public void deleteByBoardId(Long boardId) { accompanyRequestRepository.deleteByAccompanyBoardId(boardId); diff --git a/src/main/java/com/dnd/accompany/domain/qna100/api/dto/CreateAndUpdateQnaRequest.java b/src/main/java/com/dnd/accompany/domain/qna100/api/dto/CreateAndUpdateQnaRequest.java index b169a93..1e933a9 100644 --- a/src/main/java/com/dnd/accompany/domain/qna100/api/dto/CreateAndUpdateQnaRequest.java +++ b/src/main/java/com/dnd/accompany/domain/qna100/api/dto/CreateAndUpdateQnaRequest.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import com.dnd.accompany.domain.qna100.entity.Qna100; diff --git a/src/main/java/com/dnd/accompany/domain/qna100/api/dto/Qna.java b/src/main/java/com/dnd/accompany/domain/qna100/api/dto/Qna.java index c287fb7..b7eb1f1 100644 --- a/src/main/java/com/dnd/accompany/domain/qna100/api/dto/Qna.java +++ b/src/main/java/com/dnd/accompany/domain/qna100/api/dto/Qna.java @@ -10,7 +10,7 @@ public record Qna( @Size(max = 2000) String answer ) { - public static Qna from(Qna100 qna100){ + public static Qna from(Qna100 qna100) { return new Qna(qna100.getId(), qna100.getQuestion(), qna100.getAnswer()); } } diff --git a/src/main/java/com/dnd/accompany/domain/qna100/api/dto/ReadQnaResponse.java b/src/main/java/com/dnd/accompany/domain/qna100/api/dto/ReadQnaResponse.java index 106280f..792bbe0 100644 --- a/src/main/java/com/dnd/accompany/domain/qna100/api/dto/ReadQnaResponse.java +++ b/src/main/java/com/dnd/accompany/domain/qna100/api/dto/ReadQnaResponse.java @@ -10,9 +10,9 @@ public record ReadQnaResponse( List qnas ) { - public static ReadQnaResponse from(List qna100s){ + public static ReadQnaResponse from(List qna100s) { return new ReadQnaResponse(qna100s.stream() - .map(Qna::from) - .collect(toList())); + .map(Qna::from) + .collect(toList())); } } diff --git a/src/main/java/com/dnd/accompany/domain/qna100/entity/Qna100.java b/src/main/java/com/dnd/accompany/domain/qna100/entity/Qna100.java index 8badf5e..1b31dc2 100644 --- a/src/main/java/com/dnd/accompany/domain/qna100/entity/Qna100.java +++ b/src/main/java/com/dnd/accompany/domain/qna100/entity/Qna100.java @@ -27,30 +27,21 @@ @SQLDelete(sql = "UPDATE qna100s SET deleted = true WHERE id = ?") public class Qna100 extends TimeBaseEntity { + public static final String QUESTION1 = "고기 vs 해산물"; + public static final String QUESTION2 = "액티비티 vs 힐링"; + public static final String QUESTION3 = "낮 vs 밤 활동성이 많은 시간"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @Column(nullable = false) private Long userId; - @Column(length = 2000) private String question; - @Column(length = 2000) private String answer; - private boolean deleted = false; - public void setQuestion(String question) { - this.question = question; - } - - public void setAnswer(String answer) { - this.answer = answer; - } - - public static Qna100 from(Long userId, String question, String answer){ + public static Qna100 from(Long userId, String question, String answer) { return Qna100.builder() .userId(userId) .question(question) @@ -58,7 +49,11 @@ public static Qna100 from(Long userId, String question, String answer){ .build(); } - public static final String QUESTION1 = "고기 vs 해산물"; - public static final String QUESTION2 = "액티비티 vs 힐링"; - public static final String QUESTION3 = "낮 vs 밤 활동성이 많은 시간"; + public void setQuestion(String question) { + this.question = question; + } + + public void setAnswer(String answer) { + this.answer = answer; + } } diff --git a/src/main/java/com/dnd/accompany/domain/qna100/infrastructure/QnaRepository.java b/src/main/java/com/dnd/accompany/domain/qna100/infrastructure/QnaRepository.java index dac49e4..6105c74 100644 --- a/src/main/java/com/dnd/accompany/domain/qna100/infrastructure/QnaRepository.java +++ b/src/main/java/com/dnd/accompany/domain/qna100/infrastructure/QnaRepository.java @@ -12,6 +12,8 @@ @Repository public interface QnaRepository extends JpaRepository, QnaRepositoryCustom { Optional findFirstByUserId(Long userId); + void deleteByIdIn(List ids); + List findAllByUserId(Long userId); } diff --git a/src/main/java/com/dnd/accompany/domain/qna100/service/QnaService.java b/src/main/java/com/dnd/accompany/domain/qna100/service/QnaService.java index d2e9189..7cb5828 100644 --- a/src/main/java/com/dnd/accompany/domain/qna100/service/QnaService.java +++ b/src/main/java/com/dnd/accompany/domain/qna100/service/QnaService.java @@ -66,13 +66,13 @@ public ReadQnaResponse getAllQnas(Long userId) { return ReadQnaResponse.from(qnas); } - public void init(Long userId){ + public void init(Long userId) { List qnas = List.of( - Qna100.from(userId, QUESTION1, ""), + Qna100.from(userId, QUESTION1, ""), Qna100.from(userId, QUESTION2, ""), Qna100.from(userId, QUESTION3, "") ); - qnaRepository.saveAll(qnas); + qnaRepository.saveAll(qnas); } }