Search in sources :

Example 1 with FlashActivityDTO

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);
}
Also used : FlashActivityDTO(com.actionworks.flashsale.app.model.dto.FlashActivityDTO) FlashActivityCache(com.actionworks.flashsale.app.service.activity.cache.model.FlashActivityCache) BizException(com.actionworks.flashsale.app.exception.BizException)

Example 2 with 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));
}
Also used : FlashActivityDTO(com.actionworks.flashsale.app.model.dto.FlashActivityDTO) GetMapping(org.springframework.web.bind.annotation.GetMapping) SentinelResource(com.alibaba.csp.sentinel.annotation.SentinelResource)

Example 3 with 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);
}
Also used : FlashActivityDTO(com.actionworks.flashsale.app.model.dto.FlashActivityDTO) FlashActivity(com.actionworks.flashsale.domain.model.entity.FlashActivity) FlashActivitiesCache(com.actionworks.flashsale.app.service.activity.cache.model.FlashActivitiesCache)

Example 4 with FlashActivityDTO

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;
}
Also used : FlashActivityDTO(com.actionworks.flashsale.app.model.dto.FlashActivityDTO)

Example 5 with 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());
}
Also used : FlashActivityDTO(com.actionworks.flashsale.app.model.dto.FlashActivityDTO) FlashActivitiesQuery(com.actionworks.flashsale.app.model.query.FlashActivitiesQuery) GetMapping(org.springframework.web.bind.annotation.GetMapping) SentinelResource(com.alibaba.csp.sentinel.annotation.SentinelResource)

Aggregations

FlashActivityDTO (com.actionworks.flashsale.app.model.dto.FlashActivityDTO)6 SentinelResource (com.alibaba.csp.sentinel.annotation.SentinelResource)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 FlashActivitiesQuery (com.actionworks.flashsale.app.model.query.FlashActivitiesQuery)2 BizException (com.actionworks.flashsale.app.exception.BizException)1 FlashActivitiesCache (com.actionworks.flashsale.app.service.activity.cache.model.FlashActivitiesCache)1 FlashActivityCache (com.actionworks.flashsale.app.service.activity.cache.model.FlashActivityCache)1 FlashActivity (com.actionworks.flashsale.domain.model.entity.FlashActivity)1