RED-9393: user stats endpoint
added endpoint
This commit is contained in:
parent
539da8d80e
commit
98c2aed8ba
@ -0,0 +1,56 @@
|
||||
package com.iqser.red.persistence.service.v1.external.api.impl.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.DossierEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.DossierService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.FileStatusManagementService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.FileStatusPersistenceService;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.service.users.UserService;
|
||||
import com.iqser.red.service.persistence.service.v1.api.external.model.UserStats;
|
||||
import com.iqser.red.service.persistence.service.v1.api.external.resource.UserStatsResource;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class UserStatsController implements UserStatsResource {
|
||||
|
||||
private final UserService userService;
|
||||
private final DossierService dossierService;
|
||||
private final FileStatusManagementService fileStatusManagementService;
|
||||
private final FileStatusPersistenceService fileStatusPersistenceService;
|
||||
|
||||
|
||||
@Override
|
||||
public UserStats getUserStats(String userId) {
|
||||
|
||||
if (userService.getUserById(userId) == null) {
|
||||
return null;
|
||||
}
|
||||
List<DossierEntity> allDossiers = dossierService.getAllDossiers();
|
||||
List<FileEntity> allFiels = fileStatusPersistenceService.getAllFiles()
|
||||
.stream()
|
||||
.filter(file -> file.getAssignee().equals(userId))
|
||||
.collect(Collectors.toList());
|
||||
int numberOfDossierOwnerships = allDossiers.stream()
|
||||
.filter(dossier -> dossier.getOwnerId().equals(userId))
|
||||
.collect(Collectors.toList()).size();
|
||||
int numberOfDossierMemberships = allDossiers.stream()
|
||||
.filter(dossier -> dossier.getMemberIds().contains(userId))
|
||||
.collect(Collectors.toList()).size();
|
||||
int numberOfAssignedFiles = allFiels.size();
|
||||
return UserStats.builder()
|
||||
.numberOfDossierOwnerships(numberOfDossierOwnerships)
|
||||
.numberOfDossierMemberships(numberOfDossierMemberships)
|
||||
.numberOfAssignedFiles(numberOfAssignedFiles)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.external.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserStats {
|
||||
|
||||
private int numberOfDossierMemberships;
|
||||
private int numberOfDossierOwnerships;
|
||||
private int numberOfAssignedFiles;
|
||||
|
||||
}
|
||||
@ -0,0 +1,38 @@
|
||||
package com.iqser.red.service.persistence.service.v1.api.external.resource;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.external.model.UserStats;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
|
||||
@ApiResponses(value = {@ApiResponse(responseCode = "429", description = "Too many requests.")})
|
||||
public interface UserStatsResource {
|
||||
|
||||
String USER_PATH = "/users";
|
||||
|
||||
String USER_ID_PARAM = "userId";
|
||||
|
||||
String USER_ID_PATH_VARIABLE = "/{" + USER_ID_PARAM + "}";
|
||||
|
||||
String STATS_PATH = "/stats";
|
||||
|
||||
String PATH = ExternalApi.BASE_PATH + STATS_PATH + USER_PATH;
|
||||
|
||||
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
@GetMapping(value = PATH+ USER_ID_PATH_VARIABLE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "Gets user stats for user specified by id.", description = "")
|
||||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found")})
|
||||
UserStats getUserStats(@Parameter(name = USER_ID_PARAM, description = "The unique identifier of the user whose statistics we want to retrieve.", required = true) @PathVariable(USER_ID_PARAM) String userId);
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user