Skip to content

Commit

Permalink
Merge pull request #208 from Central-MakeUs/develop
Browse files Browse the repository at this point in the history
v1.2.1
  • Loading branch information
leeeeeyeon authored Apr 2, 2024
2 parents 6376730 + 74b6641 commit 42831a8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.dilly.member.application;

import static com.dilly.global.Constants.LATEST_VERSION;
import static com.dilly.global.Constants.MINIMUM_REQUIRED_VERSION;

import com.dilly.exception.BadRequestException;
import com.dilly.exception.ErrorCode;
import com.dilly.exception.internalserver.InternalServerException;
import com.dilly.global.util.SecurityUtil;
import com.dilly.member.adaptor.MemberReader;
import com.dilly.member.domain.Member;
Expand All @@ -27,27 +30,50 @@ public StatusResponse getStatus(String appVersion) {

// 유저 계정 상태 확인
if (!member.getStatus().equals(Status.REGISTERED)) {
return StatusResponse.from(false, Reason.INVALID_STATUS);
return StatusResponse.from(memberId, false, Reason.INVALID_STATUS);
}

// 유저 버전 확인
Integer latestMajorVersion = getMajorVersion(LATEST_VERSION);
Integer memberMajorVersion = getMajorVersion(appVersion);
log.info("latestMajorVersion: {}, userMajorVersion: {}", latestMajorVersion, memberMajorVersion);
Integer minimumRequiredMajorVersion = extractMajorVersion(MINIMUM_REQUIRED_VERSION);
Integer minimumRequiredMinorVersion = extractMinorVersion(MINIMUM_REQUIRED_VERSION);

if (memberMajorVersion < latestMajorVersion) {
return StatusResponse.from(false, Reason.NEED_UPDATE);
Integer memberMajorVersion = extractMajorVersion(appVersion);
Integer memberMinorVersion = extractMinorVersion(appVersion);

if (minimumRequiredMajorVersion == null || minimumRequiredMinorVersion == null) {
throw new InternalServerException(ErrorCode.INVALID_LATEST_VERSION);
}

return StatusResponse.from(true);
if (memberMajorVersion == null || memberMinorVersion == null) {
throw new BadRequestException(ErrorCode.FAILED_TO_EXTRACT_VERSION);
}

if (memberMajorVersion < minimumRequiredMajorVersion) {
return StatusResponse.from(memberId, false, Reason.NEED_UPDATE);
}

if (memberMinorVersion < minimumRequiredMinorVersion) {
return StatusResponse.from(memberId, false, Reason.NEED_UPDATE);
}

return StatusResponse.from(memberId, true);
}

private Integer getMajorVersion(String version) {
private Integer extractMajorVersion(String version) {
String[] parts = version.split("\\.");
if (parts.length > 0) {
return Integer.parseInt(parts[0]);
}

return null;
}

private Integer extractMinorVersion(String version) {
String[] parts = version.split("\\.");
if (parts.length > 1) {
return Integer.parseInt(parts[1]);
} else {
return 0;
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@
@Builder
@JsonInclude(Include.NON_NULL)
public record StatusResponse(
@Schema(example = "1")
Long id,

@Schema(example = "true")
Boolean isAvailable,

@Schema(example = "NEED_UPDATE")
Reason reason
) {

public static StatusResponse from(Boolean isAvailable) {
public static StatusResponse from(Long id, Boolean isAvailable) {
return StatusResponse.builder()
.id(id)
.isAvailable(isAvailable)
.build();
}

public static StatusResponse from(Boolean isAvailable, Reason reason) {
public static StatusResponse from(Long id, Boolean isAvailable, Reason reason) {
return StatusResponse.builder()
.id(id)
.isAvailable(isAvailable)
.reason(reason)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.dilly.exception;

public class BadRequestException extends BusinessException {

public BadRequestException(ErrorCode errorCode) {
super(errorCode);
}
}
4 changes: 4 additions & 0 deletions packy-common/src/main/java/com/dilly/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public enum ErrorCode {
GIFTBOX_ALREADY_OPENDED(HttpStatus.CONFLICT, "이미 열린 선물입니다."),
GIFTBOX_ACCESS_DENIED(HttpStatus.FORBIDDEN, "선물박스에 접근할 수 없습니다."),
GIFTBOX_ALREADY_DELETED(HttpStatus.NOT_FOUND, "이미 삭제된 선물박스입니다."),

// Version
FAILED_TO_EXTRACT_VERSION(HttpStatus.BAD_REQUEST, "사용자 버전을 추출하는데 실패했습니다."),
INVALID_LATEST_VERSION(HttpStatus.INTERNAL_SERVER_ERROR, "최신 버전이 올바르지 않습니다."),
;

private final HttpStatus httpStatus;
Expand Down
2 changes: 1 addition & 1 deletion packy-domain/src/main/java/com/dilly/global/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public class Constants {
private Constants() {}

public static final String LATEST_VERSION = "1.1.1";
public static final String MINIMUM_REQUIRED_VERSION = "1.1.1";
}

0 comments on commit 42831a8

Please sign in to comment.