Skip to content

Commit

Permalink
Merge pull request #49 from dnd-side-project/main
Browse files Browse the repository at this point in the history
#47 Develop에 Main Merge
  • Loading branch information
min-0 authored Sep 11, 2024
2 parents 3ba4e47 + 4b73706 commit a09f6cf
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 94 deletions.
13 changes: 2 additions & 11 deletions src/main/java/com/dnd/dndtravel/map/controller/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import com.dnd.dndtravel.map.controller.request.validation.PhotoValidation;
import com.dnd.dndtravel.map.controller.swagger.MapControllerSwagger;
import com.dnd.dndtravel.map.service.MapService;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordDetailViewResponse;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordResponse;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordsResponse;
import com.dnd.dndtravel.map.service.dto.response.RegionResponse;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -50,23 +50,14 @@ public void memo(
//커서를 0으로 주면 최신 게시글을을 displayPerPage별로 조회함
//서버에서 클라에 마지막 게시글의 ID를 줘야함
@GetMapping("/maps/history")
public List<AttractionRecordResponse> findRecords(
public AttractionRecordsResponse findRecords(
AuthenticationMember authenticationMember,
@RequestParam(defaultValue = "0") long cursorNo,
@RequestParam(defaultValue = "10") int displayPerPage
) {
return mapService.allRecords(authenticationMember.id(), cursorNo, displayPerPage);
}

// 기록 단건 조회
@GetMapping("/maps/history/{recordId}")
public AttractionRecordDetailViewResponse findRecord(
AuthenticationMember authenticationMember,
@PathVariable long recordId
) {
return mapService.findOneVisitRecord(authenticationMember.id(), recordId);
}

@PutMapping(value = "/maps/history/{recordId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void updateRecord(
AuthenticationMember authenticationMember,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.dnd.dndtravel.config.AuthenticationMember;
import com.dnd.dndtravel.map.controller.request.RecordRequest;
import com.dnd.dndtravel.map.controller.request.UpdateRecordRequest;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordDetailViewResponse;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordResponse;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordsResponse;
import com.dnd.dndtravel.map.service.dto.response.RegionResponse;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -83,7 +83,7 @@ void memo(
),
})
@AuthenticationCommonResponse
List<AttractionRecordResponse> findRecords(
AttractionRecordsResponse findRecords(
@Parameter(hidden = true)
AuthenticationMember authenticationMember,
@Parameter(description = "게시글의 ID값, 0 혹은 미입력시 가장최신 페이지 조회", example = "이전요청의 마지막 게시글ID가 7인경우 7로 요청시 다음 페이지 게시글 조회")
Expand All @@ -92,27 +92,6 @@ List<AttractionRecordResponse> findRecords(
int displayPerPage
);

@Operation(
summary = "인증된 사용자의 방문 기록 단건 조회"
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정상조회, 단일 JSON객체 반환",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = AttractionRecordDetailViewResponse.class))),
@ApiResponse(responseCode = "400", description = "유저정보나 방문기록이 유효하지 않은경우",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(example = STATUS_CODE_400_BODY_MESSAGE)
)
),
})
@AuthenticationCommonResponse
AttractionRecordDetailViewResponse findRecord(
@Parameter(hidden = true)
AuthenticationMember authenticationMember,
@Parameter(description = "방문기록 id값", required = true)
long recordId
);

@Operation(
summary = "인증된 사용자의 방문 기록 수정"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface MemberAttractionRepositoryCustom {
Long maxCursor(long memberId);

List<RecordProjection> findAttractionRecords(long memberId, long cursorNo, int displayPerPage);

Long entireVisitCount(long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@
import static com.dnd.dndtravel.member.domain.QMember.member;

import java.util.List;
import java.util.Optional;

import com.dnd.dndtravel.map.domain.MemberAttraction;
import com.dnd.dndtravel.map.repository.dto.projection.RecordProjection;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.core.types.dsl.NumberPath;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;
Expand All @@ -22,7 +15,6 @@
public class MemberAttractionRepositoryImpl implements MemberAttractionRepositoryCustom {

private final JPAQueryFactory jpaQueryFactory;
private final NumberPath<Long> entireRecordCount = Expressions.numberPath(Long.class, "entireRecordCount");

/**
* select max(ma.id)
Expand All @@ -48,22 +40,25 @@ public Long maxCursor(long memberId) {
public List<RecordProjection> findAttractionRecords(long memberId, long cursorNo, int displayPerPage) {
return jpaQueryFactory.select(Projections.constructor(RecordProjection.class,
memberAttraction.id,
ExpressionUtils.as(JPAExpressions
.select(memberAttraction.id.count())
.from(memberAttraction)
.where(memberAttraction.member.id.eq(member.id)), entireRecordCount
),
memberAttraction.memo,
memberAttraction.localDate,
memberAttraction.region,
attraction
))
.from(memberAttraction)
.join(member).on(memberAttraction.member.id.eq(member.id))
.join(member).on(memberAttraction.member.id.eq(memberId))
.join(attraction).on(memberAttraction.attraction.id.eq(attraction.id))
.where(memberAttraction.id.lt(cursorNo))
.orderBy(memberAttraction.id.desc())
.limit(displayPerPage)
.fetch();
}

@Override
public Long entireVisitCount(long memberId) {
return jpaQueryFactory.select(memberAttraction.id.count())
.from(memberAttraction)
.where(memberAttraction.member.id.eq(memberId))
.fetchOne();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
@Getter
public class RecordProjection {
private final long memberAttractionId;
private final long entireRecordCount;
private String attractionName;
private final String memo;
private final LocalDate visitDate;
private final String region;
private final Attraction attraction;
private List<String> photoUrls;

public RecordProjection(long memberAttractionId, long entireRecordCount, String memo,
public RecordProjection(long memberAttractionId, String memo,
LocalDate visitDate, String region, Attraction attraction) {
this.memberAttractionId = memberAttractionId;
this.entireRecordCount = entireRecordCount;
this.memo = memo;
this.visitDate = visitDate;
this.region = region;
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/com/dnd/dndtravel/map/service/MapService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import com.dnd.dndtravel.map.repository.dto.projection.AttractionPhotoProjection;
import com.dnd.dndtravel.map.repository.dto.projection.RecordProjection;
import com.dnd.dndtravel.map.service.dto.RegionDto;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordDetailViewResponse;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordResponse;
import com.dnd.dndtravel.map.service.dto.response.AttractionRecordsResponse;
import com.dnd.dndtravel.map.service.dto.response.RegionResponse;
import com.dnd.dndtravel.map.repository.AttractionRepository;
import com.dnd.dndtravel.map.repository.MemberAttractionRepository;
Expand Down Expand Up @@ -90,37 +90,29 @@ public void recordAttraction(RecordDto recordDto, long memberId) {

// 모든 기록 조회
@Transactional(readOnly = true)
public List<AttractionRecordResponse> allRecords(long memberId, long cursorNo, int displayPerPage) {
public AttractionRecordsResponse allRecords(long memberId, long cursorNo, int displayPerPage) {
//validation
Member member = memberRepository.findById(memberId).orElseThrow(() -> new MemberNotFoundException(memberId));
List<MemberAttraction> memberAttractions = memberAttractionRepository.findByMemberId(memberId);
if (memberAttractions.isEmpty()) {
return List.of();
return new AttractionRecordsResponse(0, List.of());
}

// 첫 커서값인 경우
if (cursorNo <= 0) {
cursorNo = memberAttractionRepository.maxCursor(member.getId());
}
List<RecordProjection> attractionRecords = memberAttractionRepository.findAttractionRecords(memberId, cursorNo, displayPerPage);
Long visitCount = memberAttractionRepository.entireVisitCount(memberId);

// 명소명 저장
attractionRecords.forEach(RecordProjection::inputAttractionNames);
// 사진 URL 저장
setPhotoUrlsWithJoin(attractionRecords);

return attractionRecords.stream()
return new AttractionRecordsResponse(visitCount, attractionRecords.stream()
.map(AttractionRecordResponse::from)
.toList();
}

//기록 단건 조회
@Transactional(readOnly = true)
public AttractionRecordDetailViewResponse findOneVisitRecord(long memberId, long memberAttractionId) {
//todo memberAttraction 쿼리한방으로 줄일수도 있을것같다.
Member member = memberRepository.findById(memberId).orElseThrow(() -> new MemberNotFoundException(memberId));
MemberAttraction memberAttraction = memberAttractionRepository.findById(memberAttractionId).orElseThrow(() -> new MemberAttractionNotFoundException(memberAttractionId));
return AttractionRecordDetailViewResponse.from(memberAttraction);
.toList());
}

// 방문기록 수정
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
public record AttractionRecordResponse(
@Schema(description = "방문기록 id", requiredMode = REQUIRED)
long id,
@Schema(description = "방문기록 전체개수", requiredMode = REQUIRED)
long entireRecordCount,
@Schema(description = "지역명", requiredMode = REQUIRED)
String region,
@Schema(description = "명소명", requiredMode = REQUIRED)
Expand All @@ -31,7 +29,6 @@ public record AttractionRecordResponse(
public static AttractionRecordResponse from(RecordProjection recordProjection) {
return AttractionRecordResponse.builder()
.id(recordProjection.getMemberAttractionId())
.entireRecordCount(recordProjection.getEntireRecordCount())
.attractionName(recordProjection.getAttractionName())
.memo(recordProjection.getMemo())
.visitDate(recordProjection.getVisitDate())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dnd.dndtravel.map.service.dto.response;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import java.util.List;

import io.swagger.v3.oas.annotations.media.Schema;

public record AttractionRecordsResponse(
@Schema(description = "방문기록 전체개수", requiredMode = REQUIRED)
long entireRecordCount,
@Schema(description = "방문기록 리스트들", requiredMode = REQUIRED)
List<AttractionRecordResponse> recordResponses
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

@Getter
public enum SelectedColor {
RED("RED"),
PINK("PINK"),
ORANGE("ORANGE"),
YELLOW("YELLOW"),
MELON("MELON"),
GREEN("GREEN"),
BLUE("BLUE"),
PURPLE("PURPLE");

Expand Down

0 comments on commit a09f6cf

Please sign in to comment.