Skip to content

Commit

Permalink
feat: 동행 시작 여부에 따른 동행글 목록 조회 api를 추가한다. (#60)
Browse files Browse the repository at this point in the history
* feat: 동행 시작 여부에 따른 동행글 목록 조회 api를 추가한다.

* style: 코드를 reformatting 한다.
- 들여쓰기, 줄바꿈 등
  • Loading branch information
min429 authored Nov 5, 2024
1 parent cea18b2 commit ca9efce
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 138 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -67,6 +63,15 @@ public ResponseEntity<PageResponse<AccompanyBoardThumbnail>> readAll(
return ResponseEntity.ok(accompanyBoardService.getAllBoards(request, region));
}

@Operation(summary = "동행 시작 여부에 따른 동행글 목록 조회")
@PostMapping("/all/by-started")
public ResponseEntity<PageResponse<AccompanyBoardThumbnail>> 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<PageResponse<AccompanyBoardThumbnail>> readMine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public ResponseEntity<Void> approve(

@Operation(summary = "동행 신청 거절")
@PostMapping("/decline/{id}")
public ResponseEntity<Void> decline(
@PathVariable("id") Long requestId,
@AuthenticationPrincipal JwtAuthentication user) {
public ResponseEntity<Void> decline(
@PathVariable("id") Long requestId,
@AuthenticationPrincipal JwtAuthentication user) {
accompanyServiceFacade.declineRequest(requestId, user.getId());
return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Getter
Expand All @@ -19,7 +18,8 @@ public abstract class FindSlicesResult {
private final String cursor;

public static <T extends FindSlicesResult> String getLastCursor(List<T> result) {
if(result.isEmpty()) return null;
if (result.isEmpty())
return null;

return result.get(result.size() - 1).getCursor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,10 +21,12 @@ public record PageRequest(
}
}

public static BooleanBuilder cursorCondition(String cursor, DateTimePath<LocalDateTime> updatedAt, NumberPath<Long> id) {
public static BooleanBuilder cursorCondition(String cursor, DateTimePath<LocalDateTime> updatedAt,
NumberPath<Long> 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'))",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.dnd.accompany.domain.accompany.api.dto;


import com.dnd.accompany.domain.user.dto.UserProfileDetailResponse;

public record ReadAccompanyResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ public class ReceivedAccompany {
private List<String> 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<TravelPreference> travelPreferences,
List<TravelStyle> travelStyles, List<FoodPreference> foodPreferences, List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SendedAccompany {

@Builder
public SendedAccompany(Long requestId, String title, Region region, LocalDateTime startDate, LocalDateTime endDate,
String nickname, List<String> imageUrls) {
String nickname, List<String> imageUrls) {
this.requestId = requestId;
this.title = title;
this.region = region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -28,4 +24,8 @@ public static Region from(String keyword) {
}
return null;
}

public String description() {
return description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccompanyRequest, Long>, AccompanyRequestRepositoryCustom {
public interface AccompanyRequestRepository
extends JpaRepository<AccompanyRequest, Long>, AccompanyRequestRepositoryCustom {
void deleteByAccompanyBoardId(Long boardId);

@Query("SELECT r FROM AccompanyRequest r WHERE r.accompanyBoard.id = :boardId AND r.user.id = :userId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccompanyUser, Long>, AccompanyUserRepositoryCustom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -106,6 +102,41 @@ public Slice<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int s
return createSlice(size, content);
}

@Override
public Slice<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int size, Region region,
boolean started) {
List<FindBoardThumbnailsResult> 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<FindRecordThumbnailsResult> findRecordThumbnails(String cursor, int size, Long userId) {
List<FindRecordThumbnailsResult> content = queryFactory
Expand Down Expand Up @@ -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));
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import com.dnd.accompany.domain.accompany.entity.enums.Region;

public interface AccompanyBoardRepositoryCustom {

Slice<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int size, Region region);

Slice<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int size, Region region, boolean started);

Slice<FindRecordThumbnailsResult> findRecordThumbnails(String cursor, int size, Long userId);

Slice<FindBoardThumbnailsResult> findBoardThumbnailsByHostId(String cursor, int size, Long userId);

Slice<FindBoardThumbnailsResult> findBoardThumbnailsByKeyword(String cursor, int size, String keyword);

boolean isHostOfBoard(Long userId, Long boardId);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<FindBoardThumbnailsResult> findBoardThumbnails(String cursor, int size, Long applicantId);
Expand Down
Loading

0 comments on commit ca9efce

Please sign in to comment.