Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public List<Label> findLabelList() {
.collect(Collectors.toList());
}

@Override
public boolean existsByLabelName(String labelName) {
return labelRepository.existsByLabelName(labelName);
}

@Override
public void save(Label label) {
LabelEntity labelEntity = labelPersistenceMapper.toEntity(label);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface LabelRepository extends JpaRepository<LabelEntity, Long> {

List<LabelEntity> findByIsDeletedFalse();

boolean existsByLabelName(String labelName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface LoadLabelPort {

List<Label> findLabelList();


}
boolean existsByLabelName(String labelName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import clap.server.application.port.inbound.label.AddLabelUsecase;
import clap.server.application.port.inbound.domain.MemberService;
import clap.server.application.port.outbound.task.CommandLabelPort;
import clap.server.application.port.outbound.task.LoadLabelPort;
import clap.server.common.annotation.architecture.ApplicationService;
import clap.server.domain.model.member.Member;
import clap.server.domain.model.task.Label;
import clap.server.exception.ApplicationException;
import clap.server.exception.code.LabelErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -15,12 +18,16 @@
public class AddLabelService implements AddLabelUsecase {

private final MemberService memberService;
private final LoadLabelPort loadLabelPort;
private final CommandLabelPort commandLabelPort;

@Transactional
@Override
public void addLabel(Long adminId, CreateLabelRequest request) {
Member admin = memberService.findActiveMember(adminId);
if (loadLabelPort.existsByLabelName(request.labelName())) {
throw new ApplicationException(LabelErrorCode.DUPLICATE_LABEL_NAME);
}
Label label = Label.addLabel(admin, request.labelName(), request.labelColor());
commandLabelPort.save(label);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/clap/server/exception/code/LabelErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@Getter
@RequiredArgsConstructor
public enum LabelErrorCode implements BaseErrorCode{
LABEL_NOT_FOUND(HttpStatus.NOT_FOUND, "LABEL_001", "작업 구분을 찾을 수 없습니다.");
LABEL_NOT_FOUND(HttpStatus.NOT_FOUND, "LABEL_001", "작업 구분을 찾을 수 없습니다."),
DUPLICATE_LABEL_NAME(HttpStatus.BAD_REQUEST, "LABEL_002", "중복된 구분 이름입니다.");


private final HttpStatus httpStatus;
Expand Down
Loading