use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class MessagesController method postMessage.
/* creates a new message (context type + element id are used as the identifier of the location of the message) */
@RequestMapping(path = "/messages/{contextElementType}/{contextElementId}", method = RequestMethod.POST)
public PostResult postMessage(@PathVariable("contextElementType") String contextElementTypeStr, @PathVariable("contextElementId") String contextElementIdStr, @RequestBody MessageDto messageDto) {
if (getLoggedUser() == null) {
return new PostResult("error", "endpoint enabled users only", null);
}
MessageThreadContextType contextType = MessageThreadContextType.valueOf(contextElementTypeStr);
UUID elementId = UUID.fromString(contextElementIdStr);
UUID initiativeId = messageService.getInitiativeIdOfMessage(contextType, elementId);
/* Permission to comment is default to ecosystem for now */
if (!initiativeService.isMemberOfEcosystem(initiativeId, getLoggedUserId())) {
return new PostResult("error", "not authorized", "");
}
return messageService.postMessage(messageDto, getLoggedUserId(), contextType, elementId);
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class TokenTransferService method transferFromInitiativeToUser.
@Transactional
public PostResult transferFromInitiativeToUser(UUID initiativeId, UUID receiverId, UUID assetId, double value) {
AppUser receiver = appUserRepository.findByC1Id(receiverId);
TokenType tokenType = tokenService.getTokenType(assetId);
String result = tokenService.transfer(tokenType.getId(), initiativeId, receiver.getC1Id(), value, TokenHolderType.USER);
if (result.equals("success")) {
/* register the transfer to the contributor */
Member member = initiativeService.getOrAddMember(initiativeId, receiver.getC1Id());
MemberTransfer thisTransfer = new MemberTransfer();
thisTransfer.setMember(member);
thisTransfer.setTokenType(tokenType);
thisTransfer.setValue(value);
thisTransfer.setStatus(MemberTransferStatus.DONE);
thisTransfer = memberTransferRepository.save(thisTransfer);
member.getTokensTransfers().add(thisTransfer);
memberRepository.save(member);
return new PostResult("success", "assets transferred successfully", thisTransfer.getId().toString());
} else {
return new PostResult("error", "error transferring assets: " + result, "");
}
}
Aggregations