Skip to content

Commit

Permalink
YEL-230 [fix] 구독 조회하기 api 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjeongs committed Apr 3, 2024
1 parent 165bc55 commit f259c25
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Optional<Purchase> findTopByUserAndProductTypeOrderByCreatedAtDesc(User user,

void delete(Purchase purchase);

Purchase getTopByStateAndUserId(User user);
Optional<Purchase> getTopByStateAndUserId(User user);

Long countByStartAt(Gateway gateway, ProductType productType, LocalDateTime start, LocalDateTime end);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ public void delete(Purchase purchase) {
}

@Override
public Purchase getTopByStateAndUserId(User user) {
return purchaseJpaRepository.findTopByStateAndUser(user)
.orElseThrow(() -> new PurchaseNotFoundException(NOT_FOUND_USER_SUBSCRIBE_EXCEPTION));
public Optional<Purchase> getTopByStateAndUserId(User user) {
return purchaseJpaRepository.findTopByStateAndUser(user);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static UserSubscribeDetailResponse of(Purchase purchase) {
.id(purchase.getUser().getId())
.subscribe(purchase.getUser().getSubscribe().getInitial())
.expiredDate(
toYearAndMonthFormattedString(purchase.getUpdatedAt().plusDays(SUBSCRIBE_DAYS)))
toYearAndMonthFormattedString(purchase.getUpdatedAt() !=null ? purchase.getUpdatedAt().plusDays(SUBSCRIBE_DAYS):null))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import com.yello.server.domain.friend.repository.FriendRepository;
import com.yello.server.domain.group.entity.UserGroup;
import com.yello.server.domain.group.repository.UserGroupRepository;
import com.yello.server.domain.purchase.entity.Gateway;
import com.yello.server.domain.purchase.entity.ProductType;
import com.yello.server.domain.purchase.entity.Purchase;
import com.yello.server.domain.purchase.entity.PurchaseState;
import com.yello.server.domain.purchase.repository.PurchaseRepository;
import com.yello.server.domain.user.dto.request.UserDataUpdateRequest;
import com.yello.server.domain.user.dto.request.UserDeleteReasonRequest;
Expand Down Expand Up @@ -123,9 +126,13 @@ public void delete(User user) {

public UserSubscribeDetailResponse getUserSubscribe(Long userId) {
final User user = userRepository.getById(userId);
final Purchase purchase = purchaseRepository.getTopByStateAndUserId(user);
Optional<Purchase> purchase = purchaseRepository.getTopByStateAndUserId(user);
Purchase userSubscribe = purchase.orElseGet(() ->
Purchase.builder()
.user(user)
.build());

return UserSubscribeDetailResponse.of(purchase);
return UserSubscribeDetailResponse.of(userSubscribe);
}

@Transactional
Expand Down
20 changes: 19 additions & 1 deletion src/main/resources/static/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ <h1>YELL:O API 문서</h1>
<li><a href="#_vote_api">Vote API</a></li>
<li><a href="#_friend_api">Friend API</a></li>
<li><a href="#_purchase_api">Purchase API</a></li>
<li><a href="#_pay_api">Pay API</a></li>
<li><a href="#_notice_api">Notice API</a></li>
<li><a href="#_event_api">Event API</a></li>
</ul>
Expand Down Expand Up @@ -618,6 +619,23 @@ <h3 id="_purchase_api"><a class="link" href="#_purchase_api">Purchase API</a></h
</div>
</div>
<div class="sect2">
<h3 id="_pay_api"><a class="link" href="#_pay_api">Pay API</a></h3>
<div class="ulist">
<ul>
<li>
<p>@Deprecated at 2024.03</p>
<div class="ulist">
<ul>
<li>
<p><a href="pay.html">결제 전환율 체크</a></p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_notice_api"><a class="link" href="#_notice_api">Notice API</a></h3>
<div class="ulist">
<ul>
Expand All @@ -641,7 +659,7 @@ <h3 id="_event_api"><a class="link" href="#_event_api">Event API</a></h3>
<p>🆕 <a href="reward-event.html">이벤트 보상, 2024-02-07</a></p>
</li>
<li>
<p>🆕 <a href="reward-admob.html">광고보고 보상 얻기, 2024-02-19</a></p>
<p>🆕 <a href="reward-admob.html">광고보고 보상 얻기, 2024-02-11</a></p>
</li>
<li>
<p>🆕 <a href="check-is-possible-admob.html">광고보고 보상 얻기 가능 여부 조회, 2024-02-17</a></p>
Expand Down
16 changes: 12 additions & 4 deletions src/main/resources/static/docs/reward-admob.html
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ <h3 id="_요청">요청</h3>
<pre class="highlight nowrap"><code class="language-http" data-lang="http">POST /api/v1/admob/reward HTTP/1.1
Content-Type: application/json;charset=UTF-8
Authorization: Bearer your-access-token
IdempotencyKey: 87552f7c-9b62-4b12-b567-1bd062b09288
Content-Length: 134

{
Expand All @@ -473,7 +474,7 @@ <h3 id="_request_body">request body</h3>
<p>ADMOB_POINT : 광고 보고 10 포인트</p>
</li>
<li>
<p>ADMOB_MULTIPLE_POINT : 투표 후, 광고 보고 포인트 2배 이벤트</p>
<p>ADMOB_MULTIPLE_POINT : 광고 보고 포인트 2배 이벤트</p>
</li>
</ul>
</div>
Expand Down Expand Up @@ -528,6 +529,16 @@ <h3 id="_note">NOTE</h3>
<div class="ulist">
<ul>
<li>
<p>Header에 무작위한 UUID4 값을 넣어주세요</p>
<div class="ulist">
<ul>
<li>
<p>예시) IdempotencyKey: 0397b5f3-ecdc-47d6-b5d7-2b1afcf00e87</p>
</li>
</ul>
</div>
</li>
<li>
<p>주의사항</p>
<div class="ulist">
<ul>
Expand Down Expand Up @@ -555,9 +566,6 @@ <h3 id="_changelog">CHANGELOG</h3>
<div class="ulist">
<ul>
<li>
<p>2024.02.19 API ENUM, 명세서 수정</p>
</li>
<li>
<p>2024.02.11 릴리즈</p>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,15 @@ public void delete(Purchase purchase) {
}

@Override
public Purchase getTopByStateAndUserId(User user) {
public Optional<Purchase> getTopByStateAndUserId(User user) {
return data.stream()
.filter(purchase -> {
return purchase.getUser().equals(user) &&
purchase.getProductType().equals(ProductType.YELLO_PLUS) &&
purchase.getState().equals(PurchaseState.ACTIVE);
})
.sorted(Comparator.comparing(Purchase::getUpdatedAt).reversed())
.findFirst()
.orElseThrow(() -> new PurchaseNotFoundException(NOT_FOUND_USER_SUBSCRIBE_EXCEPTION));
.findFirst();
}

@Override
Expand Down

0 comments on commit f259c25

Please sign in to comment.