Skip to content

Commit

Permalink
feat: 添加作业集删除接口
Browse files Browse the repository at this point in the history
  • Loading branch information
dragove committed Jan 5, 2024
1 parent 999c4b6 commit e434f97
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,4 +69,14 @@ public MaaResult<Void> updateCopilotSet(
return MaaResult.success();
}

@Operation(summary = "删除作业集")
@SecurityRequirement(name = SpringDocConfig.SECURITY_SCHEME_NAME)
@PostMapping("/delete")
public MaaResult<Void> deleteCopilotSet(
@Parameter(description = "删除作业集信息请求") @Valid @RequestBody CommonIdInput<Long> req) {
service.delete(req.getId(), helper.getUserId());
return MaaResult.success();
}


}
Original file line number Diff line number Diff line change
@@ -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<T> {

@NotNull(message = "id必填")
private T id;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -71,4 +72,10 @@ public class CopilotSet implements Serializable, CopilotSetType {
*/
private CopilotSetStatus status;

@JsonIgnore
private boolean delete;

@JsonIgnore
private LocalDateTime deleteTime;

}
16 changes: 16 additions & 0 deletions src/main/java/plus/maa/backend/service/CopilotSetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}

0 comments on commit e434f97

Please sign in to comment.