updated code

This commit is contained in:
harish
2024-10-20 11:34:15 +05:30
parent f7e512908a
commit 13ddfeaabf
5 changed files with 38 additions and 14 deletions

View File

@@ -93,4 +93,8 @@ public class HubDao {
return hubRepository.findByUniqueUuid(hubUuid).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND, return hubRepository.findByUniqueUuid(hubUuid).orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
Translator.toLocale(GepafinConstant.HUB_NOT_FOUND))); Translator.toLocale(GepafinConstant.HUB_NOT_FOUND)));
} }
public HubResponseBean getHubByHubUuid(String uuid) {
return convertToHubResponseBean(getHubByUuid(uuid));
}
} }

View File

@@ -14,4 +14,5 @@ public interface HubService {
List<HubResponseBean> getAllHubs(); List<HubResponseBean> getAllHubs();
void deleteHub(Long hubId); void deleteHub(Long hubId);
HubEntity getHubByUuid(String hubUuid); HubEntity getHubByUuid(String hubUuid);
HubResponseBean getHubByHubUuid(String uuid);
} }

View File

@@ -51,4 +51,9 @@ public class HubServiceImpl implements HubService {
public HubEntity getHubByUuid(String hubUuid) { public HubEntity getHubByUuid(String hubUuid) {
return hubDao.getHubByUuid(hubUuid); return hubDao.getHubByUuid(hubUuid);
} }
@Override
public HubResponseBean getHubByHubUuid(String uuid) {
return hubDao.getHubByHubUuid(uuid);
}
} }

View File

@@ -64,7 +64,6 @@ public interface HubApi {
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = { @ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) })) @ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))
}) })
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
@GetMapping(value = "/{hubId}", produces = "application/json") @GetMapping(value = "/{hubId}", produces = "application/json")
ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request, ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request,
@Parameter(description = "The hub id", required = true) @Parameter(description = "The hub id", required = true)
@@ -97,4 +96,18 @@ public interface HubApi {
ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request, ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request,
@Parameter(description = "The hub id", required = true) @Parameter(description = "The hub id", required = true)
@PathVariable("hubId") Long hubId); @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);
} }

View File

@@ -8,9 +8,10 @@ import net.gepafin.tendermanagement.model.request.HubReq;
import net.gepafin.tendermanagement.model.response.HubResponseBean; import net.gepafin.tendermanagement.model.response.HubResponseBean;
import net.gepafin.tendermanagement.model.util.Response; import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.HubService; 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.HubApi;
import net.gepafin.tendermanagement.web.rest.api.errors.Status; 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.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -20,17 +21,11 @@ import java.util.List;
@RestController @RestController
public class HubApiController implements HubApi { public class HubApiController implements HubApi {
private final HubService hubService; @Autowired
private final Validator validator; private HubService hubService;
public HubApiController(HubService hubService, Validator validator) {
this.hubService = hubService;
this.validator = validator;
}
@Override @Override
public ResponseEntity<Response<HubResponseBean>> createHub(HttpServletRequest request, @Valid HubReq hubReq) { public ResponseEntity<Response<HubResponseBean>> createHub(HttpServletRequest request, @Valid HubReq hubReq) {
validator.validateUser(request);
HubResponseBean hubResponse = hubService.createHub(hubReq); HubResponseBean hubResponse = hubService.createHub(hubReq);
return ResponseEntity.status(HttpStatus.CREATED) return ResponseEntity.status(HttpStatus.CREATED)
.body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_CREATE_SUCCESS))); .body(new Response<>(hubResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_CREATE_SUCCESS)));
@@ -38,7 +33,7 @@ public class HubApiController implements HubApi {
@Override @Override
public ResponseEntity<Response<HubResponseBean>> updateHub(HttpServletRequest request, Long hubId, @Valid HubReq hubReq) { public ResponseEntity<Response<HubResponseBean>> updateHub(HttpServletRequest request, Long hubId, @Valid HubReq hubReq) {
validator.validateUser(request);
HubResponseBean hubResponse = hubService.updateHub(hubId, hubReq); HubResponseBean hubResponse = hubService.updateHub(hubId, hubReq);
if (hubResponse != null) { if (hubResponse != null) {
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
@@ -51,7 +46,7 @@ public class HubApiController implements HubApi {
@Override @Override
public ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request, Long hubId) { public ResponseEntity<Response<HubResponseBean>> getHubById(HttpServletRequest request, Long hubId) {
validator.validateUser(request);
HubResponseBean hubResponse = hubService.getHubById(hubId); HubResponseBean hubResponse = hubService.getHubById(hubId);
if (hubResponse != null) { if (hubResponse != null) {
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
@@ -64,7 +59,7 @@ public class HubApiController implements HubApi {
@Override @Override
public ResponseEntity<Response<List<HubResponseBean>>> getAllHubs(HttpServletRequest request) { public ResponseEntity<Response<List<HubResponseBean>>> getAllHubs(HttpServletRequest request) {
validator.validateUser(request);
List<HubResponseBean> hubs = hubService.getAllHubs(); List<HubResponseBean> hubs = hubService.getAllHubs();
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(hubs, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_ALL_SUCCESS))); .body(new Response<>(hubs, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_GET_ALL_SUCCESS)));
@@ -72,9 +67,15 @@ public class HubApiController implements HubApi {
@Override @Override
public ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request, Long hubId) { public ResponseEntity<Response<Void>> deleteHub(HttpServletRequest request, Long hubId) {
validator.validateUser(request);
hubService.deleteHub(hubId); hubService.deleteHub(hubId);
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.HUB_DELETE_SUCCESS))); .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)));
}
} }