Skip to content

Commit

Permalink
Merge branch 'master' into EFRS-1270_fix_swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
VolodymyrBushko authored Sep 6, 2022
2 parents 77490f1 + 5c4ca23 commit 0acbfc6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.exadel.frs.controller;


import static com.exadel.frs.system.global.Constants.ADMIN;
import static com.exadel.frs.commonservice.enums.AppStatus.NOT_READY;
import static com.exadel.frs.commonservice.enums.AppStatus.OK;
import com.exadel.frs.commonservice.enums.AppStatus;
import com.exadel.frs.dto.ui.AppStatusResponseDto;
import io.swagger.annotations.ApiOperation;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;

@Slf4j
@RestController
@RequestMapping(ADMIN)
@RequiredArgsConstructor
Expand All @@ -22,13 +26,12 @@ public class AppStatusController {
@GetMapping("/status")
@ApiOperation(value = "Get status of application")
public AppStatusResponseDto getAppStatus() {
AppStatusResponseDto responseDto = new AppStatusResponseDto();
try {
responseDto.setStatus(dataSource.getConnection().isValid(1000) ? AppStatus.OK : AppStatus.NOT_READY);
return responseDto;
} catch (Exception e) {
responseDto.setStatus(AppStatus.NOT_READY);
return responseDto;
try (Connection connection = dataSource.getConnection()) {
AppStatus status = connection.isValid(1000) ? OK : NOT_READY;
return new AppStatusResponseDto(status);
} catch (SQLException e) {
log.error(e.getMessage(), e);
return new AppStatusResponseDto(NOT_READY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
package com.exadel.frs.dto.ui;

import com.exadel.frs.commonservice.enums.AppStatus;
import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Data
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class AppStatusResponseDto {

private AppStatus status;
}
}

0 comments on commit 0acbfc6

Please sign in to comment.