updated code
This commit is contained in:
@@ -93,4 +93,8 @@ public class HubDao {
|
||||
return hubRepository.findByUniqueUuid(hubUuid).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.HUB_NOT_FOUND)));
|
||||
}
|
||||
|
||||
public HubResponseBean getHubByHubUuid(String uuid) {
|
||||
return convertToHubResponseBean(getHubByUuid(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,5 @@ public interface HubService {
|
||||
List<HubResponseBean> getAllHubs();
|
||||
void deleteHub(Long hubId);
|
||||
HubEntity getHubByUuid(String hubUuid);
|
||||
HubResponseBean getHubByHubUuid(String uuid);
|
||||
}
|
||||
|
||||
@@ -51,4 +51,9 @@ public class HubServiceImpl implements HubService {
|
||||
public HubEntity getHubByUuid(String hubUuid) {
|
||||
return hubDao.getHubByUuid(hubUuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HubResponseBean getHubByHubUuid(String uuid) {
|
||||
return hubDao.getHubByHubUuid(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@ public interface HubApi {
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||
})
|
||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||
@GetMapping(value = "/{hubId}", produces = "application/json")
|
||||
ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request,
|
||||
@Parameter(description = "The hub id", required = true)
|
||||
@@ -97,4 +96,18 @@ public interface HubApi {
|
||||
ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request,
|
||||
@Parameter(description = "The hub id", required = true)
|
||||
@PathVariable("hubId") Long hubId);
|
||||
|
||||
@Operation(summary = "API to get a hub by id", responses = {
|
||||
@ApiResponse(responseCode = "200", description = "OK"),
|
||||
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
|
||||
})
|
||||
@GetMapping(value = "/uuid/{uuid}", produces = "application/json")
|
||||
ResponseEntity<Response<HubResponseBean>> getHubByUuid(HttpServletRequest request,
|
||||
@Parameter(description = "The hub id", required = true)
|
||||
@PathVariable("uuid") String uuid);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,10 @@ import net.gepafin.tendermanagement.model.request.HubReq;
|
||||
import net.gepafin.tendermanagement.model.response.HubResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
import net.gepafin.tendermanagement.service.HubService;
|
||||
import net.gepafin.tendermanagement.util.Validator;
|
||||
import net.gepafin.tendermanagement.web.rest.api.HubApi;
|
||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -20,17 +21,11 @@ import java.util.List;
|
||||
@RestController
|
||||
public class HubApiController implements HubApi {
|
||||
|
||||
private final HubService hubService;
|
||||
private final Validator validator;
|
||||
|
||||
public HubApiController(HubService hubService, Validator validator) {
|
||||
this.hubService = hubService;
|
||||
this.validator = validator;
|
||||
}
|
||||
@Autowired
|
||||
private HubService hubService;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<HubResponseBean>> createHub(HttpServletRequest request, @Valid HubReq hubReq) {
|
||||
validator.validateUser(request);
|
||||
HubResponseBean hubResponse = hubService.createHub(hubReq);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_CREATE_SUCCESS)));
|
||||
@@ -38,7 +33,7 @@ public class HubApiController implements HubApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<HubResponseBean>> updateHub(HttpServletRequest request, Long hubId, @Valid HubReq hubReq) {
|
||||
validator.validateUser(request);
|
||||
|
||||
HubResponseBean hubResponse = hubService.updateHub(hubId, hubReq);
|
||||
if (hubResponse != null) {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
@@ -51,7 +46,7 @@ public class HubApiController implements HubApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request, Long hubId) {
|
||||
validator.validateUser(request);
|
||||
|
||||
HubResponseBean hubResponse = hubService.getHubById(hubId);
|
||||
if (hubResponse != null) {
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
@@ -64,7 +59,7 @@ public class HubApiController implements HubApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<HubResponseBean>>> getAllHubs(HttpServletRequest request) {
|
||||
validator.validateUser(request);
|
||||
|
||||
List<HubResponseBean> hubs = hubService.getAllHubs();
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(hubs, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_ALL_SUCCESS)));
|
||||
@@ -72,9 +67,15 @@ public class HubApiController implements HubApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request, Long hubId) {
|
||||
validator.validateUser(request);
|
||||
|
||||
hubService.deleteHub(hubId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_DELETE_SUCCESS)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<HubResponseBean>> getHubByUuid(HttpServletRequest request, String uuid) {
|
||||
HubResponseBean hubResponse = hubService.getHubByHubUuid(uuid);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_SUCCESS)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user