Skip to content

Commit

Permalink
[CHORE] resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
delphox60 committed Nov 5, 2023
2 parents fe73591 + 2edbaa2 commit 6151980
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 32 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ fabric.properties
*.tar.gz
*.rar

# Access/Refresh Tokens
*.token

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
Expand Down Expand Up @@ -232,4 +235,4 @@ $RECYCLE.BIN/

!gradle/wrapper/gradle-wrapper.jar

# End of https://www.toptal.com/developers/gitignore/api/windows,intellij,macos,java
# End of https://www.toptal.com/developers/gitignore/api/windows,intellij,macos,java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.google.api.services.androidpublisher.model.SubscriptionPurchase;
import com.nextroom.nextRoomServer.dto.BaseResponse;
import com.nextroom.nextRoomServer.dto.SubscriptionDto;
import com.nextroom.nextRoomServer.service.PaymentService;
import com.nextroom.nextRoomServer.util.AndroidPublisherClient;
import com.nextroom.nextRoomServer.util.Base64Decoder;

Expand All @@ -27,8 +26,6 @@
@RequestMapping("/api/v1/payment")
@RequiredArgsConstructor
public class PaymentController {
private final PaymentService paymentService;

@PostMapping
public ResponseEntity<BaseResponse> updatePayment(
// @RequestBody Object message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
import java.util.regex.Pattern;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nextroom.nextRoomServer.dto.BaseResponse;
import com.nextroom.nextRoomServer.dto.DataResponse;
import com.nextroom.nextRoomServer.dto.SubscriptionDto;
import com.nextroom.nextRoomServer.service.SubscriptionService;
import com.nextroom.nextRoomServer.util.Base64Decoder;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

Expand All @@ -23,5 +28,69 @@
@RequestMapping("/api/v1/subscription")
@RequiredArgsConstructor
public class SubscriptionController {
private final SubscriptionService subscriptionService;

@PostMapping
public ResponseEntity<BaseResponse> updateSubscription(@RequestBody SubscriptionDto.UpdateSubscription messageDto) {
String decodedData = Base64Decoder.decode(messageDto.getMessage().getData());

System.out.println(decodedData);

Pattern pattern = Pattern.compile(".*\"testNotification\":\\{(.*?)\\}.*");
Matcher matcher = pattern.matcher(decodedData);

if (matcher.find()) {
String notificationContent = matcher.group(1);
System.out.println("Extracted Notification Content: " + notificationContent);
}

return ResponseEntity.ok(new BaseResponse(OK));
}

@PostMapping("/test")
public ResponseEntity<BaseResponse> addSubscription() {
subscriptionService.test();
return ResponseEntity.ok(new BaseResponse(OK));
}

@Operation(
summary = "ꡬ독 정보 쑰회(마이 νŽ˜μ΄μ§€)",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "TOKEN_UNAUTHORIZED"),
@ApiResponse(responseCode = "403", description = "NOT_PERMITTED"),
@ApiResponse(responseCode = "404", description = "TARGET_SHOP_NOT_FOUND")
}
)
@GetMapping("/mypage")
public ResponseEntity<BaseResponse> getSubscriptionInfo() {
return ResponseEntity.ok(new DataResponse<>(OK, subscriptionService.getSubscriptionInfo()));
}

@Operation(
summary = "μœ μ € μƒνƒœ 쑰회",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "TOKEN_UNAUTHORIZED"),
@ApiResponse(responseCode = "403", description = "NOT_PERMITTED"),
@ApiResponse(responseCode = "404", description = "TARGET_SHOP_NOT_FOUND")
}
)
@GetMapping("/status")
public ResponseEntity<BaseResponse> getUserStatus() {
return ResponseEntity.ok(new DataResponse<>(OK, subscriptionService.getUserStatus()));
}

