PlatformCityFeePlanController.java 2.92 KB
package com.diligrp.rider.controller;

import com.diligrp.rider.common.result.Result;
import com.diligrp.rider.dto.DeliveryFeePlanPreviewDTO;
import com.diligrp.rider.dto.DeliveryFeePlanSaveDTO;
import com.diligrp.rider.service.DeliveryFeePlanService;
import com.diligrp.rider.vo.DeliveryFeePlanDetailVO;
import com.diligrp.rider.vo.DeliveryFeePlanVO;
import com.diligrp.rider.vo.DeliveryFeeResultVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/platform/city")
@RequiredArgsConstructor
public class PlatformCityFeePlanController {

    private final DeliveryFeePlanService deliveryFeePlanService;

    @GetMapping("/{cityId}/fee-plans")
    public Result<List<DeliveryFeePlanVO>> listPlans(@PathVariable Long cityId) {
        return Result.success(deliveryFeePlanService.listPlans(cityId));
    }

    @GetMapping("/{cityId}/fee-plans/{planId}")
    public Result<DeliveryFeePlanDetailVO> getPlanDetail(@PathVariable Long cityId, @PathVariable Long planId) {
        return Result.success(deliveryFeePlanService.getPlanDetail(cityId, planId));
    }

    @PostMapping("/{cityId}/fee-plans")
    public Result<Long> createPlan(@PathVariable Long cityId, @RequestBody DeliveryFeePlanSaveDTO dto) {
        return Result.success(deliveryFeePlanService.createPlan(cityId, dto));
    }

    @PostMapping("/{cityId}/fee-plans/init-default")
    public Result<Long> initializeDefaultPlan(@PathVariable Long cityId) {
        return Result.success(deliveryFeePlanService.initializeDefaultPlan(cityId));
    }

    @PutMapping("/{cityId}/fee-plans/{planId}")
    public Result<Void> updatePlan(@PathVariable Long cityId,
                                   @PathVariable Long planId,
                                   @RequestBody DeliveryFeePlanSaveDTO dto) {
        deliveryFeePlanService.updatePlan(cityId, planId, dto);
        return Result.success();
    }

    @PostMapping("/{cityId}/fee-plans/{planId}/copy")
    public Result<Long> copyPlan(@PathVariable Long cityId, @PathVariable Long planId) {
        return Result.success(deliveryFeePlanService.copyPlan(cityId, planId));
    }

    @PostMapping("/{cityId}/fee-plans/{planId}/default")
    public Result<Void> setDefaultPlan(@PathVariable Long cityId, @PathVariable Long planId) {
        deliveryFeePlanService.setDefaultPlan(cityId, planId);
        return Result.success();
    }

    @DeleteMapping("/{cityId}/fee-plans/{planId}")
    public Result<Void> deletePlan(@PathVariable Long cityId, @PathVariable Long planId) {
        deliveryFeePlanService.deletePlan(cityId, planId);
        return Result.success();
    }

    @PostMapping("/{cityId}/fee-plans/preview")
    public Result<DeliveryFeeResultVO> preview(@PathVariable Long cityId,
                                               @RequestBody DeliveryFeePlanPreviewDTO dto) {
        return Result.success(deliveryFeePlanService.preview(cityId, dto));
    }
}