use of com.actionworks.flashsale.app.model.dto.FlashActivityDTO in project flash-sale by ThoughtsBeta.
the class DefaultActivityAppService method getFlashActivity.
@Override
public AppSimpleResult<FlashActivityDTO> getFlashActivity(Long userId, Long activityId, Long version) {
if (userId == null || activityId == null) {
throw new BizException(INVALID_PARAMS);
}
FlashActivityCache flashActivityCache = flashActivityCacheService.getCachedActivity(activityId, version);
if (!flashActivityCache.isExist()) {
throw new BizException(ACTIVITY_NOT_FOUND.getErrDesc());
}
if (flashActivityCache.isLater()) {
return AppSimpleResult.tryLater();
}
FlashActivityDTO flashActivityDTO = FlashActivityAppBuilder.toFlashActivityDTO(flashActivityCache.getFlashActivity());
flashActivityDTO.setVersion(flashActivityCache.getVersion());
return AppSimpleResult.ok(flashActivityDTO);
}
use of com.actionworks.flashsale.app.model.dto.FlashActivityDTO in project flash-sale by ThoughtsBeta.
the class FlashActivityController method getFlashActivity.
@GetMapping(value = "/flash-activities/{activityId}")
@SentinelResource("GetActivityResource")
public SingleResponse<FlashActivityResponse> getFlashActivity(@RequestAttribute Long userId, @PathVariable Long activityId, @RequestParam(required = false) Long version) {
AppSimpleResult<FlashActivityDTO> flashActivityResult = flashActivityAppService.getFlashActivity(userId, activityId, version);
if (!flashActivityResult.isSuccess() || flashActivityResult.getData() == null) {
return ResponseBuilder.withSingle(flashActivityResult);
}
FlashActivityDTO flashActivityDTO = flashActivityResult.getData();
return SingleResponse.of(toFlashActivityResponse(flashActivityDTO));
}
use of com.actionworks.flashsale.app.model.dto.FlashActivityDTO in project flash-sale by ThoughtsBeta.
the class DefaultActivityAppService method getFlashActivities.
@Override
public AppMultiResult<FlashActivityDTO> getFlashActivities(Long userId, FlashActivitiesQuery flashActivitiesQuery) {
List<FlashActivity> activities;
Integer total;
if (flashActivitiesQuery.isFirstPureQuery()) {
FlashActivitiesCache flashActivitiesCache = flashActivitiesCacheService.getCachedActivities(flashActivitiesQuery.getPageNumber(), flashActivitiesQuery.getVersion());
if (flashActivitiesCache.isLater()) {
return AppMultiResult.tryLater();
}
activities = flashActivitiesCache.getFlashActivities();
total = flashActivitiesCache.getTotal();
} else {
PageResult<FlashActivity> flashActivityPageResult = flashActivityDomainService.getFlashActivities(toFlashActivitiesQuery(flashActivitiesQuery));
activities = flashActivityPageResult.getData();
total = flashActivityPageResult.getTotal();
}
List<FlashActivityDTO> flashActivityDTOList = activities.stream().map(FlashActivityAppBuilder::toFlashActivityDTO).collect(Collectors.toList());
return AppMultiResult.of(flashActivityDTOList, total);
}
use of com.actionworks.flashsale.app.model.dto.FlashActivityDTO in project flash-sale by ThoughtsBeta.
the class FlashActivityAppBuilder method toFlashActivityDTO.
public static FlashActivityDTO toFlashActivityDTO(FlashActivity flashActivity) {
if (flashActivity == null) {
return null;
}
FlashActivityDTO flashActivityDTO = new FlashActivityDTO();
BeanUtils.copyProperties(flashActivity, flashActivityDTO);
return flashActivityDTO;
}
use of com.actionworks.flashsale.app.model.dto.FlashActivityDTO in project flash-sale by ThoughtsBeta.
the class FlashActivityController method getOnlineFlashActivities.
@GetMapping(value = "/flash-activities/online")
@SentinelResource("GetOnlineActivitiesResource")
public MultiResponse<FlashActivityResponse> getOnlineFlashActivities(@RequestAttribute Long userId, @RequestParam Integer pageSize, @RequestParam Integer pageNumber, @RequestParam(required = false) String keyword) {
FlashActivitiesQuery flashActivitiesQuery = new FlashActivitiesQuery().setKeyword(keyword).setPageSize(pageSize).setPageNumber(pageNumber).setStatus(FlashActivityStatus.ONLINE.getCode());
AppMultiResult<FlashActivityDTO> flashActivitiesResult = flashActivityAppService.getFlashActivities(userId, flashActivitiesQuery);
if (!flashActivitiesResult.isSuccess() || flashActivitiesResult.getData() == null) {
return ResponseBuilder.withMulti(flashActivitiesResult);
}
return MultiResponse.of(toFlashActivitiesResponse(flashActivitiesResult.getData()), flashActivitiesResult.getTotal());
}
Aggregations