Skip to content

Commit 038d5a7

Browse files
committed
feat: add application version info retrieval functionality
1 parent f99558b commit 038d5a7

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

backend/src/main/java/com/park/utmstack/config/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ public final class Constants {
162162
public static final String API_KEY_HEADER = "Utm-Api-Key";
163163
public static final List<String> API_ENDPOINT_IGNORE = Collections.emptyList();
164164

165+
// Application version file
166+
public static final String APP_VERSION_FILE = "/utmstack//version/version.json";
167+
165168
private Constants() {
166169
}
167170
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.park.utmstack.service.app_info;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.park.utmstack.service.dto.app_info.AppInfoDto;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.stereotype.Service;
7+
8+
import java.io.File;
9+
import java.io.IOException;
10+
11+
import static com.park.utmstack.config.Constants.APP_VERSION_FILE;
12+
13+
@Service
14+
@Slf4j
15+
public class AppInfoService {
16+
17+
private static final String CLASSNAME = "AppInfoService";
18+
19+
public AppInfoDto loadVersionInfo() throws Exception {
20+
final String ctx = "loadVersionInfo";
21+
try {
22+
ObjectMapper mapper = new ObjectMapper();
23+
return mapper.readValue(new File(APP_VERSION_FILE), AppInfoDto.class);
24+
} catch (IOException e) {
25+
log.error("{}: An error occurred while reading the version file: {}", CLASSNAME + "." + ctx, e.getMessage(), e);
26+
throw new RuntimeException("An error occurred while reading the version file");
27+
}
28+
29+
}
30+
}
31+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.park.utmstack.service.dto.app_info;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@Data
9+
@AllArgsConstructor
10+
@NoArgsConstructor
11+
@JsonIgnoreProperties(ignoreUnknown = true)
12+
public class AppInfoDto {
13+
private String version;
14+
private String edition;
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.park.utmstack.web.rest.app_info;
2+
3+
import com.park.utmstack.service.app_info.AppInfoService;
4+
import com.park.utmstack.service.dto.app_info.AppInfoDto;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
@RestController
12+
@RequestMapping("/api/info")
13+
@RequiredArgsConstructor
14+
public class AppInfoResource {
15+
16+
private final AppInfoService appInfoService;
17+
18+
@GetMapping("/version")
19+
public ResponseEntity<AppInfoDto> getInfo() throws Exception {
20+
return ResponseEntity.ok(appInfoService.loadVersionInfo());
21+
}
22+
}

0 commit comments

Comments
 (0)