TorrentMapperImpl.java

package api.mapper;

import api.dtos.TorrentDto;
import api.entities.S3Object;
import api.entities.Torrent;
import api.entities.User;
import javax.annotation.processing.Generated;
import org.springframework.stereotype.Component;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2026-04-25T01:54:14+0000",
    comments = "version: 1.6.3, compiler: javac, environment: Java 17.0.18 (Eclipse Adoptium)"
)
@Component
public class TorrentMapperImpl implements TorrentMapper {

    @Override
    public TorrentDto toDto(Torrent torrent) {
        if ( torrent == null ) {
            return null;
        }

        TorrentDto.TorrentDtoBuilder torrentDto = TorrentDto.builder();

        torrentDto.fileSize( torrentFileSize( torrent ) );
        torrentDto.uploaderId( torrentUploaderId( torrent ) );
        torrentDto.uploaderUsername( torrentUploaderUsername( torrent ) );
        torrentDto.id( torrent.getId() );
        torrentDto.name( torrent.getName() );
        torrentDto.description( torrent.getDescription() );
        torrentDto.repoId( torrent.getRepoId() );
        torrentDto.createdAt( torrent.getCreatedAt() );
        torrentDto.updatedAt( torrent.getUpdatedAt() );

        return torrentDto.build();
    }

    @Override
    public void update(Torrent torrent, TorrentDto updateDto) {
        if ( updateDto == null ) {
            return;
        }

        if ( updateDto.getName() != null ) {
            torrent.setName( updateDto.getName() );
        }
        if ( updateDto.getDescription() != null ) {
            torrent.setDescription( updateDto.getDescription() );
        }
    }

    @Override
    public Torrent toEntity(TorrentDto createDto) {
        if ( createDto == null ) {
            return null;
        }

        Torrent.TorrentBuilder torrent = Torrent.builder();

        torrent.name( createDto.getName() );
        torrent.description( createDto.getDescription() );
        torrent.repoId( createDto.getRepoId() );

        return torrent.build();
    }

    private Long torrentFileSize(Torrent torrent) {
        S3Object file = torrent.getFile();
        if ( file == null ) {
            return null;
        }
        return file.getSize();
    }

    private Integer torrentUploaderId(Torrent torrent) {
        User uploader = torrent.getUploader();
        if ( uploader == null ) {
            return null;
        }
        return uploader.getId();
    }

    private String torrentUploaderUsername(Torrent torrent) {
        User uploader = torrent.getUploader();
        if ( uploader == null ) {
            return null;
        }
        return uploader.getUsername();
    }
}