Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M3-238 앱 버전 api #63

Merged
merged 10 commits into from
Aug 13, 2024
1 change: 1 addition & 0 deletions .github/workflows/cd_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
echo "APPLE_TEAM_ID=${{ secrets.APPLE_TEAM_ID }}" >> .env
echo "APPLE_KEY_ID=${{ secrets.APPLE_KEY_ID }}" >> .env
echo "APPLE_PRIVATE_KEY=${{ secrets.APPLE_PRIVATE_KEY }}" >> .env
echo "NEED_UPDATE_VERSION=${{ secrets.NEED_UPDATE_VERSION }}" >> .env

echo "SPRING_PROFILES_ACTIVE=dev" >> .env

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cd_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
echo "APPLE_TEAM_ID=${{ secrets.APPLE_TEAM_ID }}" >> .env
echo "APPLE_KEY_ID=${{ secrets.APPLE_KEY_ID }}" >> .env
echo "APPLE_PRIVATE_KEY=${{ secrets.APPLE_PRIVATE_KEY }}" >> .env
echo "NEED_UPDATE_VERSION=${{ secrets.NEED_UPDATE_VERSION }}" >> .env

- name: gradlew에 실행 권한 부여
run: chmod +x ./gradlew
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.m3pro.groundflip.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.m3pro.groundflip.domain.dto.Response;
import com.m3pro.groundflip.domain.dto.version.VersionResponse;
import com.m3pro.groundflip.service.VersionService;

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

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
@Tag(name = "version", description = "앱 버전 API")
public class VersionController {
private final VersionService versionService;

@Operation(summary = "버전 업데이트 필요 여부 확인", description = "현재 앱 버전 업데이트가 필요한지 판별")
@GetMapping("/version")
public Response<VersionResponse> getVersion(
@Parameter(description = "현재 버전", required = true)
@RequestParam String currentVersion
) {
return Response.createSuccess(versionService.getVersion(currentVersion));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.m3pro.groundflip.domain.dto.version;

import com.m3pro.groundflip.enums.Version;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Schema(title = "앱 버전 get")
public class VersionResponse {
@Schema(description = "앱 버전", example = "1.0.5")
private String version;

@Schema(description = "앱 버전", example = "1.0.5")
private Version needUpdate;

}
2 changes: 1 addition & 1 deletion src/main/java/com/m3pro/groundflip/enums/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public enum Place {
COMPANY("회사/학교"),
ELSE("기타 장소");

private String place;
private final String place;
}
14 changes: 14 additions & 0 deletions src/main/java/com/m3pro/groundflip/enums/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.m3pro.groundflip.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum Version {
OK("업데이트 불필요"),
NEED("업데이트 필요"),
FORCE("강제 업데이트");

private final String update;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum ErrorCode {
IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 이미지입니다."),
PLACE_NOT_FOUND(HttpStatus.NOT_FOUND, "장소가 등록되어 있지 않습니다."),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 에러 입니다"),
VERSION_NOT_FOUND(HttpStatus.NOT_FOUND, "버전이 존재하지 않습니다."),

// 권한 관련 에러
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "권한이 없습니다"),
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/m3pro/groundflip/service/VersionService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.m3pro.groundflip.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.m3pro.groundflip.domain.dto.version.VersionResponse;
import com.m3pro.groundflip.enums.Version;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class VersionService {

@Value("${version.update}")
private String lastestVersion;

private Version needUpdate;

public VersionResponse getVersion(String currentVersion) {
if (!lastestVersion.equals(currentVersion)) {
needUpdate = Version.NEED;
} else {
needUpdate = Version.OK;
}

return VersionResponse.builder()
.version(lastestVersion)
.needUpdate(needUpdate)
.build();
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,7 @@ cloud:
s3:
bucket: ${AWS_S3_BUCKET}

version:
update: ${NEED_UPDATE_VERSION}


2 changes: 2 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ cloud:
s3:
bucket: ${AWS_S3_BUCKET}

version:
update: ${NEED_UPDATE_VERSION}

2 changes: 2 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ cloud:
s3:
bucket: ${AWS_S3_BUCKET}

version:
update: ${NEED_UPDATE_VERSION}


41 changes: 41 additions & 0 deletions src/test/java/com/m3pro/groundflip/service/VersionServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.m3pro.groundflip.service;

import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.util.ReflectionTestUtils;

import com.m3pro.groundflip.domain.dto.version.VersionResponse;

@ExtendWith(MockitoExtension.class)
public class VersionServiceTest {

@InjectMocks
private VersionService versionService;

@BeforeEach
void setUp() {
ReflectionTestUtils.setField(versionService, "lastestVersion", "1.0.3");
}

@Test
@DisplayName("[getVersion] version이 잘 get 되는지")
void getVersionTest() {
//Given
String currentVersion = "1.0.3";

//When
VersionResponse versionResponse = versionService.getVersion(currentVersion);

//Then
assertThat(versionResponse).isNotNull();
assertThat(versionResponse.getVersion()).isEqualTo("1.0.3");

}

}
3 changes: 3 additions & 0 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ cloud:
secret-key: test-value
s3:
bucket: test-value

version:
update: 1.0.3
Loading