-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from uswLectureEvaluation/feat/version_update
feat: 버전 강제 업데이트 API
- Loading branch information
Showing
20 changed files
with
524 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/usw/suwiki/domain/version/controller/ClientAppVersionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package usw.suwiki.domain.version.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
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 usw.suwiki.domain.version.dto.response.CheckUpdateMandatoryResponse; | ||
import usw.suwiki.domain.version.service.ClientAppVersionService; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequestMapping("/client/version") | ||
@RequiredArgsConstructor | ||
public class ClientAppVersionController { | ||
private final ClientAppVersionService clientAppVersionService; | ||
|
||
@GetMapping("/update-mandatory") | ||
public ResponseEntity<CheckUpdateMandatoryResponse> checkIsUpdateMandatory( | ||
@RequestParam String os, | ||
@RequestParam Integer versionCode | ||
) { | ||
return ResponseEntity.ok(clientAppVersionService.checkIsUpdateMandatory(os, versionCode)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/usw/suwiki/domain/version/dto/response/CheckUpdateMandatoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package usw.suwiki.domain.version.dto.response; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class CheckUpdateMandatoryResponse { | ||
private final Boolean isUpdateMandatory; | ||
|
||
public static CheckUpdateMandatoryResponse from(boolean isUpdateMandatory) { | ||
return CheckUpdateMandatoryResponse.builder() | ||
.isUpdateMandatory(isUpdateMandatory) | ||
.build(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/usw/suwiki/domain/version/entity/ClientAppVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package usw.suwiki.domain.version.entity; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import javax.persistence.UniqueConstraint; | ||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import usw.suwiki.global.BaseTimeEntity; | ||
import usw.suwiki.global.exception.ExceptionType; | ||
import usw.suwiki.global.exception.errortype.VersionException; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(uniqueConstraints = { | ||
@UniqueConstraint( | ||
name = "UNIQUE_OS_AND_VERSION_CODE", | ||
columnNames = {"os", "version_code"} | ||
) | ||
}) | ||
public class ClientAppVersion extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "client_app_version_id") | ||
private Long id; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@NotNull | ||
@Column(name = "os") | ||
private ClientOS os; | ||
|
||
@NotNull | ||
@Min(value = 0) | ||
@Column(name = "version_code") | ||
private Integer versionCode; | ||
|
||
@NotNull | ||
private Boolean isVital; | ||
|
||
@Size(max = 2000) | ||
private String description; | ||
|
||
|
||
@Builder | ||
public ClientAppVersion(ClientOS os, Integer versionCode, Boolean isVital, String description) { | ||
this.os = os; | ||
this.versionCode = versionCode; | ||
this.isVital = isVital; | ||
this.description = description; | ||
} | ||
|
||
public boolean judgeIsUpdateMandatory(ClientOS os, Integer otherVersionCode) { | ||
if (!this.os.equals(os)) { | ||
throw new VersionException(ExceptionType.SERVER_ERROR); | ||
} | ||
return this.isVital && this.versionCode > otherVersionCode; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/usw/suwiki/domain/version/entity/ClientOS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package usw.suwiki.domain.version.entity; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
import lombok.RequiredArgsConstructor; | ||
import usw.suwiki.global.exception.ExceptionType; | ||
import usw.suwiki.global.exception.errortype.VersionException; | ||
import usw.suwiki.global.util.enums.KeyValueEnumModel; | ||
|
||
@RequiredArgsConstructor | ||
public enum ClientOS implements KeyValueEnumModel<String> { | ||
ANDROID("ANDROID"), IOS("IOS"), WEB("WEB"); | ||
|
||
private final String value; | ||
|
||
public static ClientOS ofString(String param) { | ||
if (Objects.isNull(param)) { | ||
throw new VersionException(ExceptionType.INVALID_CLIENT_OS); | ||
} | ||
return Arrays.stream(ClientOS.values()) | ||
.filter(v -> v.getValue().equals(param.toUpperCase())) | ||
.findFirst() | ||
.orElseThrow(() -> new VersionException(ExceptionType.COMMON_CLIENT_ERROR)); | ||
} | ||
|
||
@Override | ||
public String getKey() { | ||
return name(); | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return value; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/usw/suwiki/domain/version/repository/ClientAppVersionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package usw.suwiki.domain.version.repository; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import usw.suwiki.domain.version.entity.ClientAppVersion; | ||
import usw.suwiki.domain.version.entity.ClientOS; | ||
|
||
public interface ClientAppVersionRepository extends JpaRepository<ClientAppVersion, Long> { | ||
Optional<ClientAppVersion> findFirstByOsAndIsVitalTrueOrderByVersionCodeDesc(ClientOS os); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/usw/suwiki/domain/version/service/ClientAppVersionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package usw.suwiki.domain.version.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import usw.suwiki.domain.version.dto.response.CheckUpdateMandatoryResponse; | ||
import usw.suwiki.domain.version.entity.ClientAppVersion; | ||
import usw.suwiki.domain.version.entity.ClientOS; | ||
import usw.suwiki.domain.version.repository.ClientAppVersionRepository; | ||
import usw.suwiki.global.exception.ExceptionType; | ||
import usw.suwiki.global.exception.errortype.VersionException; | ||
|
||
|
||
@Slf4j | ||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ClientAppVersionService { | ||
private final ClientAppVersionRepository clientAppVersionRepository; | ||
|
||
public CheckUpdateMandatoryResponse checkIsUpdateMandatory(String os, int versionCode) { | ||
ClientOS clientOS = ClientOS.ofString(os); | ||
ClientAppVersion clientAppVersion = clientAppVersionRepository | ||
.findFirstByOsAndIsVitalTrueOrderByVersionCodeDesc(clientOS) | ||
.orElseThrow(() -> new VersionException(ExceptionType.SERVER_ERROR)); | ||
|
||
boolean isUpdateMandatory = clientAppVersion.judgeIsUpdateMandatory(clientOS, versionCode); | ||
return CheckUpdateMandatoryResponse.from(isUpdateMandatory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
package usw.suwiki.global; | ||
|
||
import java.time.LocalDateTime; | ||
import javax.persistence.EntityListeners; | ||
import javax.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import javax.persistence.EntityListeners; | ||
import javax.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
|
||
|
||
@Getter | ||
@MappedSuperclass //Jpa Entity 클래스들이 BastTimeEntity 를 상속할 경우, 필드들도 칼럼으로 인식된다. | ||
@EntityListeners(AuditingEntityListener.class) //Auditing 기능을 포함시킨다. | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseTimeEntity { | ||
|
||
@CreatedDate // Entity가 생성되어 저장할 때 시간이 자동 저장된다. | ||
@CreatedDate | ||
private LocalDateTime createDate; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime modifiedDate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/usw/suwiki/global/exception/errortype/VersionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package usw.suwiki.global.exception.errortype; | ||
|
||
import usw.suwiki.global.exception.ExceptionType; | ||
|
||
public class VersionException extends BaseException { | ||
public VersionException(ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/usw/suwiki/global/annotation/SuwikiJpaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package usw.suwiki.global.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.context.annotation.Import; | ||
import usw.suwiki.config.TestJpaConfig; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
|
||
@DataJpaTest | ||
@Import(TestJpaConfig.class) | ||
@TestMethodOrder(MethodOrderer.DisplayName.class) | ||
@AutoConfigureTestDatabase(replace = Replace.NONE) | ||
public @interface SuwikiJpaTest { | ||
} |
Oops, something went wrong.