use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class InitiativeService method wantToContribute.
@Transactional
public PostResult wantToContribute(UUID initiativeId, UUID userId) {
Initiative initiative = initiativeRepository.findById(initiativeId);
AppUser user = appUserRepository.findByC1Id(userId);
List<DecisionMaker> admins = decisionMakerRepository.findByGovernance_IdAndRole(initiative.getGovernance().getId(), DecisionMakerRole.ADMIN);
for (DecisionMaker admin : admins) {
WantToContributeNotification notification = new WantToContributeNotification();
notification.setInitiative(initiative);
notification.setAdmin(admin.getUser());
notification.setUser(user);
notification.setEmailState(NotificationEmailState.PENDING);
wantToContributeRepository.save(notification);
}
return new PostResult("success", "notifications recorded for sending", null);
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class TokenController method mintTokens.
@RequestMapping(path = "/token/{tokenId}/mint", method = RequestMethod.PUT)
public PostResult mintTokens(@PathVariable("tokenId") String tokenIdStr, @RequestBody TokenMintDto mintDto) {
if (getLoggedUser() == null) {
return new PostResult("error", "endpoint enabled users only", null);
}
UUID tokenId = UUID.fromString(tokenIdStr);
if (governanceService.canMintTokens(tokenId, getLoggedUser().getC1Id()) == DecisionVerdict.DENIED) {
return new PostResult("error", "not authorized", "");
}
Initiative initiative = initiativeService.findByTokenType_Id(tokenId);
String result = tokenTransferService.mintToInitiative(tokenId, initiative.getId(), getLoggedUser().getC1Id(), mintDto);
if (result.equals("success")) {
return new PostResult("success", "tokens minted", tokenId.toString());
} else {
return new PostResult("error", "error while minting tokens", "");
}
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class FileService method uploadInitiativeImage.
@Transactional
public PostResult uploadInitiativeImage(UUID userId, UUID initiativeId, MultipartFile file) throws IOException {
try (InputStream input = file.getInputStream()) {
try {
ImageIO.read(input).toString();
String key = "InitiativeImages/" + initiativeId.toString();
FileStored fileUploaded = handleFileUpload(userId, key, file, initiativeId);
if (fileUploaded != null) {
return new PostResult("success", "image uploaded", fileUploaded.getId().toString());
}
return new PostResult("error", "error uploading image", "");
} catch (Exception e) {
// It's not an image.
return new PostResult("error", "only image files are supported", "");
}
}
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class FileService method uploadCardImage.
@Transactional
public PostResult uploadCardImage(UUID userId, UUID cardWrapperId, MultipartFile file) throws IOException {
try (InputStream input = file.getInputStream()) {
try {
ImageIO.read(input).toString();
Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
String key = "CardImages/" + cardWrapperId.toString();
FileStored fileUploaded = handleFileUpload(userId, key, file, initiative.getId());
if (fileUploaded != null) {
return new PostResult("success", "image uploaded", fileUploaded.getId().toString());
}
return new PostResult("error", "error uploading image", "");
} catch (Exception e) {
// It's not an image.
return new PostResult("error", "only image files are supported", "");
}
}
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class FilesController method uploadCardImage.
@RequestMapping(value = "/upload/cardImage/{cardWrapperId}", method = RequestMethod.POST)
@ResponseBody
public PostResult uploadCardImage(@PathVariable("cardWrapperId") String cardWrapperIdStr, @RequestParam("file") MultipartFile file) throws IOException {
if (getLoggedUser() == null) {
return new PostResult("error", "endpoint enabled users only", "");
}
UUID cardWrapperId = UUID.fromString(cardWrapperIdStr);
Initiative initiative = modelService.getCardWrapperInitiative(cardWrapperId);
if (governanceService.canEditModel(initiative.getId(), getLoggedUserId()) == DecisionVerdict.DENIED) {
return new PostResult("error", "not authorized", "");
}
return fileService.uploadCardImage(getLoggedUserId(), cardWrapperId, file);
}
Aggregations