Skip to content

Commit

Permalink
Merge pull request #191 from Nexters/feature/190
Browse files Browse the repository at this point in the history
Feature/190 : νšŒμ›κ°€μž… 응λͺ¨κΆŒ νŒμ—… λ Œλ”λ§ ν”Œλž˜κ·Έ API
  • Loading branch information
swa07016 authored Aug 4, 2024
2 parents 4e1aba2 + 5c2259b commit 2535c8e
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.nexters.dailyphrase.prize.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QPrizeTicketPopupCheck is a Querydsl query type for PrizeTicketPopupCheck
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QPrizeTicketPopupCheck extends EntityPathBase<PrizeTicketPopupCheck> {

private static final long serialVersionUID = -2068721456L;

public static final QPrizeTicketPopupCheck prizeTicketPopupCheck = new QPrizeTicketPopupCheck("prizeTicketPopupCheck");

public final NumberPath<Long> id = createNumber("id", Long.class);

public final NumberPath<Long> memberId = createNumber("memberId", Long.class);

public final EnumPath<com.nexters.dailyphrase.common.enums.PrizeTicketPopupType> type = createEnum("type", com.nexters.dailyphrase.common.enums.PrizeTicketPopupType.class);

public QPrizeTicketPopupCheck(String variable) {
super(PrizeTicketPopupCheck.class, forVariable(variable));
}

public QPrizeTicketPopupCheck(Path<? extends PrizeTicketPopupCheck> path) {
super(path.getType(), path.getMetadata());
}

public QPrizeTicketPopupCheck(PathMetadata metadata) {
super(PrizeTicketPopupCheck.class, metadata);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.nexters.dailyphrase.common.enums;

public enum PrizeTicketPopupType {
GET_BY_SIGNUP
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.nexters.dailyphrase.common.annotation.Mapper;
import com.nexters.dailyphrase.common.consts.DailyPhraseStatic;
import com.nexters.dailyphrase.common.enums.PrizeEntryStatus;
import com.nexters.dailyphrase.common.enums.PrizeTicketPopupType;
import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.common.enums.PrizeTicketStatus;
import com.nexters.dailyphrase.prize.domain.*;
Expand Down Expand Up @@ -103,4 +104,15 @@ public PrizeEventResponseDTO.CheckPrizeEntryResult toCheckPrizeEntryResult(
.memberId(prizeEntryCheck.getMemberId())
.build();
}

public PrizeTicketPopupCheck toPrizeTicketPopupCheck(Long memberId, PrizeTicketPopupType type) {
return PrizeTicketPopupCheck.builder().memberId(memberId).type(type).build();
}

public PrizeEventResponseDTO.MyInfo toMyInfo(Long memberId, Boolean showGetTicketPopup) {
return PrizeEventResponseDTO.MyInfo.builder()
.memberId(memberId)
.showGetTicketPopup(showGetTicketPopup)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import org.springframework.transaction.annotation.Transactional;

import com.nexters.dailyphrase.common.consts.DailyPhraseStatic;
import com.nexters.dailyphrase.common.enums.PrizeEntryStatus;
import com.nexters.dailyphrase.common.enums.PrizeEventStatus;
import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.common.enums.PrizeTicketStatus;
import com.nexters.dailyphrase.common.enums.*;
import com.nexters.dailyphrase.common.jwt.JwtTokenService;
import com.nexters.dailyphrase.common.jwt.dto.AccessTokenInfo;
import com.nexters.dailyphrase.common.utils.MemberUtils;
Expand All @@ -37,6 +34,8 @@ public class PrizeEventService {
private final PrizeEntryQueryAdapter prizeEntryQueryAdapter;
private final PrizeEntryCommandAdapter prizeEntryCommandAdapter;
private final PrizeEntryCheckCommandAdapter prizeEntryCheckCommandAdapter;
private final PrizeTicketPopupCheckQueryAdapter prizeTicketPopupCheckQueryAdapter;
private final PrizeTicketPopupCheckCommandAdapter prizeTicketPopupCheckCommandAdapter;
private final JwtTokenService jwtTokenService;
private final PrizeEventMapper prizeEventMapper;
private final MemberUtils memberUtils;
Expand Down Expand Up @@ -135,4 +134,27 @@ public PrizeEventResponseDTO.CheckPrizeEntryResult checkPrizeEntryResult(
return prizeEventMapper.toCheckPrizeEntryResult(
prizeEntryCheckCommandAdapter.add(prizeEntryCheck));
}

@Transactional(readOnly = true)
public PrizeEventResponseDTO.MyInfo myInfo() {
Long memberId = memberUtils.getCurrentMemberId();
Boolean showGetTicketPopup = Boolean.FALSE;
// νšŒμ›κ°€μž… 응λͺ¨κΆŒμ„ νšλ“ν•œ 기둝이 μžˆλŠ” 경우

boolean hasSignupTicket =
prizeTicketQueryAdapter.existsByMemberIdAndSource(
memberId, PrizeTicketSource.SIGNUP);
boolean isFirstCheck =
!prizeTicketPopupCheckQueryAdapter.existsByMemberIdAndType(
memberId, PrizeTicketPopupType.GET_BY_SIGNUP);

if (hasSignupTicket && isFirstCheck) {
showGetTicketPopup = Boolean.TRUE;
prizeTicketPopupCheckCommandAdapter.add(
prizeEventMapper.toPrizeTicketPopupCheck(
memberId, PrizeTicketPopupType.GET_BY_SIGNUP));
}

return prizeEventMapper.toMyInfo(memberId, showGetTicketPopup);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.nexters.dailyphrase.prize.domain;

import jakarta.persistence.*;

import com.nexters.dailyphrase.common.enums.PrizeTicketPopupType;

import lombok.*;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class PrizeTicketPopupCheck {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Long memberId;

@Enumerated(EnumType.STRING)
private PrizeTicketPopupType type;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nexters.dailyphrase.prize.domain.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.nexters.dailyphrase.common.enums.PrizeTicketPopupType;
import com.nexters.dailyphrase.prize.domain.PrizeTicketPopupCheck;

public interface PrizeTicketPopupCheckRepository
extends JpaRepository<PrizeTicketPopupCheck, Long> {
boolean existsByMemberIdAndType(Long memberId, PrizeTicketPopupType type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nexters.dailyphrase.prize.implement;

import com.nexters.dailyphrase.common.annotation.Adapter;
import com.nexters.dailyphrase.prize.domain.PrizeTicketPopupCheck;
import com.nexters.dailyphrase.prize.domain.repository.PrizeTicketPopupCheckRepository;

import lombok.RequiredArgsConstructor;

@Adapter
@RequiredArgsConstructor
public class PrizeTicketPopupCheckCommandAdapter {
private final PrizeTicketPopupCheckRepository prizeTicketPopupCheckRepository;

public PrizeTicketPopupCheck add(PrizeTicketPopupCheck prizeTicketPopupCheck) {
return prizeTicketPopupCheckRepository.save(prizeTicketPopupCheck);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nexters.dailyphrase.prize.implement;

import com.nexters.dailyphrase.common.annotation.Adapter;
import com.nexters.dailyphrase.common.enums.PrizeTicketPopupType;
import com.nexters.dailyphrase.prize.domain.repository.PrizeTicketPopupCheckRepository;

import lombok.RequiredArgsConstructor;

@Adapter
@RequiredArgsConstructor
public class PrizeTicketPopupCheckQueryAdapter {
private final PrizeTicketPopupCheckRepository prizeTicketPopupCheckRepository;

public boolean existsByMemberIdAndType(Long memberId, PrizeTicketPopupType type) {
return prizeTicketPopupCheckRepository.existsByMemberIdAndType(memberId, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public CommonResponse<PrizeEventResponseDTO.EnterPhoneNumber> enterPhoneNumber(
}

@Operation(
summary = "07-05 Event 🎁 κ²½ν’ˆ 응λͺ¨ 이벀트의 κ²½ν’ˆ 응λͺ¨ κ²°κ³Ό 확인 처리 Made By μ„±ν›ˆ",
summary = "07-06 Event 🎁 κ²½ν’ˆ 응λͺ¨ 이벀트의 κ²½ν’ˆ 응λͺ¨ κ²°κ³Ό 확인 처리 Made By μ„±ν›ˆ",
description = "κ²½ν’ˆ 응λͺ¨ 이벀트의 κ²½ν’ˆ 응λͺ¨ κ²°κ³Ό 확인 처리 APIμž…λ‹ˆλ‹€.")
@PostMapping("/prizes/entry-result/check")
public CommonResponse<PrizeEventResponseDTO.CheckPrizeEntryResult> checkPrizeEntryResult(
Expand All @@ -87,7 +87,15 @@ public CommonResponse<PrizeEventResponseDTO.CheckPrizeEntryResult> checkPrizeEnt
}

@Operation(
summary = "07-07 Event 🎁 κ²½ν’ˆ 응λͺ¨ 이벀트의 응λͺ¨κΆŒ λ°œκΈ‰μš© 카카였 콜백 Made By μ„±ν›ˆ",
summary = "07-07 Event 🎁 κ²½ν’ˆ 응λͺ¨ 이벀트의 응λͺ¨κΆŒ νŒμ—… ν”Œλž˜κ·Έ 확인 Made By μ„±ν›ˆ",
description = "κ²½ν’ˆ 응λͺ¨ 이벀트의 응λͺ¨κΆŒ νŒμ—… ν”Œλž˜κ·Έ 확인 APIμž…λ‹ˆλ‹€.")
@GetMapping("/tickets/me")
public CommonResponse<PrizeEventResponseDTO.MyInfo> myInfo() {
return CommonResponse.onSuccess(prizeEventService.myInfo());
}

@Operation(
summary = "07-08 Event 🎁 κ²½ν’ˆ 응λͺ¨ 이벀트의 응λͺ¨κΆŒ λ°œκΈ‰μš© 카카였 콜백 Made By μ„±ν›ˆ",
description = "κ²½ν’ˆ 응λͺ¨ 이벀트의 응λͺ¨κΆŒ λ°œκΈ‰μš© 카카였 μ½œλ°±μž…λ‹ˆλ‹€. (직접 호좜 X)")
@PostMapping("/kakaolink/callback")
public ResponseEntity<String> handleKakaoLinkCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,13 @@ public static class CheckPrizeEntryResult {
private Long prizeId;
private Long memberId;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class MyInfo {
private Long memberId;
@Builder.Default private Boolean showGetTicketPopup = Boolean.FALSE;
}
}
9 changes: 8 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fcm:
scope: https://www.googleapis.com/auth/cloud-platform
api:
url: https://fcm.googleapis.com/v1/projects/${fcm-project-id}/messages:send
topic: "test"
topic: "deprecated_topic"
---
spring:
config:
Expand Down Expand Up @@ -151,3 +151,10 @@ spring:
# format_sql: true
# use_sql_comments: true
default_batch_fetch_size: 1000
fcm:
key:
path: firebase/firebase-adminsdk.json
scope: https://www.googleapis.com/auth/cloud-platform
api:
url: https://fcm.googleapis.com/v1/projects/${fcm-project-id}/messages:send
topic: "test_topic"
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.nexters.dailyphrase.common.enums.PrizeEntryStatus;
import com.nexters.dailyphrase.common.enums.PrizeEventStatus;
import com.nexters.dailyphrase.common.enums.PrizeTicketSource;
import com.nexters.dailyphrase.common.enums.PrizeTicketStatus;
import com.nexters.dailyphrase.member.domain.Member;
import com.nexters.dailyphrase.member.domain.repository.MemberRepository;
Expand Down Expand Up @@ -277,4 +278,48 @@ public void setup() {
.andExpect(jsonPath("$.result.memberId").value(1L))
.andExpect(jsonPath("$.result.status").value(PrizeEntryStatus.ENTERED.toString()));
}

@Test
@DisplayName("νšŒμ›κ°€μž… ν‹°μΌ“ νšλ“ ν›„ νŒμ—… λ Œλ”λ§ ν”Œλž˜κ·Έ 확인 ν…ŒμŠ€νŠΈμž…λ‹ˆλ‹€.")
@WithMockUser(username = "1")
void νšŒμ›κ°€μž…_ν‹°μΌ“_νšλ“_ν›„_νŒμ—…() throws Exception {
// given
prizeTicketRepository.save(
PrizeTicket.builder()
.eventId(1L)
.memberId(1L)
.status(PrizeTicketStatus.AVAILABLE)
.source(PrizeTicketSource.SIGNUP)
.build());

// when & then
MockHttpServletRequestBuilder request =
MockMvcRequestBuilders.get("/api/v1/events/tickets/me");

mockMvc.perform(request)
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.result.showGetTicketPopup").value(Boolean.TRUE));

mockMvc.perform(request)
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.result.showGetTicketPopup").value(Boolean.FALSE));
}

@Test
@DisplayName("νšŒμ›κ°€μž… λ―Ένšλ“μ‹œ νŒμ—… λ Œλ”λ§ ν”Œλž˜κ·Έ 확인 ν…ŒμŠ€νŠΈμž…λ‹ˆλ‹€.")
@WithMockUser(username = "1")
void νšŒμ›κ°€μž…_λ―Ένšλ“μ‹œ_νŒμ—…() throws Exception {
// given

// when & then
MockHttpServletRequestBuilder request =
MockMvcRequestBuilders.get("/api/v1/events/tickets/me");

mockMvc.perform(request)
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.result.showGetTicketPopup").value(Boolean.FALSE));
}
}

0 comments on commit 2535c8e

Please sign in to comment.