All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.pacifista.api.web.news.service.services.PacifistaNewsService Maven / Gradle / Ivy

There is a newer version: 1.5.3.11
Show newest version
package fr.pacifista.api.web.news.service.services;

import com.funixproductions.api.user.client.dtos.UserSession;
import com.funixproductions.api.user.client.security.CurrentSession;
import com.funixproductions.core.crud.services.ApiService;
import fr.pacifista.api.web.news.client.dtos.PacifistaNewsDTO;
import fr.pacifista.api.web.news.service.entities.PacifistaNews;
import fr.pacifista.api.web.news.service.mappers.PacifistaNewsMapper;
import fr.pacifista.api.web.news.service.repositories.PacifistaNewsRepository;
import lombok.NonNull;
import org.springframework.stereotype.Service;

@Service
public class PacifistaNewsService extends ApiService {

    private final CurrentSession actualSession;

    public PacifistaNewsService(PacifistaNewsRepository repository,
                                PacifistaNewsMapper mapper,
                                CurrentSession actualSession) {
        super(repository, mapper);
        this.actualSession = actualSession;
    }

    @Override
    public void beforeSavingEntity(@NonNull Iterable entity) {
        final UserSession session = this.actualSession.getUserSession();

        if (session != null) {
            for (final PacifistaNews e : entity) {
                if (e.getId() == null) {
                    e.setOriginalWriter(session.getUserDTO().getUsername());
                } else {
                    e.setUpdateWriter(session.getUserDTO().getUsername());
                }
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy