Skip to content

Commit

Permalink
Merge pull request #59 from PLOTTING-PLOWER/feat/syj/refactorLast
Browse files Browse the repository at this point in the history
✨:isStar 추가하기 위한 dto 생성
  • Loading branch information
syjdjr authored Dec 2, 2024
2 parents c19b7e7 + 5184f77 commit a95de30
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/prod-cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Java CI with Gradle

on:
push:
branches: [ "develop", "test" ]
branches: [ "develop" ]

permissions:
contents: read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.plotting.server.plogging.dto.response.*;
import com.plotting.server.plogging.exception.PloggingNotFoundException;
import com.plotting.server.plogging.repository.PloggingRepository;
import com.plotting.server.plogging.repository.PloggingStarRepository;
import com.plotting.server.plogging.repository.PloggingUserRepository;
import com.plotting.server.user.application.UserService;
import com.plotting.server.user.domain.User;
Expand All @@ -23,6 +24,7 @@
import java.time.LocalDateTime;
import java.util.List;

import static com.plotting.server.plogging.domain.QPlogging.plogging;
import static com.plotting.server.plogging.exception.errorcode.PloggingErrorCode.PLOGGING_NOT_FOUND;
import static com.plotting.server.plogging.util.PloggingConstants.*;

Expand All @@ -37,21 +39,24 @@ public class PloggingService {
private final UserRepository userRepository;
private final PloggingRepository ploggingRepository;
private final PloggingUserRepository ploggingUserRepository;
private final PloggingStarRepository ploggingStarRepository;

//플로깅 검색-> 상단 제일 첫번째 1개만 검색
public PloggingResponse getPloggingWithTitle(String title) {
PloggingResponse plogging = ploggingRepository.findByTitleContaining(title)
public PloggingGetStarResponse getPloggingWithTitle(String title) {
return ploggingRepository.findByTitleContaining(title)
.stream()
.map(PloggingResponse::from)
.findFirst()
.orElseThrow(() -> new PloggingNotFoundException(PLOGGING_NOT_FOUND));

return plogging;
.map(plogging -> {
Boolean isStar = ploggingStarRepository.existsByUserIdAndPloggingId(plogging.getUser().getId(), plogging.getId());
Long currentPeople = ploggingUserRepository.countActivePloggingUsersByPloggingId(plogging.getId());
return PloggingGetStarResponse.of(plogging, currentPeople ,isStar);
})
.findFirst() // 첫 번째 항목을 선택
.orElseThrow(() -> new PloggingNotFoundException(PLOGGING_NOT_FOUND)); // 예외 처리
}

//플로깅 홈
public HomeResponse getHome(Long userId) {
PloggingListResponse plogging = getPloggingStar();
PloggingGetStarListResponse plogging = getPloggingStar();
PlowerListResponse plowerStar = getPlowerStar();
User user = userService.getUser(userId);

Expand All @@ -68,14 +73,19 @@ private PlowerListResponse getPlowerStar() {
}

// 플로깅 즐겨찾기
private PloggingListResponse getPloggingStar() {
List<PloggingResponse> ploggingList = ploggingRepository.findTop3Ploggings().stream()
.map(PloggingResponse::from)
private PloggingGetStarListResponse getPloggingStar() {
List<PloggingGetStarResponse> ploggingList = ploggingRepository.findTop3Ploggings().stream()
.map(plogging -> {
Boolean isStar = ploggingStarRepository.existsByUserIdAndPloggingId(plogging.getUser().getId(), plogging.getId());
Long currentPeople = ploggingUserRepository.countActivePloggingUsersByPloggingId(plogging.getId());
return PloggingGetStarResponse.of(plogging, currentPeople, isStar);
})
.toList();

return PloggingListResponse.from(ploggingList);
return PloggingGetStarListResponse.from(ploggingList);
}


//플로깅 모임 등록
@Transactional
public void createPlogging(Long userId, PloggingRequest ploggingRequest, GeocodeResponse start, GeocodeResponse dest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@

@Builder
public record HomeResponse(
PloggingListResponse ploggingStarResponseList,
PloggingGetStarListResponse ploggingGetStarResponseList,
PlowerListResponse plowerResponseList,
String userNickname
String userNickname,
String userImageUrl
) {
public static HomeResponse of(PloggingListResponse ploggingListResponse,
public static HomeResponse of(PloggingGetStarListResponse ploggingGetStarListResponse,
PlowerListResponse plowerResponseList,
User user) {
return HomeResponse.builder()
.ploggingStarResponseList(ploggingListResponse)
.ploggingGetStarResponseList(ploggingGetStarListResponse)
.plowerResponseList(plowerResponseList)
.userNickname(user.getNickname())
.userImageUrl(user.getProfileImageUrl())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.plotting.server.plogging.dto.response;

import lombok.Builder;

import java.util.List;

@Builder
public record PloggingGetStarListResponse(
List<PloggingGetStarResponse> ploggingGetStarResponseList
) {
public static PloggingGetStarListResponse from(List<PloggingGetStarResponse> ploggingGetStarResponseList) {
return PloggingGetStarListResponse.builder()
// .currentPeople(currentPeople)
.ploggingGetStarResponseList(ploggingGetStarResponseList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.plotting.server.plogging.dto.response;

import com.plotting.server.plogging.domain.Plogging;
import com.plotting.server.plogging.domain.type.PloggingType;
import lombok.Builder;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Builder
public record PloggingGetStarResponse(
Long ploggingId,
String title,
Long currentPeople,
Long maxPeople,
PloggingType ploggingType,
LocalDate recruitEndDate,
LocalDateTime startTime,
Long spendTime,
String startLocation,
Boolean isStar
) {
public static PloggingGetStarResponse of(Plogging plogging, Long currentPeople, Boolean isStar) {
return PloggingGetStarResponse.builder()
.ploggingId(plogging.getId())
.title(plogging.getTitle())
.currentPeople(currentPeople)
.maxPeople(plogging.getMaxPeople())
.ploggingType(plogging.getPloggingType())
.recruitEndDate(plogging.getRecruitEndDate())
.startTime(plogging.getStartTime())
.spendTime(plogging.getSpendTime())
.startLocation(plogging.getStartLocation())
.isStar(isStar)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.plotting.server.plogging.dto.response;

import com.plotting.server.plogging.domain.PloggingStar;
import lombok.Builder;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PloggingController {
public ResponseEntity<ResponseTemplate<?>> getPloggingWithTitle(
@PathVariable String title) {

PloggingResponse response = ploggingService.getPloggingWithTitle(title);
PloggingGetStarResponse response = ploggingService.getPloggingWithTitle(title);

return ResponseEntity
.status(HttpStatus.OK)
Expand Down Expand Up @@ -76,7 +76,7 @@ public ResponseEntity<ResponseTemplate<?>> createPlogging(
.body(ResponseTemplate.EMPTY_RESPONSE);
}

@Operation(summary = "플로깅 리스트 조회", description = "플로깅 리스트 조회 화면입니다.<br> region: 서울, startDate: 2024-10-01, endDate: 2025-10-01, type: DIRECT, spendTime: 60, startTime: 2024-10-01T10:00:00, maxPeople: 10")
@Operation(summary = "플로깅 리스트 조회", description = "플로깅 리스트 조회 화면입니다.<br> region: 서울, startDate: 2024-10-01, endDate: 2025-10-01, type: ASSIGN, spendTime: 120, startTime: 2024-10-01T10:00:00, maxPeople: 10")
@GetMapping("/filter")
public ResponseEntity<ResponseTemplate<?>> findListByFilter(@RequestParam(defaultValue = "서울") String region,
@RequestParam(defaultValue = "2024-10-01") LocalDate startDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.plotting.server.plogging.dto.response.PloggingResponse;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.plotting.server.user.domain.UserType.Role;
import com.plotting.server.user.dto.OAuthAttributes;
import com.plotting.server.user.repository.UserRepository;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand Down

0 comments on commit a95de30

Please sign in to comment.