Skip to content

Commit

Permalink
Merge pull request #220 from cheng521521/main
Browse files Browse the repository at this point in the history
fix: add page function for get hiring list
  • Loading branch information
cheng521521 authored Mar 30, 2024
2 parents c802628 + add2b6b commit 964ea53
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
23 changes: 14 additions & 9 deletions src/main/java/com/dl/officialsite/admin/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public class AdminController {

private final BountyService bountyService;

public AdminController(MemberService memberService, TeamService teamService, HireService hireService,
public AdminController(MemberService memberService, TeamService teamService,
HireService hireService,
BountyService bountyService) {
this.memberService = memberService;
this.teamService = teamService;
Expand All @@ -51,13 +52,12 @@ public AdminController(MemberService memberService, TeamService teamService, Hir
}

/**
* freeze member
* //todo 查询member list把禁用的member filter out/ member不可登录
* freeze member //todo 查询member list把禁用的member filter out/ member不可登录
*/
@PutMapping("/member/freeze")
public BaseResponse freezeMember(@RequestParam String adminAddress,
@RequestParam String address) {
if (!teamService.checkMemberIsSuperAdmin(adminAddress)) {
if (!teamService.checkMemberIsAdmin(adminAddress)) {
throw new BizException(CodeEnums.NOT_THE_ADMIN);
}
memberService.freeze(address);
Expand All @@ -66,16 +66,20 @@ public BaseResponse freezeMember(@RequestParam String adminAddress,

@PostMapping("/hire/all")
public BaseResponse allHire(@RequestParam String adminAddress,
@RequestParam(defaultValue = "1") Integer pageNumber,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestBody HireSearchParams hireSearchParams) {
if (!teamService.checkMemberIsSuperAdmin(adminAddress)) {
if (!teamService.checkMemberIsAdmin(adminAddress)) {
throw new BizException(CodeEnums.NOT_THE_ADMIN);
}
return BaseResponse.successWithData(hireService.getAllHire(hireSearchParams));
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.DESC, "createTime"));
return BaseResponse.successWithData(hireService.getAllHire(hireSearchParams,pageable));
}

@DeleteMapping("/hire/delete")
public BaseResponse deleteHire(@RequestParam String adminAddress, @RequestParam Long hireId) {
if (!teamService.checkMemberIsSuperAdmin(adminAddress)) {
if (!teamService.checkMemberIsAdmin(adminAddress)) {
throw new BizException(CodeEnums.NOT_THE_ADMIN);
}
hireService.deleteHire(hireId);
Expand All @@ -87,10 +91,11 @@ public BaseResponse allBounty(@RequestParam String adminAddress,
@RequestParam(defaultValue = "1") Integer pageNumber,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestBody BountySearchVo bountySearchParams) {
if (!teamService.checkMemberIsSuperAdmin(adminAddress)) {
if (!teamService.checkMemberIsAdmin(adminAddress)) {
throw new BizException(CodeEnums.NOT_THE_ADMIN);
}
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize, Sort.by(Sort.Direction.DESC, "createTime"));
Pageable pageable = PageRequest.of(pageNumber - 1, pageSize,
Sort.by(Sort.Direction.DESC, "createTime"));
Page<BountyVo> page = bountyService.search(bountySearchParams, pageable);
return BaseResponse.successWithData(page);
}
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/com/dl/officialsite/hiring/HireService.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ public <T> Optional<Hiring> findById(Long hireId) {
return hireRepository.findById(hireId);
}

public Object getAllHire(HireSearchParams hireSearchParams) {
return hireRepository.findAll(((root, query, criteriaBuilder) -> {
public Page<HiringVO> getAllHire(HireSearchParams hireSearchParams, Pageable pageable) {
Page<Hiring> hiringPage = hireRepository.findAll(((root, query, criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.hasText(hireSearchParams.getCreator())) {
predicates.add(
Expand All @@ -301,8 +301,13 @@ public Object getAllHire(HireSearchParams hireSearchParams) {
"%" + hireSearchParams.getTitle() + "%"));
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
}));
}
}), pageable);
return hiringPage.map(hiring -> {
Map<Long, List<HiringSkillVO>> skillsMap = fetchSkillsMapByHiringIds(
Collections.singletonList(hiring.getId()));
return mapHiringToHiringVO(hiring, skillsMap);
});
};

public void deleteHire(Long hireId) {
Hiring hiring = hireRepository.findById(hireId)
Expand Down

0 comments on commit 964ea53

Please sign in to comment.