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

앱 버전 관리 기능 구현 #72

Merged
merged 35 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b56ce3e
refactor: 패키지명 변경
GIVEN53 Oct 26, 2023
57bbebe
refactor: intro interface, test용 controller 제거
GIVEN53 Oct 26, 2023
6ff0c40
refactor: 클래스명 변경
GIVEN53 Oct 26, 2023
fc81004
refactor: endpoint 변경
GIVEN53 Oct 26, 2023
27fda69
refactor: dto 클래스명 변경
GIVEN53 Oct 26, 2023
c8b0588
feat: version domain 생성
GIVEN53 Oct 26, 2023
f440026
refactor: 사용하지 않는 메서드 제거
GIVEN53 Oct 26, 2023
db1c7ea
feat: 생성자 구현
GIVEN53 Oct 26, 2023
a383311
feat: 버전 정보를 반환하는 기능 추가
GIVEN53 Oct 26, 2023
25b708d
docs: JavaDoc 추가
GIVEN53 Oct 26, 2023
e912ae7
refactor: 버전 enum 제거
GIVEN53 Oct 26, 2023
a53915a
docs: JavaDoc 추가, 수정
GIVEN53 Oct 26, 2023
1f3cd1c
feat: 앱 버전 post 요청시 body에 사용할 dto 추가
GIVEN53 Oct 26, 2023
cad1dc9
chore: update submodule
GIVEN53 Oct 26, 2023
1a9e10d
feat: 앱 버전을 저장하는 기능 추가
GIVEN53 Oct 26, 2023
5641cb8
feat: id auto increment
GIVEN53 Oct 26, 2023
f149c20
chore: version schema 추가
GIVEN53 Oct 26, 2023
0331aa8
feat: created_at 필드만 존재하는 base entity 추가
GIVEN53 Oct 26, 2023
9ca2dd0
chore: schema 포맷 수정, not null 수정
GIVEN53 Oct 26, 2023
bd1d8f6
chore: test용 schema symlink로 변경
GIVEN53 Oct 27, 2023
72879c2
fix: Version PK createdAt으로 변경
GIVEN53 Oct 27, 2023
c6d9aff
chore: data.sql version 추가
GIVEN53 Oct 27, 2023
5c3407a
refactor: @Value 생성자 주입으로 변경
GIVEN53 Oct 27, 2023
13550f9
chore: test yml에 key 추가
GIVEN53 Oct 27, 2023
127432a
feat: version fixture 추가
GIVEN53 Oct 27, 2023
bad1ac0
test: version repository unit test
GIVEN53 Oct 27, 2023
54b7a60
test: version service unit test
GIVEN53 Oct 27, 2023
1b32321
test: version controller unit test
GIVEN53 Oct 27, 2023
ee8fccf
refactor: 사용하지 않는 클래스 제거
GIVEN53 Oct 27, 2023
8d72644
refactor: fixture 반영
GIVEN53 Oct 27, 2023
ed96a1f
feat: 정규식 추가
GIVEN53 Oct 27, 2023
7c3f694
test: request body validation test
GIVEN53 Oct 27, 2023
a240e71
refactor: public 제거
GIVEN53 Oct 27, 2023
b935ece
refactor: 상수 처리
GIVEN53 Oct 27, 2023
8283777
refactor: 테스트 메서드 구체적으로 변경
GIVEN53 Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Value

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/com/coniverse/dangjang/domain/intro/dto/Version.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.coniverse.dangjang.domain.version.controller;

import org.springframework.http.HttpStatus;
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.coniverse.dangjang.domain.version.dto.request.VersionRequest;
import com.coniverse.dangjang.domain.version.dto.response.VersionResponse;
import com.coniverse.dangjang.domain.version.service.VersionService;
import com.coniverse.dangjang.global.dto.SuccessSingleResponse;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

/**
* 앱 버전 관련 controller
*
* @author TEO
* @since 1.3.0
*/
@RestController
@RequestMapping("/api/version")
@RequiredArgsConstructor
public class VersionController {
private final VersionService versionService;

/**
* 버전 정보를 GET 요청한다.
*
* @since 1.3.0
*/
@GetMapping("/intro")
public ResponseEntity<SuccessSingleResponse<VersionResponse<?>>> getIntro() {
VersionResponse<?> versionResponse = versionService.getVersionResponse();
return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse));
}

/**
* 버전 정보를 POST 요청한다.
*
* @since 1.3.0
*/
@PostMapping
public ResponseEntity<SuccessSingleResponse<VersionResponse<?>>> postVersion(@Valid @RequestBody VersionRequest request) {
VersionResponse<?> versionResponse = versionService.saveVersion(request);
return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), versionResponse));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.coniverse.dangjang.domain.version.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;

