diff --git a/src/main/java/plus/maa/backend/common/utils/converter/CopilotSetConverter.java b/src/main/java/plus/maa/backend/common/utils/converter/CopilotSetConverter.java index 81d03374..3057af84 100644 --- a/src/main/java/plus/maa/backend/common/utils/converter/CopilotSetConverter.java +++ b/src/main/java/plus/maa/backend/common/utils/converter/CopilotSetConverter.java @@ -3,6 +3,7 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import plus.maa.backend.controller.request.copilotset.CopilotSetCreateReq; +import plus.maa.backend.controller.response.CopilotSetRes; import plus.maa.backend.controller.response.user.CopilotSetListRes; import plus.maa.backend.repository.entity.CopilotSet; @@ -27,4 +28,6 @@ public interface CopilotSetConverter { @Mapping(target = "creator", ignore = true) CopilotSetListRes convert(CopilotSet copilotSet, String creator); + CopilotSetRes convertDetail(CopilotSet copilotSet, String creator); + } diff --git a/src/main/java/plus/maa/backend/config/security/SecurityConfig.java b/src/main/java/plus/maa/backend/config/security/SecurityConfig.java index 4850a402..43466348 100644 --- a/src/main/java/plus/maa/backend/config/security/SecurityConfig.java +++ b/src/main/java/plus/maa/backend/config/security/SecurityConfig.java @@ -43,6 +43,7 @@ public class SecurityConfig { "/arknights/level", "/copilot/query", "/set/query", + "/set/get", "/copilot/get/**", "/copilot/rating", "/comments/query", diff --git a/src/main/java/plus/maa/backend/controller/CopilotSetController.java b/src/main/java/plus/maa/backend/controller/CopilotSetController.java index bb3235d0..015b7fdc 100644 --- a/src/main/java/plus/maa/backend/controller/CopilotSetController.java +++ b/src/main/java/plus/maa/backend/controller/CopilotSetController.java @@ -7,18 +7,16 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import plus.maa.backend.config.SpringDocConfig; import plus.maa.backend.config.security.AuthenticationHelper; import plus.maa.backend.controller.request.CommonIdReq; import plus.maa.backend.controller.request.CopilotSetQuery; import plus.maa.backend.controller.request.CopilotSetUpdateReq; -import plus.maa.backend.controller.request.copilotset.CopilotSetModCopilotsReq; import plus.maa.backend.controller.request.copilotset.CopilotSetCreateReq; +import plus.maa.backend.controller.request.copilotset.CopilotSetModCopilotsReq; import plus.maa.backend.controller.response.CopilotSetPageRes; +import plus.maa.backend.controller.response.CopilotSetRes; import plus.maa.backend.controller.response.MaaResult; import plus.maa.backend.service.CopilotSetService; @@ -43,6 +41,14 @@ public MaaResult querySets( return MaaResult.success(service.query(req)); } + @Operation(summary = "查询作业集列表") + @ApiResponse(description = "作业集id") + @GetMapping("/get") + public MaaResult getSet(@RequestParam @Parameter(description = "作业id") long id) { + return MaaResult.success(service.get(id)); + } + + @Operation(summary = "创建作业集") @ApiResponse(description = "作业集id") @SecurityRequirement(name = SpringDocConfig.SECURITY_SCHEME_NAME) diff --git a/src/main/java/plus/maa/backend/repository/UserRepository.java b/src/main/java/plus/maa/backend/repository/UserRepository.java index 35112d39..d9a4fde5 100644 --- a/src/main/java/plus/maa/backend/repository/UserRepository.java +++ b/src/main/java/plus/maa/backend/repository/UserRepository.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -20,6 +21,8 @@ public interface UserRepository extends MongoRepository { */ MaaUser findByEmail(String email); + Optional findByUserId(String userId); + default Map findByUsersId(List userId) { return findAllById(userId) .stream().collect(Collectors.toMap(MaaUser::getUserId, Function.identity())); diff --git a/src/main/java/plus/maa/backend/service/CopilotSetService.java b/src/main/java/plus/maa/backend/service/CopilotSetService.java index 9518f81f..84cda80a 100644 --- a/src/main/java/plus/maa/backend/service/CopilotSetService.java +++ b/src/main/java/plus/maa/backend/service/CopilotSetService.java @@ -15,6 +15,7 @@ import plus.maa.backend.controller.request.copilotset.CopilotSetCreateReq; import plus.maa.backend.controller.request.copilotset.CopilotSetModCopilotsReq; import plus.maa.backend.controller.response.CopilotSetPageRes; +import plus.maa.backend.controller.response.CopilotSetRes; import plus.maa.backend.repository.CopilotSetRepository; import plus.maa.backend.repository.UserRepository; import plus.maa.backend.repository.entity.CopilotSet; @@ -132,4 +133,11 @@ public CopilotSetPageRes query(CopilotSetQuery req) { }).toList()); } + + public CopilotSetRes get(long id) { + return repository.findById(id).map($ -> { + String userName = userRepository.findByUserId($.getCreatorId()).orElse(MaaUser.UNKNOWN).getUserName(); + return converter.convertDetail($, userName); + }).orElseThrow(() -> new IllegalArgumentException("作业不存在")); + } }