package com.dora.controller;

import com.dora.common.Result;
import com.dora.entity.Banner;
import com.dora.service.BannerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Banner图控制器
 */
@RestController
@RequestMapping("/user/banner")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "Banner图管理", description = "Banner图相关接口")
public class BannerController {

    private final BannerService bannerService;

    @GetMapping("/list")
    @Operation(summary = "获取Banner列表", description = "获取所有启用的Banner图列表，无需登录")
    public Result<List<Banner>> getBannerList() {
        try {
            log.info("获取Banner列表");
            List<Banner> banners = bannerService.getAllEnabledBanners();
            return Result.success(banners, "获取Banner列表成功");
        } catch (Exception e) {
            log.error("获取Banner列表失败", e);
            return Result.error(500, "获取Banner列表失败");
        }
    }
}
