Skip to content

Commit 8640fd1

Browse files
authored
Merge pull request #559 from TaskFlow-CLAP/CLAP-428
CLAP-428 구분 추가시 이름 중복 검사 logic 추가
2 parents 3ab7468 + 7fc9560 commit 8640fd1

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

src/main/java/clap/server/adapter/outbound/persistense/LabelPersistenceAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public List<Label> findLabelList() {
3535
.collect(Collectors.toList());
3636
}
3737

38+
@Override
39+
public boolean existsByLabelName(String labelName) {
40+
return labelRepository.existsByLabelName(labelName);
41+
}
42+
3843
@Override
3944
public void save(Label label) {
4045
LabelEntity labelEntity = labelPersistenceMapper.toEntity(label);

src/main/java/clap/server/adapter/outbound/persistense/repository/task/LabelRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ public interface LabelRepository extends JpaRepository<LabelEntity, Long> {
1111

1212
List<LabelEntity> findByIsDeletedFalse();
1313

14+
boolean existsByLabelName(String labelName);
1415
}

src/main/java/clap/server/application/port/outbound/task/LoadLabelPort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ public interface LoadLabelPort {
1414

1515
List<Label> findLabelList();
1616

17-
18-
}
17+
boolean existsByLabelName(String labelName);
18+
}

src/main/java/clap/server/application/service/label/AddLabelService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import clap.server.application.port.inbound.label.AddLabelUsecase;
55
import clap.server.application.port.inbound.domain.MemberService;
66
import clap.server.application.port.outbound.task.CommandLabelPort;
7+
import clap.server.application.port.outbound.task.LoadLabelPort;
78
import clap.server.common.annotation.architecture.ApplicationService;
89
import clap.server.domain.model.member.Member;
910
import clap.server.domain.model.task.Label;
11+
import clap.server.exception.ApplicationException;
12+
import clap.server.exception.code.LabelErrorCode;
1013
import lombok.RequiredArgsConstructor;
1114
import org.springframework.transaction.annotation.Transactional;
1215

@@ -15,12 +18,16 @@
1518
public class AddLabelService implements AddLabelUsecase {
1619

1720
private final MemberService memberService;
21+
private final LoadLabelPort loadLabelPort;
1822
private final CommandLabelPort commandLabelPort;
1923

2024
@Transactional
2125
@Override
2226
public void addLabel(Long adminId, CreateLabelRequest request) {
2327
Member admin = memberService.findActiveMember(adminId);
28+
if (loadLabelPort.existsByLabelName(request.labelName())) {
29+
throw new ApplicationException(LabelErrorCode.DUPLICATE_LABEL_NAME);
30+
}
2431
Label label = Label.addLabel(admin, request.labelName(), request.labelColor());
2532
commandLabelPort.save(label);
2633
}

src/main/java/clap/server/exception/code/LabelErrorCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
@Getter
88
@RequiredArgsConstructor
99
public enum LabelErrorCode implements BaseErrorCode{
10-
LABEL_NOT_FOUND(HttpStatus.NOT_FOUND, "LABEL_001", "작업 구분을 찾을 수 없습니다.");
10+
LABEL_NOT_FOUND(HttpStatus.NOT_FOUND, "LABEL_001", "작업 구분을 찾을 수 없습니다."),
11+
DUPLICATE_LABEL_NAME(HttpStatus.BAD_REQUEST, "LABEL_002", "중복된 구분 이름입니다.");
1112

1213

1314
private final HttpStatus httpStatus;

0 commit comments

Comments
 (0)