package com.lion.lionwebsite.Service;

import com.lion.lionwebsite.Dao.normal.CollectMapper;
import com.lion.lionwebsite.Util.Response;
import lombok.Data;
import org.springframework.stereotype.Service;

@Service
@Data
public class CollectService {
    CollectMapper collectMapper;

    public CollectService(CollectMapper collectMapper){
        this.collectMapper = collectMapper;
    }

    public String collectGallery(int gid, int collector){
        Response response = Response.generateResponse();
        if(collectMapper.isCollect(gid, collector) == 0) {  //没有收藏
            collectMapper.collect(gid, collector);
            response.success("收藏成功");
        }else{
            response.failure("已经收藏了");
        }
        return response.toJSONString();
    }

    public String disCollectGallery(int gid, int collector){
        Response response = Response.generateResponse();
        if(collectMapper.isCollect(gid, collector) == 0) {  //没有收藏
            response.failure("没有收藏该本子");
        }else{
            collectMapper.disCollect(gid, collector);
            response.success("取消收藏成功");
        }

        return response.toJSONString();
    }
}
