Skip to content

Commit

Permalink
feat: 作业集详情接口
Browse files Browse the repository at this point in the history
  • Loading branch information
dragove committed Jan 6, 2024
1 parent ed4582a commit 688c2d6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,4 +28,6 @@ public interface CopilotSetConverter {
@Mapping(target = "creator", ignore = true)
CopilotSetListRes convert(CopilotSet copilotSet, String creator);

CopilotSetRes convertDetail(CopilotSet copilotSet, String creator);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class SecurityConfig {
"/arknights/level",
"/copilot/query",
"/set/query",
"/set/get",
"/copilot/get/**",
"/copilot/rating",
"/comments/query",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -43,6 +41,14 @@ public MaaResult<CopilotSetPageRes> querySets(
return MaaResult.success(service.query(req));
}

@Operation(summary = "查询作业集列表")
@ApiResponse(description = "作业集id")
@GetMapping("/get")
public MaaResult<CopilotSetRes> getSet(@RequestParam @Parameter(description = "作业id") long id) {
return MaaResult.success(service.get(id));
}


@Operation(summary = "创建作业集")
@ApiResponse(description = "作业集id")
@SecurityRequirement(name = SpringDocConfig.SECURITY_SCHEME_NAME)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/plus/maa/backend/repository/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,6 +21,8 @@ public interface UserRepository extends MongoRepository<MaaUser, String> {
*/
MaaUser findByEmail(String email);

Optional<MaaUser> findByUserId(String userId);

default Map<String, MaaUser> findByUsersId(List<String> userId) {
return findAllById(userId)
.stream().collect(Collectors.toMap(MaaUser::getUserId, Function.identity()));
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/plus/maa/backend/service/CopilotSetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("作业不存在"));
}
}

0 comments on commit 688c2d6

Please sign in to comment.