package cn.reghao.tnb.file.app.controller;

import cn.reghao.tnb.common.web.WebResult;
import cn.reghao.tnb.file.app.model.dto.AvatarUpdate;
import cn.reghao.tnb.file.app.service.AvatarService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author reghao
 * @date 2024-12-06 10:54:39
 */
@Tag(name = "头像接口")
@RestController
@RequestMapping("/api/file/avatar")
public class AvatarController {
    private final AvatarService avatarService;

    public AvatarController(AvatarService avatarService) {
        this.avatarService = avatarService;
    }

    @Operation(summary = "更新账号头像", description = "N")
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public String updateUserAvatar(@RequestBody @Validated AvatarUpdate avatarUpdate) throws Exception {
        String avatarUrl = avatarService.updateAvatar(avatarUpdate);
        return WebResult.success(Map.of("url", avatarUrl));
    }
}
