diff --git a/src/main/java/plus/maa/backend/controller/CopilotSetController.java b/src/main/java/plus/maa/backend/controller/CopilotSetController.java index 2cbda723..66f6f3b5 100644 --- a/src/main/java/plus/maa/backend/controller/CopilotSetController.java +++ b/src/main/java/plus/maa/backend/controller/CopilotSetController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController; import plus.maa.backend.config.SpringDocConfig; import plus.maa.backend.config.security.AuthenticationHelper; +import plus.maa.backend.controller.request.CommonIdInput; import plus.maa.backend.controller.request.CopilotSetUpdateReq; import plus.maa.backend.controller.request.copilotset.CopilotSetModCopilotsReq; import plus.maa.backend.controller.request.copilotset.CopilotSetCreateReq; @@ -68,4 +69,14 @@ public MaaResult updateCopilotSet( return MaaResult.success(); } + @Operation(summary = "删除作业集") + @SecurityRequirement(name = SpringDocConfig.SECURITY_SCHEME_NAME) + @PostMapping("/delete") + public MaaResult deleteCopilotSet( + @Parameter(description = "删除作业集信息请求") @Valid @RequestBody CommonIdInput req) { + service.delete(req.getId(), helper.getUserId()); + return MaaResult.success(); + } + + } diff --git a/src/main/java/plus/maa/backend/controller/request/CommonIdInput.java b/src/main/java/plus/maa/backend/controller/request/CommonIdInput.java new file mode 100644 index 00000000..535608d3 --- /dev/null +++ b/src/main/java/plus/maa/backend/controller/request/CommonIdInput.java @@ -0,0 +1,18 @@ +package plus.maa.backend.controller.request; + +import jakarta.validation.constraints.NotNull; +import lombok.Getter; +import lombok.Setter; + +/** + * @author dragove + * create on 2024-01-05 + */ +@Getter +@Setter +public class CommonIdInput { + + @NotNull(message = "id必填") + private T id; + +} diff --git a/src/main/java/plus/maa/backend/repository/entity/CopilotSet.java b/src/main/java/plus/maa/backend/repository/entity/CopilotSet.java index 6ebe75b5..c43db05d 100644 --- a/src/main/java/plus/maa/backend/repository/entity/CopilotSet.java +++ b/src/main/java/plus/maa/backend/repository/entity/CopilotSet.java @@ -1,5 +1,6 @@ package plus.maa.backend.repository.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; import lombok.Data; @@ -71,4 +72,10 @@ public class CopilotSet implements Serializable, CopilotSetType { */ private CopilotSetStatus status; + @JsonIgnore + private boolean delete; + + @JsonIgnore + private LocalDateTime deleteTime; + } diff --git a/src/main/java/plus/maa/backend/service/CopilotSetService.java b/src/main/java/plus/maa/backend/service/CopilotSetService.java index 044de575..c2b9fc28 100644 --- a/src/main/java/plus/maa/backend/service/CopilotSetService.java +++ b/src/main/java/plus/maa/backend/service/CopilotSetService.java @@ -12,6 +12,7 @@ import plus.maa.backend.repository.CopilotSetRepository; import plus.maa.backend.repository.entity.CopilotSet; +import java.time.LocalDateTime; import java.util.HashSet; import java.util.Set; @@ -78,4 +79,19 @@ public void update(CopilotSetUpdateReq req, String userId) { copilotSet.setStatus(req.getStatus()); repository.save(copilotSet); } + + /** + * 删除作业集信息(逻辑删除,保留详情接口查询结果) + * @param id 作业集id + * @param userId 登陆用户id + */ + public void delete(long id, String userId) { + log.info("delete copilot set for id: {}, userId: {}", id, userId); + CopilotSet copilotSet = repository.findById(id) + .orElseThrow(() -> new IllegalArgumentException("作业集不存在")); + Assert.state(copilotSet.getCreatorId().equals(userId), "您不是该作业集的创建者,无权删除该作业集"); + copilotSet.setDelete(true); + copilotSet.setDeleteTime(LocalDateTime.now()); + repository.save(copilotSet); + } }