use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class ModelController method addExistingCard.
@RequestMapping(path = "/initiative/{initiativeId}/model/section/{sectionId}/cardWrapper/{cardWrapperId}", method = RequestMethod.PUT)
public PostResult addExistingCard(@PathVariable("initiativeId") String initiativeIdStr, @PathVariable("sectionId") String sectionIdStr, @PathVariable("cardWrapperId") String cardWrapperIdStr, @RequestParam(name = "beforeCardWrapperId", defaultValue = "") String beforeCardWrapperIdStr) {
if (getLoggedUser() == null) {
return new PostResult("error", "endpoint enabled users only", null);
}
UUID initiativeId = UUID.fromString(initiativeIdStr);
if (governanceService.canEditModel(initiativeId, getLoggedUser().getC1Id()) == DecisionVerdict.DENIED) {
return new PostResult("error", "not authorized", "");
}
UUID beforeCardWrapperId = beforeCardWrapperIdStr.equals("") ? null : UUID.fromString(beforeCardWrapperIdStr);
return modelService.addCardToSection(UUID.fromString(sectionIdStr), UUID.fromString(cardWrapperIdStr), beforeCardWrapperId, getLoggedUserId());
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method createSection.
@Transactional
public PostResult createSection(ModelSectionDto sectionDto, UUID parentSectionId, UUID parentViewId, UUID creatorId, boolean register) {
ModelSection section = sectionDto.toEntity(null, sectionDto);
section = modelSectionRepository.save(section);
if (parentSectionId != null) {
ModelSection parent = modelSectionRepository.findById(parentSectionId);
if (parent == null)
return new PostResult("error", "parent section not found", "");
parent.getSubsections().add(section);
section.setInitiative(parent.getInitiative());
if (register)
activityService.modelSectionCreatedOnSection(section, parent, appUserRepository.findByC1Id(creatorId));
modelSectionRepository.save(parent);
} else {
ModelView view = modelViewRepository.findById(parentViewId);
if (view == null)
return new PostResult("error", "view not found", "");
view.getSections().add(section);
section.setInitiative(view.getInitiative());
if (register)
activityService.modelSectionCreatedOnView(section, view, appUserRepository.findByC1Id(creatorId));
modelViewRepository.save(view);
}
return new PostResult("success", "section created", section.getId().toString());
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method createView.
@Transactional
public PostResult createView(UUID initiativeId, ModelViewDto viewDto, UUID creatorId, boolean register) {
Initiative initiative = initiativeRepository.findById(initiativeId);
if (initiative == null)
return new PostResult("error", "initiative not found", "");
ModelView view = viewDto.toEntity(null, viewDto, initiative);
view = modelViewRepository.save(view);
initiative.getModelViews().add(view);
initiativeRepository.save(initiative);
if (register)
activityService.modelViewCreated(view, appUserRepository.findByC1Id(creatorId));
return new PostResult("success", "view created", view.getId().toString());
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method setLikeToCard.
@Transactional
public PostResult setLikeToCard(UUID cardWrapperId, UUID authorId, boolean likeStatus) {
ModelCardWrapper card = modelCardWrapperRepository.findById(cardWrapperId);
AppUser author = appUserRepository.findByC1Id(authorId);
CardLike like = cardLikeRepository.findByCardWrapperIdAndAuthor_c1Id(cardWrapperId, authorId);
/* add the like*/
if (likeStatus == true) {
if (like == null) {
like = new CardLike();
like.setAuthor(author);
like.setCardWrapper(card);
cardLikeRepository.save(like);
} else {
/* nothing to do, the like is already registered */
}
} else {
if (like != null) {
cardLikeRepository.delete(like);
} else {
/* nothing to do, the like is already absent */
}
}
return new PostResult("success", "like status changed", null);
}
use of org.collectiveone.common.dto.PostResult in project CollectiveOneWebapp by CollectiveOne.
the class ModelService method moveView.
@Transactional
public PostResult moveView(UUID initiativeId, UUID viewId, UUID onViewId, UUID creatorId) {
if (onViewId.equals(viewId)) {
return new PostResult("warning", "cannot move on itself", null);
}
Initiative initiative = initiativeRepository.findById(initiativeId);
ModelView view = modelViewRepository.findById(viewId);
ModelView beforeView = modelViewRepository.findById(onViewId);
int index = initiative.getModelViews().indexOf(beforeView);
initiative.getModelViews().remove(view);
initiativeRepository.save(initiative);
initiative.getModelViews().add(index, view);
activityService.modelViewMoved(view, appUserRepository.findByC1Id(creatorId));
modelViewRepository.save(view);
initiativeRepository.save(initiative);
return new PostResult("success", "view moved", view.getId().toString());
}
Aggregations