@Operation(
summary = "ꡬ독 μš”κΈˆμ œ 쑰회",
responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "401", description = "TOKEN_UNAUTHORIZED"),
@ApiResponse(responseCode = "403", description = "NOT_PERMITTED")
}
)
@GetMapping("/plan")
public ResponseEntity<BaseResponse> getSubscriptionPlan() {
return ResponseEntity.ok(new DataResponse<>(OK, subscriptionService.getSubscriptionPlan()));
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/nextroom/nextRoomServer/domain/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -45,4 +46,7 @@ public class Shop extends Timestamped {
@OneToMany(mappedBy = "shop", cascade = CascadeType.ALL)
@Builder.Default
private List<Theme> themes = new ArrayList<>();

@OneToOne(mappedBy = "shop", cascade = CascadeType.DETACH)
private Subscription subscription;
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.nextroom.nextRoomServer.domain;

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

import com.nextroom.nextRoomServer.enums.SubscriptionPlan;
import com.nextroom.nextRoomServer.enums.SubscriptionStatus;
import com.nextroom.nextRoomServer.enums.UserStatus;
import com.nextroom.nextRoomServer.util.Timestamped;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -31,13 +32,15 @@ public class Subscription extends Timestamped {
@Column(name = "subscription_id", nullable = false)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "shop_id", nullable = false)
private Shop shop;

private String googleId;
private SubscriptionStatus status;

@Enumerated(EnumType.STRING)
private UserStatus status;
@Enumerated(EnumType.STRING)
private SubscriptionPlan plan;
private LocalDateTime subscribedAt;
private LocalDate expiryDate;
}
55 changes: 55 additions & 0 deletions src/main/java/com/nextroom/nextRoomServer/dto/SubscriptionDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package com.nextroom.nextRoomServer.dto;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.google.gson.JsonIOException;
import com.nextroom.nextRoomServer.domain.Subscription;
import com.nextroom.nextRoomServer.enums.EnumModel;
import com.nextroom.nextRoomServer.enums.SubscriptionPlan;
import com.nextroom.nextRoomServer.enums.UserStatus;
import com.nextroom.nextRoomServer.util.Timestamped;

import lombok.Getter;

public class SubscriptionDto {
Expand Down Expand Up @@ -32,4 +42,49 @@ public static class PublishedMessage {
private String eventTimeMillis;
private SubscriptionNotification subscriptionNotification;
}

@Getter
public static class SubscriptionInfoResponse {
private final Long id;
private final SubscriptionPlan subStatus;
private final String expiryDate;
private final String createdAt;

public SubscriptionInfoResponse(Subscription subscription) {
this.id = subscription.getId();
this.subStatus = subscription.getPlan();
this.expiryDate = subscription.getExpiryDate().toString();
this.createdAt = Timestamped.dateTimeFormatter(subscription.getCreatedAt());
}
}

@Getter
public static class UserStatusResponse {
private final Long id;
private final UserStatus userStatus;
private final String expiryDate;
private final String createdAt;

public UserStatusResponse(Subscription subscription) {
this.id = subscription.getId();
this.userStatus = subscription.getStatus();
this.expiryDate = subscription.getExpiryDate().toString();
this.createdAt = Timestamped.dateTimeFormatter(subscription.getCreatedAt());
}
}

@Getter
public static class SubscriptionPlanResponse {
private final String plan;
private final String description;
private final Integer originPrice;
private final Integer sellPrice;

public SubscriptionPlanResponse(EnumModel enumModel) {
this.plan = enumModel.getKey();
this.description = enumModel.getDescription();
this.originPrice = enumModel.getOriginPrice();
this.sellPrice = enumModel.getSellPrice();
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/nextroom/nextRoomServer/enums/EnumModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nextroom.nextRoomServer.enums;

public interface EnumModel {
String getKey();

String getDescription();

Integer getOriginPrice();

Integer getSellPrice();
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
package com.nextroom.nextRoomServer.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum SubscriptionPlan {
STARTER("2개의 ν…Œλ§ˆλ₯Ό 등둝할 수 μžˆμ–΄μš”", 19900, 9900),
PRO("5개의 ν…Œλ§ˆλ₯Ό 등둝할 수 μžˆμ–΄μš”", 29900, 14900),
ENTERPRISE("8개의 ν…Œλ§ˆλ₯Ό 등둝할 수 μžˆμ–΄μš”", 39900, 19900);
public enum SubscriptionPlan implements EnumModel {
MINI("2개의 ν…Œλ§ˆλ₯Ό 등둝할 수 μžˆμ–΄μš”", 19900, 9900),
MEDIUM("5개의 ν…Œλ§ˆλ₯Ό 등둝할 수 μžˆμ–΄μš”", 29900, 14900),
LARGE("8개의 ν…Œλ§ˆλ₯Ό 등둝할 수 μžˆμ–΄μš”", 39900, 19900);

private final String description;
private final Integer originPrice;
private final Integer sellPrice;

SubscriptionPlan(String description, Integer originPrice, Integer sellPrice) {
this.description = description;
this.originPrice = originPrice;
this.sellPrice = sellPrice;
}

@Override
public String getKey() {
return name();
}

@Override
public String getDescription() {
return description;
}

@Override
public Integer getOriginPrice() {
return originPrice;
}

@Override
public Integer getSellPrice() {
return sellPrice;
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package com.nextroom.nextRoomServer.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum SubscriptionStatus {
SUBSCRIPTION_RECOVERED, // μ •κΈ° κ²°μ œκ°€ 계정 보λ₯˜μ—μ„œ λ³΅κ΅¬λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_RENEWED, // ν™œμ„± μ •κΈ° κ²°μ œκ°€ κ°±μ‹ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_CANCELED, // μ •κΈ° κ²°μ œκ°€ 자발적으둜 λ˜λŠ” λΉ„μžλ°œμ μœΌλ‘œ μ·¨μ†Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€. 자발적 μ·¨μ†Œμ˜ 경우 μ‚¬μš©μžκ°€ μ·¨μ†Œν•  λ•Œ μ „μ†‘λ©λ‹ˆλ‹€.
SUBSCRIPTION_PURCHASED, // μƒˆλ‘œμš΄ μ •κΈ° κ²°μ œκ°€ κ΅¬λ§€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_ON_HOLD, // μ •κΈ° κ²°μ œκ°€ 계정 보λ₯˜ μƒνƒœκ°€ λ˜μ—ˆμŠ΅λ‹ˆλ‹€(μ‚¬μš© μ„€μ •λœ 경우).
SUBSCRIPTION_IN_GRACE_PERIOD, // μ •κΈ° κ²°μ œκ°€ 유예 κΈ°κ°„ μƒνƒœλ‘œ μ „ν™˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€(μ‚¬μš© μ„€μ •λœ 경우).
SUBSCRIPTION_RESTARTED, // μ‚¬μš©μžκ°€ Play > 계정 > μ •κΈ° κ²°μ œμ—μ„œ μ •κΈ° 결제λ₯Ό λ³΅μ›ν–ˆμŠ΅λ‹ˆλ‹€. μ •κΈ° κ²°μ œκ°€ μ·¨μ†Œλ˜μ—ˆμ§€λ§Œ μ‚¬μš©μžκ°€ 볡원할 λ•Œ 아직 λ§Œλ£Œλ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. μžμ„Έν•œ λ‚΄μš©μ€Β λ³΅μ›μ„ μ°Έκ³ ν•˜μ„Έμš”.
SUBSCRIPTION_PRICE_CHANGE_CONFIRMED, // μ‚¬μš©μžκ°€ μ •κΈ° 결제 가격 변경을 ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_DEFERRED, // ꡬ독 κ°±μ‹  κΈ°ν•œμ΄ μ—°μž₯λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_PAUSED, // ꡬ독이 μΌμ‹œμ€‘μ§€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED, // μ •κΈ° 결제 μΌμ‹œμ€‘μ§€ 일정이 λ³€κ²½λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_REVOKED, // μ •κΈ° κ²°μ œκ°€ 만료 μ‹œκ°„ 전에 μ‚¬μš©μžμ— μ˜ν•΄ μ·¨μ†Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_EXPIRED // μ •κΈ° κ²°μ œκ°€ λ§Œλ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_RECOVERED(1), // μ •κΈ° κ²°μ œκ°€ 계정 보λ₯˜μ—μ„œ λ³΅κ΅¬λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_RENEWED(2), // ν™œμ„± μ •κΈ° κ²°μ œκ°€ κ°±μ‹ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_CANCELED(3), // μ •κΈ° κ²°μ œκ°€ 자발적으둜 λ˜λŠ” λΉ„μžλ°œμ μœΌλ‘œ μ·¨μ†Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€. 자발적 μ·¨μ†Œμ˜ 경우 μ‚¬μš©μžκ°€ μ·¨μ†Œν•  λ•Œ μ „μ†‘λ©λ‹ˆλ‹€.
SUBSCRIPTION_PURCHASED(4), // μƒˆλ‘œμš΄ μ •κΈ° κ²°μ œκ°€ κ΅¬λ§€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_ON_HOLD(5), // μ •κΈ° κ²°μ œκ°€ 계정 보λ₯˜ μƒνƒœκ°€ λ˜μ—ˆμŠ΅λ‹ˆλ‹€(μ‚¬μš© μ„€μ •λœ 경우).
SUBSCRIPTION_IN_GRACE_PERIOD(6), // μ •κΈ° κ²°μ œκ°€ 유예 κΈ°κ°„ μƒνƒœλ‘œ μ „ν™˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€(μ‚¬μš© μ„€μ •λœ 경우).
SUBSCRIPTION_RESTARTED(
7), // μ‚¬μš©μžκ°€ Play > 계정 > μ •κΈ° κ²°μ œμ—μ„œ μ •κΈ° 결제λ₯Ό λ³΅μ›ν–ˆμŠ΅λ‹ˆλ‹€. μ •κΈ° κ²°μ œκ°€ μ·¨μ†Œλ˜μ—ˆμ§€λ§Œ μ‚¬μš©μžκ°€ 볡원할 λ•Œ 아직 λ§Œλ£Œλ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. μžμ„Έν•œ λ‚΄μš©μ€Β λ³΅μ›μ„ μ°Έκ³ ν•˜μ„Έμš”.
SUBSCRIPTION_PRICE_CHANGE_CONFIRMED(8), // μ‚¬μš©μžκ°€ μ •κΈ° 결제 가격 변경을 ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_DEFERRED(9), // ꡬ독 κ°±μ‹  κΈ°ν•œμ΄ μ—°μž₯λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_PAUSED(10), // ꡬ독이 μΌμ‹œμ€‘μ§€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_PAUSE_SCHEDULE_CHANGED(11), // μ •κΈ° 결제 μΌμ‹œμ€‘μ§€ 일정이 λ³€κ²½λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_REVOKED(12), // μ •κΈ° κ²°μ œκ°€ 만료 μ‹œκ°„ 전에 μ‚¬μš©μžμ— μ˜ν•΄ μ·¨μ†Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.
SUBSCRIPTION_EXPIRED(13); // μ •κΈ° κ²°μ œκ°€ λ§Œλ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.

private final Integer status;
}
16 changes: 16 additions & 0 deletions src/main/java/com/nextroom/nextRoomServer/enums/UserStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.nextroom.nextRoomServer.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum UserStatus {
FREE("무료 μ²΄ν—˜"),
HOLD("유예 κΈ°κ°„"),
EXPIRATION("유예 κΈ°κ°„ 만료"),
SUBSCRIPTION("ꡬ독"),
SUBSCRIPTION_EXPIRATION("ꡬ독 만료");

private final String status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nextroom.nextRoomServer.repository;

import java.util.Optional;

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

import com.nextroom.nextRoomServer.domain.Subscription;

public interface SubscriptionRepository extends JpaRepository<Subscription, Long> {
Optional<Subscription> findByShopId(Long id);
}
Loading

0 comments on commit 6151980

Please sign in to comment.