|
|
@@ -1,8 +1,10 @@
|
|
|
package com.finikes.oc.vote.controller;
|
|
|
|
|
|
import com.finikes.oc.vote.ApiResponse;
|
|
|
+import com.finikes.oc.vote.dao.VoteActivityDao;
|
|
|
import com.finikes.oc.vote.dto.*;
|
|
|
import com.finikes.oc.vote.service.VoteService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
@@ -17,6 +19,9 @@ public class VoteController {
|
|
|
|
|
|
private final VoteService voteService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private VoteActivityDao voteActivityDao;
|
|
|
+
|
|
|
public VoteController(VoteService voteService) {
|
|
|
this.voteService = voteService;
|
|
|
}
|
|
|
@@ -27,7 +32,7 @@ public class VoteController {
|
|
|
* @param dto 投票活动创建数据传输对象
|
|
|
* @return 接口返回对象
|
|
|
*/
|
|
|
- @PutMapping("vote_activity/")
|
|
|
+ @PutMapping("/vote_activity")
|
|
|
public ApiResponse<Integer> createVoteActivity(@RequestBody @Valid VoteActivityCreateDto dto) {
|
|
|
int voteActivityId = voteService.createVoteActivity(dto);
|
|
|
return ApiResponse.successful(voteActivityId);
|
|
|
@@ -39,7 +44,7 @@ public class VoteController {
|
|
|
* @param dto 投票活动创建数据传输对象
|
|
|
* @return 接口返回对象
|
|
|
*/
|
|
|
- @PostMapping("vote_activity/")
|
|
|
+ @PostMapping("/vote_activity")
|
|
|
public ApiResponse<Integer> updateVoteActivity(@RequestBody @Valid VoteActivityUpdateDto dto) {
|
|
|
voteService.updateVoteActivity(dto);
|
|
|
return ApiResponse.successful();
|
|
|
@@ -55,8 +60,8 @@ public class VoteController {
|
|
|
* @param endTime 结束时间
|
|
|
* @return 接口返回对象
|
|
|
*/
|
|
|
- @GetMapping("vote_activities/section/")
|
|
|
- public ApiResponse<List<VoteActivityViewDto>> searchVoteActivity(
|
|
|
+ @GetMapping("/vote_activities/section")
|
|
|
+ public ApiResponse<VoteActivitiesSearchResponse> searchVoteActivity(
|
|
|
@RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
|
|
|
@RequestParam(value = "pageCapacity", defaultValue = "10") int pageCapacity,
|
|
|
@RequestParam(value = "key", required = false) String key,
|
|
|
@@ -70,7 +75,24 @@ public class VoteController {
|
|
|
dto.setEndTime(endTime);
|
|
|
|
|
|
List<VoteActivityViewDto> list = voteService.searchVoteActivity(dto);
|
|
|
- return ApiResponse.successful(list);
|
|
|
+
|
|
|
+ int count = 0;
|
|
|
+ if (dto.getStartTime() == null || dto.getEndTime() == null) {
|
|
|
+ count = voteActivityDao.countByTitleAndStartTimeAndEndTime(dto.getKey(),
|
|
|
+ null, null);
|
|
|
+ } else {
|
|
|
+ count = voteActivityDao.countByTitleAndStartTimeAndEndTime(dto.getKey(),
|
|
|
+ dto.getStartTime().getTime(), dto.getEndTime().getTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ int pageQuantity = count / pageCapacity;
|
|
|
+ if (count % pageCapacity > 0) {
|
|
|
+ pageQuantity++;
|
|
|
+ }
|
|
|
+ VoteActivitiesSearchResponse response = new VoteActivitiesSearchResponse();
|
|
|
+ response.setPageQuantity(pageQuantity);
|
|
|
+ response.setVoteActivityViewDtos(list);
|
|
|
+ return ApiResponse.successful(response);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -79,7 +101,7 @@ public class VoteController {
|
|
|
* @param dto 投票创建数据传输对象
|
|
|
* @return 接口返回对象
|
|
|
*/
|
|
|
- @PutMapping("vote/")
|
|
|
+ @PutMapping("/vote")
|
|
|
public ApiResponse<Integer> createVote(@RequestBody @Valid VoteCreateDto dto) {
|
|
|
int voteId = voteService.createVote(dto);
|
|
|
return ApiResponse.successful(voteId);
|
|
|
@@ -91,7 +113,7 @@ public class VoteController {
|
|
|
* @param dto 投票更新数据传输对象
|
|
|
* @return 接口返回对象
|
|
|
*/
|
|
|
- @PostMapping("vote/")
|
|
|
+ @PostMapping("/vote")
|
|
|
public ApiResponse<Integer> createVote(@RequestBody @Valid VoteUpdateDto dto) {
|
|
|
voteService.updateVote(dto);
|
|
|
return ApiResponse.successful();
|
|
|
@@ -103,7 +125,7 @@ public class VoteController {
|
|
|
* @param activityId 投票活动 ID
|
|
|
* @return 接口返回对象
|
|
|
*/
|
|
|
- @GetMapping("votes/")
|
|
|
+ @GetMapping("/votes")
|
|
|
public ApiResponse<List<VoteViewDto>> searchVote(@RequestParam("activityId") Integer activityId) {
|
|
|
List<VoteViewDto> votes = voteService.searchVotes(activityId);
|
|
|
return ApiResponse.successful(votes);
|
|
|
@@ -115,7 +137,7 @@ public class VoteController {
|
|
|
* @param dto 投票数据传输对象
|
|
|
* @return 接口返回对象
|
|
|
*/
|
|
|
- @PutMapping("choice/")
|
|
|
+ @PutMapping("/choice")
|
|
|
public ApiResponse<Void> choice(@RequestBody @Valid ChoiceDto dto) {
|
|
|
voteService.madeChoice(dto);
|
|
|
return ApiResponse.successful();
|
|
|
@@ -127,7 +149,7 @@ public class VoteController {
|
|
|
* @param dto 代理投票数据传输对象
|
|
|
* @return 接口返回对象
|
|
|
*/
|
|
|
- @PutMapping("choise/delegation")
|
|
|
+ @PutMapping("/choice/delegation")
|
|
|
public ApiResponse<Void> choiceDelegation(@RequestBody @Valid ChoiceDelegationDto dto) {
|
|
|
voteService.madeChoiceDelegation(dto);
|
|
|
return ApiResponse.successful();
|