Search in sources :

Example 46 with PostResult

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);
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) UUID(java.util.UUID) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 47 with PostResult

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, "");
    }
}
Also used : PostResult(org.collectiveone.common.dto.PostResult) AppUser(org.collectiveone.modules.users.AppUser) Member(org.collectiveone.modules.initiatives.Member) Transactional(javax.transaction.Transactional)

Aggregations

PostResult (org.collectiveone.common.dto.PostResult)47 Transactional (javax.transaction.Transactional)28 UUID (java.util.UUID)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 Initiative (org.collectiveone.modules.initiatives.Initiative)11 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)7 DecisionVerdict (org.collectiveone.modules.governance.DecisionVerdict)5 AppUser (org.collectiveone.modules.users.AppUser)5 Timestamp (java.sql.Timestamp)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 FileStored (org.collectiveone.modules.files.FileStored)3 TokenType (org.collectiveone.modules.tokens.TokenType)3 DecisionMaker (org.collectiveone.modules.governance.DecisionMaker)2 ModelSectionDto (org.collectiveone.modules.model.dto.ModelSectionDto)2 TokenMint (org.collectiveone.modules.tokens.TokenMint)2 ArrayList (java.util.ArrayList)1 WantToContributeNotification (org.collectiveone.modules.activity.WantToContributeNotification)1 BillDto (org.collectiveone.modules.assignations.dto.BillDto)1 EvaluationGradeDto (org.collectiveone.modules.assignations.dto.EvaluationGradeDto)1