package cn.reghao.tnb.content.app.data.controller;

import cn.reghao.jutil.jdk.web.db.PageList;
import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.auth.api.iface.AccountQuery;
import cn.reghao.tnb.content.app.data.model.vo.AlbumCard;
import cn.reghao.tnb.content.app.data.service.ImagePostService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2023-08-19 02:33:11
 */
@Slf4j
@Tag(name = "图片稿件查询接口")
@RestController
@RequestMapping("/api/content/image")
public class ImageQueryController {
    @DubboReference(check = false, retries = 0, timeout = 60_000)
    private AccountQuery accountQuery;
    private final ImagePostService imagePostService;

    public ImageQueryController(ImagePostService imagePostService) {
        this.imagePostService = imagePostService;
    }

    @Operation(summary = "获取用户的图片稿件列表", description = "N")
    @GetMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getUserImageAlbum(@RequestParam("userId") String userId, @RequestParam("page") int page) {
        long userId1 = accountQuery.getUserIdLong(userId);
        PageList<AlbumCard> pageList = imagePostService.getUserAlbums(userId1, page);
        return WebResult.success(pageList);
    }

    @Operation(summary = "获取图片稿件中的图片", description = "N")
    @GetMapping(value = "/{albumId}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String getImageAlbum(@PathVariable("albumId") long albumId, @RequestParam("page") int page) {
        String result = imagePostService.getImageAlbum(albumId, page);
        return result;
    }
}
