|
@@ -0,0 +1,47 @@
|
|
|
|
|
+package com.etotem.cfc.controller.profile;
|
|
|
|
|
+
|
|
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
|
|
+import com.etotem.cfc.service.ProfileReadService;
|
|
|
|
|
+import com.etotem.cfc.service.RecommendService;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/api/profile")
|
|
|
|
|
+public class ProfileController {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired private ProfileReadService profileReadService;
|
|
|
|
|
+ @Autowired private RecommendService recommendService;
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/my")
|
|
|
|
|
+ public Result<Map<String, Object>> getMyProfile(HttpServletRequest request) {
|
|
|
|
|
+ Long memberId = (Long) request.getAttribute("memberId");
|
|
|
|
|
+ if (memberId == null) {
|
|
|
|
|
+ memberId = (Long) request.getAttribute("userId");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (memberId == null) {
|
|
|
|
|
+ return Result.error("未登录");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> profile = profileReadService.getProfile(memberId);
|
|
|
|
|
+ Map<String, Object> recommendations = recommendService.getRecommendations(memberId);
|
|
|
|
|
+ profile.putAll(recommendations);
|
|
|
|
|
+ return Result.success(profile);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/history")
|
|
|
|
|
+ public Result<Map<String, Object>> getHistory(@RequestBody Map<String, Object> params, HttpServletRequest request) {
|
|
|
|
|
+ Long memberId = (Long) request.getAttribute("memberId");
|
|
|
|
|
+ if (memberId == null) {
|
|
|
|
|
+ memberId = (Long) request.getAttribute("userId");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (memberId == null) {
|
|
|
|
|
+ return Result.error("未登录");
|
|
|
|
|
+ }
|
|
|
|
|
+ int days = params.get("days") != null ? ((Number) params.get("days")).intValue() : 30;
|
|
|
|
|
+ Map<String, Object> trend = profileReadService.getTrend(memberId, days);
|
|
|
|
|
+ return Result.success(trend);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|