/*
 * This file is part of blog (https://github.com/jens-meiss/blog).
 *
 *  blog is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  blog is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with blog. If not, see <http://www.gnu.org/licenses/>.
 */
package com.github.jens_meiss.blog.server.jaxrs.blog.entry;

import com.github.jens_meiss.blog.api.dto.blog.entry.BlogEntryAddDTO;
import com.github.jens_meiss.blog.api.dto.blog.entry.BlogEntryDTO;
import com.github.jens_meiss.blog.api.dto.blog.entry.BlogEntryUpdateDTO;
import com.github.jens_meiss.blog.api.server.jaxrs.blog.entry.BlogEntryResource;
import com.github.jens_meiss.blog.api.service.BlogEntryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BlogEntryResourceImpl implements BlogEntryResource {

    private static final Logger LOGGER = LoggerFactory.getLogger(BlogEntryResourceImpl.class);

    @Autowired
    private BlogEntryService blogEntryService;

    @Override
    public void add(final BlogEntryAddDTO blogEntryAddDTO) {

        LOGGER.debug("add '{}'", blogEntryAddDTO.getBlogPath());

        blogEntryService.add(blogEntryAddDTO);
    }

    @Override
    public void edit(final String entryId, final BlogEntryUpdateDTO blogEntryUpdateDTO) {

        LOGGER.debug("editValidate '{}', '{}'", blogEntryUpdateDTO.getBlogPath(), entryId);

        blogEntryService.update(blogEntryUpdateDTO);
    }

    @Override
    public BlogEntryDTO get(final String entryId) {

        LOGGER.debug("get '{}'", entryId);

        return blogEntryService.getEntry(entryId);
    }

    @Override
    public boolean hasPermission(String entryId, String userId, String permission) {

        return blogEntryService.hasPermission(userId, entryId, permission);
    }

    @Override
    public void delete(final String entryId) {

        LOGGER.debug("delete '{}'", entryId);

        blogEntryService.delete(entryId);
    }
}
