Skip to content

Commit

Permalink
12308 add an endpoint to update app user feature configuration (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
palina-krukovich authored May 6, 2024
1 parent 74ce8eb commit 23920f6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kontur.disasterninja.client;

import com.fasterxml.jackson.databind.JsonNode;
import io.kontur.disasterninja.dto.*;
import io.kontur.disasterninja.service.KeycloakAuthorizationService;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -26,6 +27,7 @@ public class UserProfileClient extends RestClientWithBearerAuth {
private static final Logger LOG = LoggerFactory.getLogger(UserProfileClient.class);
private static final String FEATURES_USER_FEED_URL = "/features/user_feed";
private static final String FEATURES_URL = "/features";
private static final String FEATURES_FEATURE_NAME_URL = "/features/{featureName}";
private static final String APP_URL = "/apps";
private static final String APP_URL_WITH_ID = "/apps/{id}";
private static final String APP_CONFIG_URL = "/apps/configuration";
Expand Down Expand Up @@ -153,4 +155,14 @@ public ResponseEntity<AssetDto> getAsset(UUID appId, String filename) {
return userProfileRestTemplate.exchange(ASSETS_URL, GET, httpEntityWithUserBearerAuthIfPresentAndNoCacheHeader(null),
new ParameterizedTypeReference<>() {}, appId, filename);
}

public ResponseEntity<Void> updateAppUserFeatureConfiguration(UUID appId, String featureName, JsonNode configuration) {
String url = UriComponentsBuilder.fromUriString(FEATURES_FEATURE_NAME_URL)
.buildAndExpand(featureName)
.toUriString();

return userProfileRestTemplate.exchange(
url, PUT, httpEntityWithUserBearerAuthIfPresentAndNoCacheHeader(configuration),
new ParameterizedTypeReference<Void>() {}, appId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kontur.disasterninja.controller;

import com.fasterxml.jackson.databind.JsonNode;
import io.kontur.disasterninja.client.UserProfileClient;
import io.kontur.disasterninja.dto.FeatureDto;
import io.kontur.disasterninja.service.LiveSensorFeatureService;
Expand Down Expand Up @@ -42,6 +43,22 @@ public List<FeatureDto> getUserAppFeatures(
return userProfileClient.getUserAppFeatures(appId);
}

@Operation(tags = "Features", summary = "Update app feature configuration for a user")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successfully updated the user's feature configuration"),
@ApiResponse(responseCode = "401", description = "Unauthorized: User not authenticated"),
@ApiResponse(responseCode = "403", description = "Forbidden: User is not allowed to configure this feature"),
@ApiResponse(responseCode = "404", description = "Not Found: App, feature, or user does not exist"),
@ApiResponse(responseCode = "500", description = "Internal Server Error: Error processing the update")
})
@PutMapping("/{featureName}")
public ResponseEntity<Void> updateUserFeatureConfiguration(
@PathVariable(name = "featureName", required = true) String featureName,
@RequestParam(name = "appId", defaultValue = "58851b50-9574-4aec-a3a6-425fa18dcb54", required = true) UUID appId,
@RequestBody JsonNode configuration) {
return userProfileClient.updateAppUserFeatureConfiguration(appId, featureName, configuration);
}

@Operation(tags = "Features", summary = "Append user's live sensor data")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Append was successful")})
Expand Down

0 comments on commit 23920f6

Please sign in to comment.