/**
* 앱 버전 post dto
*
* @author TEO
* @since 1.3.0
*/
public record VersionRequest(@NotBlank @Pattern(regexp = "^\\d\\.\\d\\.\\d$") String minVersion,
@NotBlank @Pattern(regexp = "^\\d\\.\\d\\.\\d$") String latestVersion, @NotBlank String key) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.coniverse.dangjang.domain.version.dto.response;

import java.util.List;

import com.coniverse.dangjang.domain.version.entity.Version;
import com.fasterxml.jackson.annotation.JsonInclude;

/**
* 버전 정보를 반환하는 dto이다.
*
* @author TEO
* @since 1.3.0
*/
public record VersionResponse<T>(String minVersion, String latestVersion, @JsonInclude(JsonInclude.Include.NON_NULL) List<T> loadData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadData가 어디서 쓰이는지 궁금해요 !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intro 때 클라이언트에서 미리 로드할 데이터들을 넘기기 위한 필드에요 1.0.0 버전 때부터 존재했던거 였는데 앞으로도 계속 쓰이지 않을 경우 삭제하도록 하겠습니당

public VersionResponse(Version version, List<T> loadData) {
this(version.getMinVersion(), version.getLatestVersion(), loadData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.coniverse.dangjang.domain.version.entity;

import java.time.LocalDateTime;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* app version entity
*
* @author TEO
* @since 1.3.0
*/
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EntityListeners(AuditingEntityListener.class)
public class Version {
@Id
@CreatedDate
private LocalDateTime createdAt;
private String minVersion;
private String latestVersion;

@Builder
private Version(String minVersion, String latestVersion) {
this.minVersion = minVersion;
this.latestVersion = latestVersion;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.coniverse.dangjang.domain.version.repository;

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

import com.coniverse.dangjang.domain.version.entity.Version;

/**
* app version repository
*
* @author TEO
* @since 1.3.0
*/
public interface VersionRepository extends JpaRepository<Version, Long> {

/**
* 가장 최근의 버전 정보를 반환한다.
*
* @return Version
* @since 1.3.0
*/
Version findFirstByOrderByCreatedAtDesc();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.coniverse.dangjang.domain.version.service;

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

import com.coniverse.dangjang.domain.version.dto.request.VersionRequest;
import com.coniverse.dangjang.domain.version.dto.response.VersionResponse;
import com.coniverse.dangjang.domain.version.entity.Version;
import com.coniverse.dangjang.domain.version.repository.VersionRepository;

import lombok.RequiredArgsConstructor;

/**
* 앱 버전 관련 service
*
* @author TEO
* @since 1.3.0
*/
@Service
@RequiredArgsConstructor
@Transactional
public class VersionService {
private final VersionRepository versionRepository;
@Value("${version.key}")
private final String serverKey;

/**
* 가장 최근의 버전 정보를 반환한다.
*
* @return VersionResponse
* @since 1.0.0
*/
@Transactional(readOnly = true)
public VersionResponse<?> getVersionResponse() {
Version version = versionRepository.findFirstByOrderByCreatedAtDesc();
return new VersionResponse<>(version, null);
}

/**
* 버전 정보를 저장한다.
*
* @param request 버전 정보
* @return VersionResponse
* @since 1.3.0
*/
public VersionResponse<?> saveVersion(VersionRequest request) {
validateKey(request.key());
Version version = Version.builder()
.minVersion(request.minVersion())
.latestVersion(request.latestVersion())
.build();
versionRepository.save(version);
return new VersionResponse<>(version, null);
}

/**
* 버전 정보의 키 값을 확인한다.
*
* @param key 버전 키
* @throws IllegalArgumentException 서버 키가 아닐 경우
* @since 1.3.0
*/
private void validateKey(String key) {
if (!key.equals(serverKey)) {
throw new IllegalArgumentException("올바르지 않은 키 값입니다.");
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/config
3 changes: 3 additions & 0 deletions src/main/resources/data-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ VALUES ("11111111", "fcmToken1", '2023-10-08'),
-- ("체중 기록!", "오늘 체중을 기록해보세요 ~ ", '2023-10-08', "기록", "22222222", true),
-- ("접속해주세요!", "오늘은 접속 안하셨네요 ~ 접속해서 포인트 받아가세요", '2023-10-09', "접속", "22222222", false),
-- ("운동 기록 !", "오늘 운동을 기록해보세요 ~ ", '2023-10-10', "기록", "11111111", false);

INSERT INTO version(created_at, min_version, latest_version)
VALUES (now(), "1.0.0", "1.0.0");
Loading
Loading