package com.ruoyi.web.controller.homepage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Introduction;
import com.ruoyi.system.service.IIntroductionService;

@RestController
@RequestMapping("/homepage/introduction")
public class IntroductionController extends BaseController
{
    @Autowired
    private IIntroductionService introductionService;

    @PreAuthorize("@ss.hasPermi('homepage:introduction:query')")
    @GetMapping
    public AjaxResult getInfo()
    {
        Introduction introduction = introductionService.selectIntroductionOne();
        return success(introduction);
    }

    @PreAuthorize("@ss.hasPermi('homepage:introduction:query')")
    @GetMapping(value = "/{introId}")
    public AjaxResult getInfoById(@PathVariable Long introId)
    {
        return success(introductionService.selectIntroductionById(introId));
    }

    @PreAuthorize("@ss.hasPermi('homepage:introduction:edit')")
    @Log(title = "总体介绍", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Introduction introduction)
    {
        introduction.setCreateBy(getUsername());
        return toAjax(introductionService.insertIntroduction(introduction));
    }

    @PreAuthorize("@ss.hasPermi('homepage:introduction:edit')")
    @Log(title = "总体介绍", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Introduction introduction)
    {
        introduction.setUpdateBy(getUsername());
        return toAjax(introductionService.updateIntroduction(introduction));
    }

    @PreAuthorize("@ss.hasPermi('homepage:introduction:remove')")
    @Log(title = "总体介绍", businessType = BusinessType.DELETE)
    @DeleteMapping("/{introId}")
    public AjaxResult remove(@PathVariable Long introId)
    {
        return toAjax(introductionService.deleteIntroductionById(introId));
    }
}
