package com.talentcard.server.business.portal;
|
|
import java.util.Map;
|
|
import com.talentcard.server.business.auth.TalentAuthService;
|
import com.talentcard.server.business.auth.TalentSessionPrincipal;
|
import com.talentcard.server.business.PageResult;
|
import com.talentcard.server.common.ApiResponse;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestHeader;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
@RestController
|
@RequestMapping("/api/app")
|
public class PortalController {
|
|
private final PortalService portalService;
|
private final TalentAuthService talentAuthService;
|
|
public PortalController(PortalService portalService, TalentAuthService talentAuthService) {
|
this.portalService = portalService;
|
this.talentAuthService = talentAuthService;
|
}
|
|
@GetMapping("/home")
|
public ApiResponse<Map<String, Object>> home(@RequestParam(required = false) Long talentId) {
|
return ApiResponse.success(portalService.home(talentId));
|
}
|
|
@GetMapping("/news")
|
public ApiResponse<PageResult<Map<String, Object>>> news(
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "10") int size
|
) {
|
return ApiResponse.success(portalService.news(page, size));
|
}
|
|
@GetMapping("/news/{id}")
|
public ApiResponse<Map<String, Object>> newsDetail(@PathVariable Long id) {
|
return ApiResponse.success(portalService.newsDetail(id));
|
}
|
|
@GetMapping("/policies")
|
public ApiResponse<PageResult<Map<String, Object>>> policies(
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "10") int size
|
) {
|
return ApiResponse.success(portalService.policies(page, size));
|
}
|
|
@GetMapping("/policies/{id}")
|
public ApiResponse<Map<String, Object>> policy(@PathVariable Long id) {
|
return ApiResponse.success(portalService.policy(id));
|
}
|
|
@GetMapping("/benefits")
|
public ApiResponse<PageResult<Map<String, Object>>> benefits(
|
@RequestParam(required = false) String type,
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "10") int size
|
) {
|
return ApiResponse.success(portalService.benefits(type, page, size));
|
}
|
|
@GetMapping("/merchants")
|
public ApiResponse<PageResult<Map<String, Object>>> merchants(
|
@RequestParam(required = false) String type,
|
@RequestParam(required = false) String keyword,
|
@RequestParam(required = false) String categoryId,
|
@RequestParam(required = false) String mode,
|
@RequestParam(required = false) String sortField,
|
@RequestParam(required = false) String sortOrder,
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "10") int size
|
) {
|
return ApiResponse.success(portalService.merchants(type, keyword, categoryId, mode, sortField, sortOrder, page, size));
|
}
|
|
@GetMapping("/topics/food")
|
public ApiResponse<Map<String, Object>> foodTopic() {
|
return ApiResponse.success(portalService.foodTopic());
|
}
|
|
@GetMapping("/topics/food/merchants")
|
public ApiResponse<PageResult<Map<String, Object>>> foodMerchants(
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "4") int size,
|
@RequestParam(required = false) Long talentId
|
) {
|
return ApiResponse.success(portalService.foodMerchants(page, size, talentId));
|
}
|
|
@GetMapping("/topics/travel")
|
public ApiResponse<Map<String, Object>> travelTopic() {
|
return ApiResponse.success(portalService.travelTopic());
|
}
|
|
@GetMapping("/topics/travel/merchants")
|
public ApiResponse<PageResult<Map<String, Object>>> travelMerchants(
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "4") int size
|
) {
|
return ApiResponse.success(portalService.travelMerchants(page, size));
|
}
|
|
@GetMapping("/topics/stay")
|
public ApiResponse<Map<String, Object>> stayTopic() {
|
return ApiResponse.success(portalService.stayTopic());
|
}
|
|
@GetMapping("/topics/stay/merchants")
|
public ApiResponse<PageResult<Map<String, Object>>> stayMerchants(
|
@RequestParam(defaultValue = "hotel") String type,
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "4") int size,
|
@RequestParam(required = false) Long talentId
|
) {
|
return ApiResponse.success(portalService.stayMerchants(type, page, size, talentId));
|
}
|
|
@GetMapping("/topics/entertainment")
|
public ApiResponse<Map<String, Object>> entertainmentTopic() {
|
return ApiResponse.success(portalService.entertainmentTopic());
|
}
|
|
@GetMapping("/topics/entertainment/merchants")
|
public ApiResponse<PageResult<Map<String, Object>>> entertainmentMerchants(
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "4") int size
|
) {
|
return ApiResponse.success(portalService.entertainmentMerchants(page, size));
|
}
|
|
@GetMapping("/topics/transport")
|
public ApiResponse<Map<String, Object>> transportTopic() {
|
return ApiResponse.success(portalService.transportTopic());
|
}
|
|
@GetMapping("/topics/transport/merchants")
|
public ApiResponse<PageResult<Map<String, Object>>> transportMerchants(
|
@RequestParam(defaultValue = "fuel") String type,
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "4") int size
|
) {
|
return ApiResponse.success(portalService.transportMerchants(type, page, size));
|
}
|
|
@GetMapping("/topics/shopping")
|
public ApiResponse<Map<String, Object>> shoppingTopic() {
|
return ApiResponse.success(portalService.shoppingTopic());
|
}
|
|
@GetMapping("/topics/shopping/merchants")
|
public ApiResponse<PageResult<Map<String, Object>>> shoppingMerchants(
|
@RequestParam String categoryId,
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "4") int size
|
) {
|
return ApiResponse.success(portalService.shoppingMerchants(categoryId, page, size));
|
}
|
|
@GetMapping("/topics/premium")
|
public ApiResponse<Map<String, Object>> premiumTopic() {
|
return ApiResponse.success(portalService.premiumTopic());
|
}
|
|
@GetMapping("/topics/premium/services")
|
public ApiResponse<PageResult<Map<String, Object>>> premiumServices(
|
@RequestParam String type,
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "4") int size
|
) {
|
return ApiResponse.success(portalService.premiumServices(type, page, size));
|
}
|
|
@GetMapping("/merchants/{id}")
|
public ApiResponse<Map<String, Object>> merchantDetail(
|
@PathVariable Long id,
|
@RequestParam(required = false) Long talentId,
|
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authorization
|
) {
|
return ApiResponse.success(portalService.merchantDetail(id, sessionTalentId(authorization, talentId)));
|
}
|
|
@GetMapping("/products")
|
public ApiResponse<PageResult<Map<String, Object>>> products(
|
@RequestParam(required = false) Long merchantId,
|
@RequestParam(required = false) String type,
|
@RequestParam(required = false) Long talentId,
|
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authorization,
|
@RequestParam(defaultValue = "1") int page,
|
@RequestParam(defaultValue = "10") int size
|
) {
|
return ApiResponse.success(portalService.products(merchantId, type, sessionTalentId(authorization, talentId), page, size));
|
}
|
|
@GetMapping("/products/{id}")
|
public ApiResponse<Map<String, Object>> productDetail(
|
@PathVariable Long id,
|
@RequestParam(required = false) Long talentId,
|
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authorization
|
) {
|
return ApiResponse.success(portalService.productDetail(id, sessionTalentId(authorization, talentId)));
|
}
|
|
@GetMapping("/order-drafts/coupons")
|
public ApiResponse<java.util.List<Map<String, Object>>> availableOrderCoupons(
|
@RequestParam Long merchantId,
|
@RequestParam Long productId,
|
@RequestParam String orderId,
|
@RequestParam(required = false) Long talentId,
|
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authorization
|
) {
|
return ApiResponse.success(portalService.availableOrderCoupons(merchantId, productId, orderId, sessionTalentId(authorization, talentId)));
|
}
|
|
@GetMapping("/order-drafts/coupon-quote")
|
public ApiResponse<Map<String, Object>> orderCouponQuote(
|
@RequestParam Long merchantId,
|
@RequestParam Long productId,
|
@RequestParam String orderId,
|
@RequestParam(required = false) Long couponId,
|
@RequestParam(required = false) Long talentId,
|
@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authorization
|
) {
|
return ApiResponse.success(portalService.orderCouponQuote(merchantId, productId, orderId, couponId, sessionTalentId(authorization, talentId)));
|
}
|
|
private Long sessionTalentId(String authorization, Long requestedTalentId) {
|
if (authorization == null || authorization.isBlank()) return requestedTalentId;
|
TalentSessionPrincipal principal = talentAuthService.authenticate(authorization);
|
return principal.talentId();
|
}
|
}
|