Search in sources :

Example 1 with ModelCardWrapperDto

use of org.collectiveone.modules.model.dto.ModelCardWrapperDto in project CollectiveOneWebapp by CollectiveOne.

the class ModelCardWrapper method toDto.

public ModelCardWrapperDto toDto() {
    ModelCardWrapperDto cardWrapperDto = new ModelCardWrapperDto();
    cardWrapperDto.setId(id.toString());
    cardWrapperDto.setCard(card.toDto());
    cardWrapperDto.setStateControl(stateControl);
    if (state != null)
        cardWrapperDto.setState(state.toString());
    if (initiative != null)
        cardWrapperDto.setInitiativeId(initiative.getId().toString());
    if (targetDate != null)
        cardWrapperDto.setTargetDate(targetDate.getTime());
    return cardWrapperDto;
}
Also used : ModelCardWrapperDto(org.collectiveone.modules.model.dto.ModelCardWrapperDto)

Example 2 with ModelCardWrapperDto

use of org.collectiveone.modules.model.dto.ModelCardWrapperDto in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method addSectionSubElements.

@Transactional
public ModelSectionDto addSectionSubElements(ModelSectionDto sectionDto, UUID sectionId, Integer level, UUID requestByUserId) {
    ModelSection section = modelSectionRepository.findById(sectionId);
    if (level >= 1) {
        sectionDto.setSubElementsLoaded(true);
        for (ModelCardWrapper cardWrapper : section.getCardsWrappers()) {
            ModelCardWrapperDto cardWrapperDto = cardWrapper.toDto();
            cardWrapperDto.setnLikes(cardLikeRepository.countOfCard(cardWrapper.getId()));
            if (requestByUserId != null) {
                cardWrapperDto.setUserLiked(cardLikeRepository.findByCardWrapperIdAndAuthor_c1Id(cardWrapper.getId(), requestByUserId) != null);
            }
            List<ModelSection> inSections = modelCardWrapperRepository.findParentSections(cardWrapper.getId());
            for (ModelSection inSection : inSections) {
                cardWrapperDto.getInSections().add(inSection.toDto());
            }
            sectionDto.getCardsWrappers().add(cardWrapperDto);
        }
        for (ModelSection subsection : section.getSubsections()) {
            sectionDto.getSubsections().add(addSectionSubElements(subsection.toDto(), subsection.getId(), level - 1, requestByUserId));
        }
    } else {
        sectionDto.setSubElementsLoaded(false);
    }
    return sectionDto;
}
Also used : ModelCardWrapperDto(org.collectiveone.modules.model.dto.ModelCardWrapperDto) Transactional(javax.transaction.Transactional)

Example 3 with ModelCardWrapperDto

use of org.collectiveone.modules.model.dto.ModelCardWrapperDto in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method searchCardWrapper.

@Transactional
public GetResult<Page<ModelCardWrapperDto>> searchCardWrapper(String query, PageRequest page, UUID initiativeId) {
    List<UUID> initiativeEcosystemIds = initiativeService.findAllInitiativeEcosystemIds(initiativeId);
    Page<ModelCardWrapper> enititiesPage = modelCardWrapperRepository.searchBy("%" + query.toLowerCase() + "%", initiativeEcosystemIds, page);
    List<ModelCardWrapperDto> cardsDtos = new ArrayList<ModelCardWrapperDto>();
    for (ModelCardWrapper cardWrapper : enititiesPage.getContent()) {
        List<ModelSection> inSections = modelCardWrapperRepository.findParentSections(cardWrapper.getId());
        ModelCardWrapperDto cardWrapperDto = cardWrapper.toDto();
        for (ModelSection section : inSections) {
            cardWrapperDto.getInSections().add(section.toDto());
        }
        cardsDtos.add(cardWrapperDto);
    }
    Page<ModelCardWrapperDto> dtosPage = new PageImpl<ModelCardWrapperDto>(cardsDtos, page, enititiesPage.getNumberOfElements());
    return new GetResult<Page<ModelCardWrapperDto>>("succes", "cards returned", dtosPage);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) GetResult(org.collectiveone.common.dto.GetResult) ArrayList(java.util.ArrayList) UUID(java.util.UUID) ModelCardWrapperDto(org.collectiveone.modules.model.dto.ModelCardWrapperDto) Transactional(javax.transaction.Transactional)

Example 4 with ModelCardWrapperDto

use of org.collectiveone.modules.model.dto.ModelCardWrapperDto in project CollectiveOneWebapp by CollectiveOne.

the class ModelService method getCardWrapper.

@Transactional
public GetResult<ModelCardWrapperDto> getCardWrapper(UUID cardWrapperId, UUID requestByUserId) {
    ModelCardWrapper cardWrapper = modelCardWrapperRepository.findById(cardWrapperId);
    List<ModelSection> inSections = modelCardWrapperRepository.findParentSections(cardWrapper.getId());
    ModelCardWrapperDto cardWrapperDto = cardWrapper.toDto();
    cardWrapperDto.setnLikes(cardLikeRepository.countOfCard(cardWrapper.getId()));
    if (requestByUserId != null) {
        cardWrapperDto.setUserLiked(cardLikeRepository.findByCardWrapperIdAndAuthor_c1Id(cardWrapper.getId(), requestByUserId) != null);
    }
    for (ModelSection section : inSections) {
        cardWrapperDto.getInSections().add(section.toDto());
    }
    return new GetResult<ModelCardWrapperDto>("success", "card retrieved", cardWrapperDto);
}
Also used : GetResult(org.collectiveone.common.dto.GetResult) ModelCardWrapperDto(org.collectiveone.modules.model.dto.ModelCardWrapperDto) Transactional(javax.transaction.Transactional)

Aggregations

ModelCardWrapperDto (org.collectiveone.modules.model.dto.ModelCardWrapperDto)4 Transactional (javax.transaction.Transactional)3 GetResult (org.collectiveone.common.dto.GetResult)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 PageImpl (org.springframework.data.domain.PageImpl)1