You've already forked FrameTour-BE
feat(pricing): 更新用户优惠券查询接口返回完整信息
- 修改 getUserCoupons 接口不再需要传入 userId 参数,从上下文获取当前登录用户 - 新增 UserCouponResp DTO 包含领取记录和优惠券配置的完整信息 - 更新 ICouponService 接口返回类型为 UserCouponResp 列表 - 在 Controller 层添加 getUserId 方法用于获取当前登录用户ID - 实现完整的用户优惠券信息组装逻辑,包含领取时间、过期时间等记录信息
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.ycwl.basic.pricing.controller;
|
||||
|
||||
import com.ycwl.basic.constant.BaseContextHandler;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.pricing.dto.*;
|
||||
import com.ycwl.basic.pricing.dto.resp.UserCouponResp;
|
||||
import com.ycwl.basic.pricing.service.ICouponService;
|
||||
import com.ycwl.basic.pricing.service.IPriceCalculationService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -53,16 +55,37 @@ public class PriceCalculationController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户可用优惠券
|
||||
* 查询用户可用优惠券(包含领取记录信息)
|
||||
*/
|
||||
@GetMapping("/coupons/my-coupons")
|
||||
public ApiResponse<List<CouponInfo>> getUserCoupons(@RequestParam Long userId) {
|
||||
public ApiResponse<List<UserCouponResp>> getUserCoupons() {
|
||||
Long userId = getUserId();
|
||||
if (userId == null) {
|
||||
return ApiResponse.fail("用户未登录");
|
||||
}
|
||||
|
||||
log.info("查询用户可用优惠券: userId={}", userId);
|
||||
|
||||
List<CouponInfo> coupons = couponService.getUserAvailableCoupons(userId);
|
||||
|
||||
|
||||
List<UserCouponResp> coupons = couponService.getUserAvailableCoupons(userId);
|
||||
|
||||
log.info("用户可用优惠券数量: {}", coupons.size());
|
||||
|
||||
|
||||
return ApiResponse.success(coupons);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户ID
|
||||
*/
|
||||
private Long getUserId() {
|
||||
try {
|
||||
String userIdStr = BaseContextHandler.getUserId();
|
||||
if (userIdStr == null || userIdStr.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return Long.valueOf(userIdStr);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("无法解析用户ID: {}", BaseContextHandler.getUserId());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user