package com.red.circle.other.app.command.dynamic;

import com.red.circle.common.business.dto.cmd.IdLongCmd;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicTagCO;
import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicTag;
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicTagService;
import com.red.circle.other.inner.asserts.DynamicErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 获得动态标签.
 * </p>
 *
 * @author pengshigang
 * @since 2022-04-14
 */
@Component
@RequiredArgsConstructor
public class DynamicTagCmdExe {

  private final DynamicTagService dynamicTagService;

  public DynamicTagCO execute(IdLongCmd cmd) {

    DynamicTag tag = dynamicTagService.getById(cmd.getId());
    ResponseAssert.notNull(DynamicErrorCode.NO_RELATED_INFORMATION_FOUND, tag);

    return new DynamicTagCO()
        .setId(tag.getId())
        .setTag(tag.getTag())
        .setDesc(tag.getDescription())
        .setImageUrl(tag.getImageUrl());

  }

}
