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

Issue30 builderclasses #60

Merged
merged 18 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
49 changes: 26 additions & 23 deletions src/main/java/io/aiven/klaw/controller/SchemaRegstryController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.aiven.klaw.controller;

import static io.aiven.klaw.service.UtilControllerService.handleException;

import io.aiven.klaw.error.KlawException;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.model.SchemaRequestModel;
Expand Down Expand Up @@ -49,14 +51,14 @@ public ResponseEntity<List<SchemaRequestModel>> getCreatedSchemaRequests(
@PostMapping(
value = "/deleteSchemaRequests",
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> deleteSchemaRequests(
public ResponseEntity<ApiResponse> deleteSchemaRequests(
@RequestParam("req_no") String avroSchemaReqId) {

String deleteTopicReqStatus =
schemaRegstryControllerService.deleteSchemaRequests(avroSchemaReqId);

deleteTopicReqStatus = "{\"result\":\"" + deleteTopicReqStatus + "\"}";
return new ResponseEntity<>(deleteTopicReqStatus, HttpStatus.OK);
try {
return new ResponseEntity<>(
schemaRegstryControllerService.deleteSchemaRequests(avroSchemaReqId), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(
Expand All @@ -68,34 +70,35 @@ public ResponseEntity<ApiResponse> execSchemaRequests(
return new ResponseEntity<>(
schemaRegstryControllerService.execSchemaRequests(avroSchemaReqId), HttpStatus.OK);
} catch (KlawException e) {
log.error(e.getMessage());
return new ResponseEntity<>(
ApiResponse.builder().message("Unable to register schema").build(),
HttpStatus.INTERNAL_SERVER_ERROR);
return handleException(e);
}
}

@PostMapping(
value = "/execSchemaRequestsDecline",
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> execSchemaRequestsDecline(
public ResponseEntity<ApiResponse> execSchemaRequestsDecline(
@RequestParam("avroSchemaReqId") String avroSchemaReqId,
@RequestParam("reasonForDecline") String reasonForDecline) {
String updateTopicReqStatus =
"{\"result\":\""
+ schemaRegstryControllerService.execSchemaRequestsDecline(
avroSchemaReqId, reasonForDecline)
+ "\"}";
return new ResponseEntity<>(updateTopicReqStatus, HttpStatus.OK);

try {
return new ResponseEntity<>(
schemaRegstryControllerService.execSchemaRequestsDecline(
avroSchemaReqId, reasonForDecline),
HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(value = "/uploadSchema")
public ResponseEntity<ApiResponse> uploadSchema(
@Valid @RequestBody SchemaRequestModel addSchemaRequest) {
return new ResponseEntity<>(
ApiResponse.builder()
.result(schemaRegstryControllerService.uploadSchema(addSchemaRequest))
.build(),
HttpStatus.OK);
try {
return new ResponseEntity<>(
schemaRegstryControllerService.uploadSchema(addSchemaRequest), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}
}
14 changes: 11 additions & 3 deletions src/main/java/io/aiven/klaw/controller/ServerConfigController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.aiven.klaw.controller;

import static io.aiven.klaw.service.UtilControllerService.handleException;

import io.aiven.klaw.error.KlawException;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.model.KwPropertiesModel;
import io.aiven.klaw.model.ServerConfigProperties;
import io.aiven.klaw.service.ServerConfigService;
Expand Down Expand Up @@ -47,10 +51,14 @@ public ResponseEntity<Map<String, String>> resetCache() {
}

@PostMapping(value = "/updateKwCustomProperty")
public ResponseEntity<Map<String, String>> updateKwCustomProperty(
public ResponseEntity<ApiResponse> updateKwCustomProperty(
@RequestBody KwPropertiesModel kwPropertiesModel) {
return new ResponseEntity<>(
serverConfigService.updateKwCustomProperty(kwPropertiesModel), HttpStatus.OK);
try {
return new ResponseEntity<>(
serverConfigService.updateKwCustomProperty(kwPropertiesModel), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@RequestMapping(
Expand Down
80 changes: 43 additions & 37 deletions src/main/java/io/aiven/klaw/controller/TopicController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.aiven.klaw.controller;

import static io.aiven.klaw.service.UtilControllerService.handleException;

import io.aiven.klaw.error.KlawException;
import io.aiven.klaw.model.ApiResponse;
import io.aiven.klaw.model.TopicInfo;
Expand Down Expand Up @@ -34,29 +36,34 @@ public ResponseEntity<ApiResponse> createTopicsRequest(
return new ResponseEntity<>(
topicControllerService.createTopicsRequest(addTopicRequest), HttpStatus.OK);
} catch (KlawException e) {
log.error(e.getMessage());
return new ResponseEntity<>(
ApiResponse.builder().message("Unable to create a topic request").build(),
HttpStatus.INTERNAL_SERVER_ERROR);
return handleException(e);
}
}

@PostMapping(
value = "/createTopicDeleteRequest",
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Map<String, String>> createTopicDeleteRequest(
public ResponseEntity<ApiResponse> createTopicDeleteRequest(
@RequestParam("topicName") String topicName, @RequestParam("env") String envId) {
return new ResponseEntity<>(
topicControllerService.createTopicDeleteRequest(topicName, envId), HttpStatus.OK);
try {
return new ResponseEntity<>(
topicControllerService.createTopicDeleteRequest(topicName, envId), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(
value = "/createClaimTopicRequest",
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Map<String, String>> createClaimTopicRequest(
public ResponseEntity<ApiResponse> createClaimTopicRequest(
@RequestParam("topicName") String topicName, @RequestParam("env") String envId) {
return new ResponseEntity<>(
topicControllerService.createClaimTopicRequest(topicName, envId), HttpStatus.OK);
try {
return new ResponseEntity<>(
topicControllerService.createClaimTopicRequest(topicName, envId), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@RequestMapping(
Expand Down Expand Up @@ -104,8 +111,13 @@ public ResponseEntity<List<TopicRequestModel>> getCreatedTopicRequests(
value = "/deleteTopicRequests",
method = RequestMethod.POST,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> deleteTopicRequests(@RequestParam("topicId") String topicId) {
return new ResponseEntity<>(topicControllerService.deleteTopicRequests(topicId), HttpStatus.OK);
public ResponseEntity<ApiResponse> deleteTopicRequests(@RequestParam("topicId") String topicId) {
try {
return new ResponseEntity<>(
topicControllerService.deleteTopicRequests(topicId), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@PostMapping(
Expand All @@ -116,26 +128,22 @@ public ResponseEntity<ApiResponse> approveTopicRequests(@RequestParam("topicId")
return new ResponseEntity<>(
topicControllerService.approveTopicRequests(topicId), HttpStatus.OK);
} catch (KlawException e) {
log.error(e.getMessage());
return new ResponseEntity<>(
ApiResponse.builder()
.message("Unable to approve topics")
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build(),
HttpStatus.INTERNAL_SERVER_ERROR);
return handleException(e);
}
}

@PostMapping(
value = "/execTopicRequestsDecline",
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> declineTopicRequests(
public ResponseEntity<ApiResponse> declineTopicRequests(
@RequestParam("topicId") String topicId,
@RequestParam("reasonForDecline") String reasonForDecline)
throws KlawException {

return new ResponseEntity<>(
topicControllerService.declineTopicRequests(topicId, reasonForDecline), HttpStatus.OK);
@RequestParam("reasonForDecline") String reasonForDecline) {
try {
return new ResponseEntity<>(
topicControllerService.declineTopicRequests(topicId, reasonForDecline), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

@RequestMapping(
Expand All @@ -148,8 +156,7 @@ public ResponseEntity<List<List<TopicInfo>>> getTopics(
@RequestParam(value = "currentPage", defaultValue = "") String currentPage,
@RequestParam(value = "topicnamesearch", required = false) String topicNameSearch,
@RequestParam(value = "teamName", required = false) String teamName,
@RequestParam(value = "topicType", required = false) String topicType)
throws Exception {
@RequestParam(value = "topicType", required = false) String topicType) {

return new ResponseEntity<>(
topicControllerService.getTopics(
Expand All @@ -162,8 +169,7 @@ public ResponseEntity<List<List<TopicInfo>>> getTopics(
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<String>> getTopicsOnly(
@RequestParam(value = "isMyTeamTopics", defaultValue = "false") String isMyTeamTopics)
throws Exception {
@RequestParam(value = "isMyTeamTopics", defaultValue = "false") String isMyTeamTopics) {
return new ResponseEntity<>(
topicControllerService.getAllTopics(Boolean.parseBoolean(isMyTeamTopics)), HttpStatus.OK);
}
Expand All @@ -173,19 +179,19 @@ public ResponseEntity<List<String>> getTopicsOnly(
method = RequestMethod.GET,
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Map<String, Object>> getTopicDetailsPerEnv(
@RequestParam("envSelected") String envId, @RequestParam("topicname") String topicName)
throws Exception {

@RequestParam("envSelected") String envId, @RequestParam("topicname") String topicName) {
return new ResponseEntity<>(
topicControllerService.getTopicDetailsPerEnv(envId, topicName), HttpStatus.OK);
}

@PostMapping(value = "/saveTopicDocumentation")
public ResponseEntity<Map<String, String>> saveTopicDocumentation(
@RequestBody TopicInfo topicInfo) {
Map<String, String> saveTopicDocumentationResult =
topicControllerService.saveTopicDocumentation(topicInfo);
return new ResponseEntity<>(saveTopicDocumentationResult, HttpStatus.OK);
public ResponseEntity<ApiResponse> saveTopicDocumentation(@RequestBody TopicInfo topicInfo) {
try {
return new ResponseEntity<>(
topicControllerService.saveTopicDocumentation(topicInfo), HttpStatus.OK);
} catch (KlawException e) {
return handleException(e);
}
}

// getTopic Events from kafka cluster
Expand Down
Loading