Skip to content

Commit e6c5338

Browse files
committed
CLAP-175 Feat: 구분 수정 API 구현
1 parent 8fe4af7 commit e6c5338

File tree

7 files changed

+68
-13
lines changed

7 files changed

+68
-13
lines changed
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package clap.server.adapter.inbound.web.admin;
22

33
import clap.server.adapter.inbound.security.SecurityUserDetails;
4-
import clap.server.adapter.inbound.web.dto.label.AddLabelRequest;
4+
import clap.server.adapter.inbound.web.dto.label.AddAndEditLabelRequest;
55
import clap.server.application.port.inbound.admin.AddLabelUsecase;
6+
import clap.server.application.port.inbound.admin.UpdateLabelUsecase;
67
import clap.server.common.annotation.architecture.WebAdapter;
78
import io.swagger.v3.oas.annotations.Operation;
89
import io.swagger.v3.oas.annotations.tags.Tag;
910
import lombok.RequiredArgsConstructor;
1011
import org.springframework.security.access.annotation.Secured;
1112
import org.springframework.security.core.annotation.AuthenticationPrincipal;
12-
import org.springframework.web.bind.annotation.PostMapping;
13-
import org.springframework.web.bind.annotation.RequestBody;
14-
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.bind.annotation.*;
1514

1615
@Tag(name = "05. Admin")
1716
@WebAdapter
@@ -20,12 +19,23 @@
2019
public class UpdateLabelController {
2120

2221
private final AddLabelUsecase addLabelUsecase;
22+
private final UpdateLabelUsecase updateLabelUsecase;
2323

2424
@Operation(summary = "구분(label) 추가 API")
2525
@PostMapping
2626
@Secured({"ROLE_ADMIN"})
2727
public void addLabel(@AuthenticationPrincipal SecurityUserDetails userInfo,
28-
@RequestBody AddLabelRequest request) {
28+
@RequestBody AddAndEditLabelRequest request) {
2929
addLabelUsecase.addLabel(userInfo.getUserId(), request);
3030
}
31+
32+
@Operation(summary = "구분(label) 수정 API")
33+
@PatchMapping("/{labelId}")
34+
@Secured({"ROLE_ADMIN"})
35+
public void updateLabel(@AuthenticationPrincipal SecurityUserDetails userInfo,
36+
@PathVariable Long labelId,
37+
@RequestBody AddAndEditLabelRequest request) {
38+
updateLabelUsecase.editLabel(userInfo.getUserId(), labelId, request);
39+
40+
}
3141
}

src/main/java/clap/server/adapter/inbound/web/dto/label/AddLabelRequest.java renamed to src/main/java/clap/server/adapter/inbound/web/dto/label/AddAndEditLabelRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import clap.server.adapter.outbound.persistense.entity.task.constant.LabelColor;
44

5-
public record AddLabelRequest(
5+
public record AddAndEditLabelRequest(
66

77
String labelName,
88
LabelColor labelColor
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package clap.server.application.port.inbound.admin;
22

3-
import clap.server.adapter.inbound.web.dto.label.AddLabelRequest;
3+
import clap.server.adapter.inbound.web.dto.label.AddAndEditLabelRequest;
44

55
public interface AddLabelUsecase {
66

7-
void addLabel(Long adminId, AddLabelRequest request);
7+
void addLabel(Long adminId, AddAndEditLabelRequest request);
88

99

1010
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package clap.server.application.port.inbound.admin;
2+
3+
import clap.server.adapter.inbound.web.dto.label.AddAndEditLabelRequest;
4+
5+
public interface UpdateLabelUsecase {
6+
void editLabel(Long adminId, Long labelId, AddAndEditLabelRequest request);
7+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package clap.server.application.service.label;
22

3-
import clap.server.adapter.inbound.web.dto.label.AddLabelRequest;
3+
import clap.server.adapter.inbound.web.dto.label.AddAndEditLabelRequest;
44
import clap.server.application.port.inbound.admin.AddLabelUsecase;
55
import clap.server.application.port.inbound.domain.MemberService;
66
import clap.server.application.port.outbound.task.CommandLabelPort;
@@ -19,7 +19,7 @@ public class AddLabelService implements AddLabelUsecase {
1919

2020
@Transactional
2121
@Override
22-
public void addLabel(Long adminId, AddLabelRequest request) {
22+
public void addLabel(Long adminId, AddAndEditLabelRequest request) {
2323
Member admin = memberService.findActiveMember(adminId);
2424
Label label = Label.addLabel(admin, request);
2525
commandLabelPort.save(label);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package clap.server.application.service.label;
2+
3+
import clap.server.adapter.inbound.web.dto.label.AddAndEditLabelRequest;
4+
import clap.server.application.port.inbound.admin.UpdateLabelUsecase;
5+
import clap.server.application.port.inbound.domain.MemberService;
6+
import clap.server.application.port.outbound.task.CommandLabelPort;
7+
import clap.server.application.port.outbound.task.LoadLabelPort;
8+
import clap.server.common.annotation.architecture.ApplicationService;
9+
import clap.server.domain.model.task.Label;
10+
import clap.server.exception.ApplicationException;
11+
import clap.server.exception.code.LabelErrorCode;
12+
import lombok.RequiredArgsConstructor;
13+
import org.springframework.transaction.annotation.Transactional;
14+
15+
@ApplicationService
16+
@RequiredArgsConstructor
17+
public class UpdateLabelService implements UpdateLabelUsecase {
18+
19+
private final MemberService memberService;
20+
private final LoadLabelPort loadLabelPort;
21+
private final CommandLabelPort commandLabelPort;
22+
23+
@Transactional
24+
@Override
25+
public void editLabel(Long adminId, Long labelId, AddAndEditLabelRequest request) {
26+
memberService.findActiveMember(adminId);
27+
28+
Label label = loadLabelPort.findById(labelId)
29+
.orElseThrow(() -> new ApplicationException(LabelErrorCode.LABEL_NOT_FOUND));
30+
31+
label.updateLabel(request);
32+
commandLabelPort.save(label);
33+
}
34+
}

src/main/java/clap/server/domain/model/task/Label.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package clap.server.domain.model.task;
22

3-
import clap.server.adapter.inbound.web.dto.label.AddLabelRequest;
3+
import clap.server.adapter.inbound.web.dto.label.AddAndEditLabelRequest;
44
import clap.server.adapter.outbound.persistense.entity.task.constant.LabelColor;
5-
import clap.server.adapter.outbound.persistense.entity.task.constant.TaskStatus;
65
import clap.server.domain.model.common.BaseTime;
76
import clap.server.domain.model.member.Member;
87
import lombok.AccessLevel;
@@ -20,12 +19,17 @@ public class Label extends BaseTime {
2019
private LabelColor labelColor;
2120
private boolean isDeleted;
2221

23-
public static Label addLabel(Member admin, AddLabelRequest request) {
22+
public static Label addLabel(Member admin, AddAndEditLabelRequest request) {
2423
return Label.builder()
2524
.admin(admin)
2625
.labelName(request.labelName())
2726
.labelColor(request.labelColor())
2827
.isDeleted(false)
2928
.build();
3029
}
30+
31+
public void updateLabel(AddAndEditLabelRequest request) {
32+
this.labelName = request.labelName();
33+
this.labelColor = request.labelColor();
34+
}
3135
}

0 commit comments

Comments
 (0)