Added user action and versioning for company.
This commit is contained in:
@@ -4,6 +4,10 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||
import net.gepafin.tendermanagement.model.request.UserActionRequest;
|
||||
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,71 +34,101 @@ import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||
@RestController
|
||||
@RequestMapping("${openapi.gepafin.base-path:/v1/company}")
|
||||
public class CompanyApiController implements CompanyApi{
|
||||
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CompanyApiController.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
private CompanyService companyService;
|
||||
|
||||
@Autowired
|
||||
private LoggingUtil loggingUtil;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<CompanyResponse>> createCompany(HttpServletRequest request,
|
||||
CompanyRequest companyRequest) {
|
||||
log.info("Create company with - Request Body: {}", companyRequest);
|
||||
|
||||
/** This code is responsible for creating user action logs for "Creating company" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT).actionContext(UserActionContextEnum.CREATE_COMPANY).build());
|
||||
|
||||
CompanyResponse data = companyService.createCompany(request, companyRequest);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_CREATED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<CompanyResponse>> updateCompany(HttpServletRequest request, Long companyId,
|
||||
CompanyRequest companyRequest) {
|
||||
log.info("Update company with - Request Body: {}", companyRequest);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "update company" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPDATE).actionContext(UserActionContextEnum.UPDATE_COMPANY).build());
|
||||
|
||||
CompanyResponse data = companyService.updateCompany(request, companyId, companyRequest);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_UPDATED_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<CompanyResponse>> getCompany(HttpServletRequest request, Long companyId) {
|
||||
|
||||
|
||||
log.info("Get company with id: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "get company" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_COMPANY).build());
|
||||
|
||||
CompanyResponse data = companyService.getCompany(request, companyId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_GET_SUCCESS_MSG)));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_GET_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> deleteCompany(HttpServletRequest request, Long companyId) {
|
||||
log.info("Delete company with id: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "delete company" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.DELETE_COMPANY).build());
|
||||
|
||||
companyService.deleteCompany(request, companyId);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_DELETE_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<CompanyResponse>>> getCompanyByUserId(HttpServletRequest request, Long userId) {
|
||||
|
||||
log.info("Get company with userId: {}", userId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Get company by user id" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_COMPANY_BY_USER).build());
|
||||
|
||||
List<CompanyResponse> data = companyService.getCompanyByUserId(request, userId);
|
||||
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.COMPANY_GET_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<Map<String,Object>>> checkVatNumber(HttpServletRequest request, String vatNumber) {
|
||||
log.info("check VatNumber with: {}", vatNumber);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Check vat number" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.CHECK_COMPANY_VAT_NUMBER).build());
|
||||
|
||||
Map<String,Object> data = companyService.checkVatNumber(request, vatNumber);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.CHECK_VATNUMBER_SUCCESS_MSG)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<byte[]> downloadCompanyDelegation(HttpServletRequest request, Long companyId, CompanyDelegationRequest companyDelegationRequest) {
|
||||
log.info("download company delegation with companyId: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Download company delegation" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DOWNLOAD).actionContext(UserActionContextEnum.DOWNLOAD_COMPANY_DELEGATION_TEMPLATE).build());
|
||||
|
||||
ByteArrayOutputStream data = companyService.downloadCompanyDelegation(request, companyId, companyDelegationRequest);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
@@ -102,35 +136,51 @@ public class CompanyApiController implements CompanyApi{
|
||||
|
||||
return new ResponseEntity<>(data.toByteArray(), headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<CompanyDelegationResponse>> uploadCompanyDelegation(HttpServletRequest request, Long companyId,
|
||||
MultipartFile file) {
|
||||
log.info("upload company delegation with companyId: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Uploading company delegation document" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.UPLOAD).actionContext(UserActionContextEnum.UPLOAD_COMPANY_DELEGATION).build());
|
||||
|
||||
CompanyDelegationResponse companyDelegationResponse = companyService.uploadCompanyDelegation(request, companyId, file);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FILE_UPLOAD_SUCCESS)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<CompanyDelegationResponse>> getCompanyDelegation(HttpServletRequest request,
|
||||
Long companyId) {
|
||||
log.info("get company delegation with companyId: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Get company delegation" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_COMPANY_DELEGATION).build());
|
||||
|
||||
CompanyDelegationResponse companyDelegationResponse = companyService.getCompanyDelegation(request, companyId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(companyDelegationResponse, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_FETCH_SUCCESS)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> deleteCompanyDelegation(HttpServletRequest request,
|
||||
Long companyId) {
|
||||
public ResponseEntity<Response<Void>> deleteCompanyDelegation(HttpServletRequest request, Long companyId) {
|
||||
|
||||
log.info("delete company delegation with companyId: {}", companyId);
|
||||
|
||||
/** This code is responsible for creating user action logs for the "delete company delegation" operation. **/
|
||||
loggingUtil.logUserAction(
|
||||
UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.DELETE_COMPANY_DELEGATION).build());
|
||||
|
||||
companyService.deleteCompanyDelegation(request, companyId);
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_DELETE_SUCCESS)));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new Response<>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.DELEGATION_DELETE_SUCCESS)));
|
||||
}
|
||||
@Override
|
||||
public ResponseEntity<Response<Void>> removeCompanyFromList(HttpServletRequest request, Long companyId) {
|
||||
log.info("Api to remove a company from user's list");
|
||||
|
||||
/** This code is responsible for creating user action logs for the "Remove company from user list" operation. **/
|
||||
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.DELETE).actionContext(UserActionContextEnum.REMOVE_COMPANY_FROM_USER).build());
|
||||
|
||||
companyService.removeCompanyFromList(request, companyId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
|
||||
Reference in New Issue
Block a user