Skip to content

Commit

Permalink
Merge pull request #50 from imdangg/feat/fix
Browse files Browse the repository at this point in the history
인사이트 API 수정
  • Loading branch information
yeonkyungJoo authored Jan 20, 2025
2 parents 49e00d9 + a81b9ed commit c9801b7
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ public enum ErrorCode {
MEMBER_15ACCUSED,
ALREADY_ACCUSED,
ALREADY_RECOMMENDED,
EXCHANGE_REQUIRED
EXCHANGE_REQUIRED,

// 요청 실패
EXCHANGE_REQUEST_FAILED,
// 요청 수락 실패
EXCHANGE_REQUEST_ACCEPT_FAILED,
// 요청 거절 실패
EXCHANGE_REQUEST_REJECT_FAILED
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.project.imdang.domain.event.DomainEvent;

public interface SagaStep<T, S extends DomainEvent, U extends DomainEvent> {
public interface SagaStep<T, S extends DomainEvent> {
S process(T data);
U rollback(T data);
void rollback(T data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.project.imdang.insight.service.domain.dto.insight.list.ApartmentComplexResponse;
import com.project.imdang.insight.service.domain.dto.insight.list.DistrictResponse;
import com.project.imdang.insight.service.domain.dto.insight.list.InsightResponse;
import com.project.imdang.insight.service.domain.dto.insight.list.InsightSimpleResponse;
import com.project.imdang.insight.service.domain.dto.insight.list.ListMyInsightCreatedByMeQuery;
import com.project.imdang.insight.service.domain.dto.insight.list.ListMyInsightQuery;
import com.project.imdang.insight.service.domain.ports.input.service.InsightApplicationService;
import com.project.imdang.insight.service.domain.valueobject.District;
Expand Down Expand Up @@ -45,7 +47,7 @@ public ResponseEntity<List<DistrictResponse>> listDistrict(@AuthenticationPrinci
@GetMapping("/by-district/apartment-complexes")
public ResponseEntity<List<ApartmentComplexResponse>> listApartmentComplexByDistrict(@AuthenticationPrincipal UUID memberId,
@ModelAttribute District district) {
List<ApartmentComplexResponse> apartmentComplexResponses = insightApplicationService.listApartmentComplexByDistrict(memberId, district);
List<ApartmentComplexResponse> apartmentComplexResponses = insightApplicationService.listMyInsightApartmentComplexByDistrict(memberId, district);
return ResponseEntity.ok(apartmentComplexResponses);
}

Expand Down Expand Up @@ -76,4 +78,23 @@ public ResponseEntity<Page<InsightResponse>> list(@AuthenticationPrincipal UUID
Page<InsightResponse> insights = insightApplicationService.listMyInsight(listMyInsightQuery);
return ResponseEntity.ok(insights);
}

@GetMapping("/created-by-me")
public ResponseEntity<Page<InsightSimpleResponse>> listCreatedByMe(@AuthenticationPrincipal UUID memberId,
// TODO - PagingQuery
@RequestParam(name = "pageNumber", defaultValue = "0") Integer pageNumber,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
@RequestParam(name = "direction", defaultValue = "DESC") String direction,
@RequestParam(name = "properties", defaultValue = "created_at") String[] properties) {

ListMyInsightCreatedByMeQuery listMyInsightCreatedByMeQuery = ListMyInsightCreatedByMeQuery.builder()
.memberId(memberId)
.pageNumber(pageNumber)
.pageSize(pageSize)
.direction(direction)
.properties(properties)
.build();
Page<InsightSimpleResponse> insights = insightApplicationService.listMyInsightCreatedByMe(listMyInsightCreatedByMeQuery);
return ResponseEntity.ok(insights);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,16 @@ void list() throws Exception {
.andDo(print())
.andReturn();
}

@Test
void listCreatedByMe() throws Exception {
mockMvc.perform(get("/my-insights/created-by-me")
.header("Authorization", "Bearer " + requestMemberToken)
.param("pageNumber", "1")
.param("pageSize", "5")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print())
.andReturn();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.project.imdang.insight.service.domain.dto.insight.list.ApartmentComplexResponse;
import com.project.imdang.insight.service.domain.dto.insight.list.DistrictResponse;
import com.project.imdang.insight.service.domain.dto.insight.list.InsightResponse;
import com.project.imdang.insight.service.domain.dto.insight.list.InsightSimpleResponse;
import com.project.imdang.insight.service.domain.dto.insight.list.ListInsightByApartmentComplexQuery;
import com.project.imdang.insight.service.domain.dto.insight.list.ListInsightQuery;
import com.project.imdang.insight.service.domain.dto.insight.list.ListMyInsightCreatedByMeQuery;
import com.project.imdang.insight.service.domain.dto.insight.list.ListMyInsightQuery;
import com.project.imdang.insight.service.domain.dto.insight.recommend.RecommendInsightCommand;
import com.project.imdang.insight.service.domain.dto.insight.recommend.RecommendInsightResponse;
Expand All @@ -22,10 +24,11 @@
import com.project.imdang.insight.service.domain.handler.insight.CreateInsightCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.DeleteInsightCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.DetailInsightCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListApartmentComplexByDistrictCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListInsightByApartmentComplexCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListInsightCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListMyInsightApartmentComplexByDistrictCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListMyInsightCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListMyInsightCreatedByMeCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListMyInsightDistrictCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.ListMyVisitedApartmentComplexCommandHandler;
import com.project.imdang.insight.service.domain.handler.insight.RecommendInsightCommandHandler;
Expand All @@ -52,8 +55,9 @@ public class InsightApplicationServiceImpl implements InsightApplicationService


private final ListMyInsightDistrictCommandHandler listMyInsightDistrictCommandHandler;
private final ListApartmentComplexByDistrictCommandHandler listApartmentComplexByDistrictCommandHandler;
private final ListMyInsightApartmentComplexByDistrictCommandHandler listMyInsightApartmentComplexByDistrictCommandHandler;
private final ListMyInsightCommandHandler listMyInsightCommandHandler;
private final ListMyInsightCreatedByMeCommandHandler listMyInsightCreatedByMeCommandHandler;

private final DetailInsightCommandHandler detailInsightCommandHandler;
private final CreateInsightCommandHandler createInsightCommandHandler;
Expand Down Expand Up @@ -84,15 +88,20 @@ public List<DistrictResponse> listMyInsightDistrict(UUID memberId) {
}

@Override
public List<ApartmentComplexResponse> listApartmentComplexByDistrict(UUID memberId, District district) {
return listApartmentComplexByDistrictCommandHandler.listApartmentComplexByDistrict(memberId, district);
public List<ApartmentComplexResponse> listMyInsightApartmentComplexByDistrict(UUID memberId, District district) {
return listMyInsightApartmentComplexByDistrictCommandHandler.listMyInsightApartmentComplexByDistrict(memberId, district);
}

@Override
public Page<InsightResponse> listMyInsight(ListMyInsightQuery listMyInsightQuery) {
return listMyInsightCommandHandler.listMyInsight(listMyInsightQuery);
}

@Override
public Page<InsightSimpleResponse> listMyInsightCreatedByMe(ListMyInsightCreatedByMeQuery listMyInsightCreatedByMeQuery) {
return listMyInsightCreatedByMeCommandHandler.listMyInsightCreatedByMe(listMyInsightCreatedByMeQuery);
}

@Override
public DetailInsightResponse detailInsight(DetailInsightQuery detailInsightQuery) {
return detailInsightCommandHandler.detailInsight(detailInsightQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class DetailInsightResponse {
private Integer score;
private ZonedDateTime createdAt;
private ExchangeRequestStatus exchangeRequestStatus;
private UUID exchangeRequestId;

public DetailInsightResponse toPreviewInsightResponse() {
return DetailInsightResponse.builder()
Expand All @@ -65,6 +66,11 @@ public DetailInsightResponse toPreviewInsightResponse() {
.title(title)
.address(address)
.apartmentComplex(apartmentComplex)
.visitAt(visitAt)
.visitTimes(visitTimes)
.visitMethods(visitMethods)
.access(access)
.summary(summary)
.recommendedCount(recommendedCount)
.memberId(memberId)
// .member(member)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.project.imdang.insight.service.domain.dto.insight.list;

import com.project.imdang.insight.service.domain.valueobject.Address;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Builder
@AllArgsConstructor
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class InsightSimpleResponse {
private UUID insightId;
private Integer recommendedCount;
private Address address;
private String title;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.project.imdang.insight.service.domain.dto.insight.list;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Builder
@AllArgsConstructor
@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ListMyInsightCreatedByMeQuery {
// extends PagingQuery {
// @Setter
private UUID memberId;

private Integer pageNumber;
private Integer pageSize;
private String direction;
private String[] properties;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ public ExchangeRequest save(ExchangeRequest exchangeRequest) {
log.info("ExchangeRequest[id: {}] is saved.", savedExchangeRequest.getId().getValue());
return savedExchangeRequest;
}

public void delete(ExchangeRequestId exchangeRequestId) {
exchangeRequestRepository.deleteById(exchangeRequestId);
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,51 @@
package com.project.imdang.insight.service.domain.handler;

import com.project.imdang.domain.event.EmptyEvent;
import com.project.imdang.domain.message.MemberCouponPendingUpdatedResponseMessage;
import com.project.imdang.domain.valueobject.ExchangeRequestId;
import com.project.imdang.insight.service.domain.ExchangeDomainService;
import com.project.imdang.insight.service.domain.entity.ExchangeRequest;
import com.project.imdang.insight.service.domain.event.ExchangeRequestCreatedEvent;
import com.project.imdang.insight.service.domain.exception.ExchangeDomainException;
import com.project.imdang.insight.service.domain.exception.ExchangeRequestNotFoundException;
import com.project.imdang.insight.service.domain.ports.output.repository.ExchangeRequestRepository;
import com.project.imdang.insight.service.domain.exception.InsightApplicationServiceException;
import com.project.imdang.saga.SagaStep;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import static com.project.imdang.domain.exception.ErrorCode.EXCHANGE_REQUEST_FAILED;

@Slf4j
@RequiredArgsConstructor
@Component
public class ExchangeRequestMemberCouponSaga implements SagaStep<MemberCouponPendingUpdatedResponseMessage, ExchangeRequestCreatedEvent, EmptyEvent> {
public class ExchangeRequestMemberCouponSaga implements SagaStep<MemberCouponPendingUpdatedResponseMessage, ExchangeRequestCreatedEvent> {
// request exchange using coupon
// init exchange_request → memberCoupon "pending" → save exchange_request

private final ExchangeDomainService exchangeDomainService;
private final ExchangeRequestRepository exchangeRequestRepository;

// private final EventPublisher eventPublisher;
private final ExchangeRequestHelper exchangeRequestHelper;

// memberCoupon "PENDING" 처리 완료
@Override
public ExchangeRequestCreatedEvent process(MemberCouponPendingUpdatedResponseMessage response) {

ExchangeRequestId exchangeRequestId = new ExchangeRequestId(response.getExchangeRequestId());
ExchangeRequest exchangeRequest = exchangeRequestRepository.findById(exchangeRequestId)
.orElseThrow(() -> new ExchangeRequestNotFoundException(exchangeRequestId));
log.info("MemberCoupon[id: {}] updated as PENDING.", exchangeRequest.getMemberCouponId());
ExchangeRequest exchangeRequest = exchangeRequestHelper.get(exchangeRequestId);
log.info("MemberCoupon[id: {}] status updated as PENDING.", exchangeRequest.getMemberCouponId());

ExchangeRequestCreatedEvent exchangeRequestCreatedEvent = exchangeDomainService.completeCheckCoupon(exchangeRequest);
save(exchangeRequestCreatedEvent.getExchangeRequest());
exchangeRequestHelper.save(exchangeRequestCreatedEvent.getExchangeRequest());
// eventPublisher.publish(exchangeRequestCreatedEvent);
return exchangeRequestCreatedEvent;
}

// memberCoupon "PENDING" 처리 실패
@Override
public EmptyEvent rollback(MemberCouponPendingUpdatedResponseMessage response) {
ExchangeRequestId exchangeRequestId = new ExchangeRequestId(response.getExchangeRequestId());
// TODO - 로그
log.info("Failed!");
// TODO - CHECK : 삭제 처리
exchangeRequestRepository.deleteById(exchangeRequestId);
return EmptyEvent.INSTANCE;
}
public void rollback(MemberCouponPendingUpdatedResponseMessage response) {

throw new InsightApplicationServiceException(EXCHANGE_REQUEST_FAILED);

private ExchangeRequest save(ExchangeRequest exchangeRequest) {
ExchangeRequest savedExchangeRequest = exchangeRequestRepository.save(exchangeRequest);
if(savedExchangeRequest == null) {
String errorMessage = "Could not save ExchangeRequest!";
log.error(errorMessage);
throw new ExchangeDomainException(errorMessage);
}
log.info("ExchangeRequest[id: {}] is saved.", savedExchangeRequest.getId().getValue());
return savedExchangeRequest;
// 삭제 처리
// ExchangeRequestId exchangeRequestId = new ExchangeRequestId(response.getExchangeRequestId());
// exchangeRequestHelper.delete(exchangeRequestId);
// return EmptyEvent.INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
@Slf4j
@RequiredArgsConstructor
@Component
public class InsightAccuseMemberSaga implements SagaStep<MemberAccusedResponseMessage, EmptyEvent, EmptyEvent> {
public class InsightAccuseMemberSaga implements SagaStep<MemberAccusedResponseMessage, EmptyEvent> {
// insight accuse
// insight accuse → check accusedMember accusedCount & update status
// insight accuse → increase accusedMember accusedCount (& update status)

private final InsightDomainService insightDomainService;

// accusedMember increase accusedCount 처리 완료
@Override
public EmptyEvent process(MemberAccusedResponseMessage response) {
InsightId accusedInsightId = new InsightId(response.getAccusedInsightId());
return null;
}

// accusedMember increase accusedCount 처리 실패
@Override
public EmptyEvent rollback(MemberAccusedResponseMessage response) {
return null;
public void rollback(MemberAccusedResponseMessage response) {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.project.imdang.insight.service.domain.handler.exchange;

import com.project.imdang.domain.valueobject.ExchangeRequestId;
import com.project.imdang.domain.valueobject.MemberCouponId;
import com.project.imdang.insight.service.domain.ExchangeDomainService;
import com.project.imdang.insight.service.domain.dto.exchange.accept.AcceptExchangeRequestCommand;
import com.project.imdang.insight.service.domain.dto.exchange.accept.AcceptExchangeRequestResponse;
Expand Down Expand Up @@ -36,24 +37,31 @@ public AcceptExchangeRequestResponse acceptExchangeRequest(AcceptExchangeRequest
.equals(acceptExchangeRequestCommand.getRequestedMemberId())) {
throw new RuntimeException();
}
ExchangeRequestAcceptedEvent exchangeRequestAcceptedEvent = exchangeDomainService.acceptExchangeRequest(exchangeRequest);
log.info("ExchangeRequest[id: {}] is accepted.", exchangeRequest.getId().getValue());
ExchangeRequest saved = exchangeRequestHelper.save(exchangeRequest);

// memberSnapshot에 insert
MemberSnapshot requestMemberSnapshot = MemberSnapshot.builder()
.memberId(exchangeRequest.getRequestMemberId())
.snapshotId(exchangeRequest.getRequestedSnapshotId())
.insightId(exchangeRequest.getRequestedInsightId())
// TODO - CHECK
.createdAt(exchangeRequestAcceptedEvent.getCreatedAt())
.build();
memberSnapshotHelper.save(requestMemberSnapshot);

if (exchangeRequest.getMemberCouponId() != null) {
// TODO : 쿠폰 사용 처리
// 쿠폰 사용 처리 : 쿠폰 사용한 ExchangeRequest 수락 시, MemberCoupon 상태 'USED' 처리
// 'USED' 처리 완료 - process
// 'USED' 처리 실패 - rollback
MemberCouponId memberCouponId = exchangeRequest.getMemberCouponId();
// exchangeRequestAcceptedRequestMessagePublisher.publish(
// new ExchangeRequestAcceptedRequestMessage(exchangeRequest.getId().getValue()));

} else {

ExchangeRequestAcceptedEvent exchangeRequestAcceptedEvent = exchangeDomainService.acceptExchangeRequest(exchangeRequest);
log.info("ExchangeRequest[id: {}] is accepted.", exchangeRequest.getId().getValue());
ExchangeRequest saved = exchangeRequestHelper.save(exchangeRequest);

// memberSnapshot에 insert
MemberSnapshot requestMemberSnapshot = MemberSnapshot.builder()
.memberId(exchangeRequest.getRequestMemberId())
.snapshotId(exchangeRequest.getRequestedSnapshotId())
.insightId(exchangeRequest.getRequestedInsightId())
// TODO - CHECK
.createdAt(exchangeRequestAcceptedEvent.getCreatedAt())
.build();
memberSnapshotHelper.save(requestMemberSnapshot);

MemberSnapshot requestedMemberSnapshot = MemberSnapshot.builder()
.memberId(exchangeRequest.getRequestedMemberId())
.snapshotId(exchangeRequest.getRequestMemberSnapshotId())
Expand All @@ -63,10 +71,7 @@ public AcceptExchangeRequestResponse acceptExchangeRequest(AcceptExchangeRequest
.build();
memberSnapshotHelper.save(requestedMemberSnapshot);
}

// TODO : publish


return exchangeRequestDataMapper.exchangeRequestToAcceptExchangeRequestResponse(saved);
return null;
// return exchangeRequestDataMapper.exchangeRequestToAcceptExchangeRequestResponse(saved);
}
}
Loading

0 comments on commit c9801b7

Please sign in to comment.