refactor(model-file): Refactor the toEntity that creates and updates the DTO

This commit is contained in:
sol 2025-08-21 16:42:09 +08:00
parent 4a1ce2324e
commit c067653144
6 changed files with 50 additions and 28 deletions

View file

@ -2,10 +2,13 @@ package com.bgasol.model.file.image.dto;
import com.bgasol.common.core.base.dto.BaseCreateDto;
import com.bgasol.model.file.image.entity.ImageEntity;
import com.bgasol.model.file.image.mapstruct.ImageMapstruct;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
@Setter
@ -25,9 +28,7 @@ public class ImageCreateDto extends BaseCreateDto<ImageEntity> {
@JsonIgnore
@Schema(hidden = true)
public ImageEntity toEntity() {
ImageEntity imageEntity = new ImageEntity();
imageEntity.setName(name);
imageEntity.setFileId(fileId);
ImageEntity imageEntity = ImageMapstruct.IMAGE_MAPSTRUCT.toEntity(this);
return this.toEntity(imageEntity);
}
}

View file

@ -2,10 +2,13 @@ package com.bgasol.model.file.image.dto;
import com.bgasol.common.core.base.dto.BaseUpdateDto;
import com.bgasol.model.file.image.entity.ImageEntity;
import com.bgasol.model.file.image.mapstruct.ImageMapstruct;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
@Setter
@ -25,9 +28,7 @@ public class ImageUpdateDto extends BaseUpdateDto<ImageEntity> {
@JsonIgnore
@Schema(hidden = true)
public ImageEntity toEntity() {
ImageEntity imageEntity = new ImageEntity();
imageEntity.setName(name);
imageEntity.setFileId(fileId);
ImageEntity imageEntity = ImageMapstruct.IMAGE_MAPSTRUCT.toEntity(this);
return this.toEntity(imageEntity);
}
}

View file

@ -0,0 +1,17 @@
package com.bgasol.model.file.image.mapstruct;
import com.bgasol.model.file.image.dto.ImageCreateDto;
import com.bgasol.model.file.image.dto.ImageUpdateDto;
import com.bgasol.model.file.image.entity.ImageEntity;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper()
public interface ImageMapstruct {
ImageMapstruct IMAGE_MAPSTRUCT = Mappers.getMapper(ImageMapstruct.class);
ImageEntity toEntity(ImageCreateDto dto);
ImageEntity toEntity(ImageUpdateDto dto);
}

View file

@ -9,6 +9,8 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import static com.bgasol.model.file.video.mapstruct.VideoMapstruct.VIDEO_MAPSTRUCT;
@Setter
@Getter
@SuperBuilder
@ -46,16 +48,7 @@ public class VideoCreateDto extends BaseCreateDto<VideoEntity> {
@JsonIgnore
@Schema(hidden = true)
public VideoEntity toEntity() {
VideoEntity videoEntity = VideoEntity.builder()
.name(name)
.width(width)
.height(height)
.duration(duration)
.format(format)
.bitrate(bitrate)
.fps(fps)
.codec(codec)
.fileId(fileId).build();
VideoEntity videoEntity = VIDEO_MAPSTRUCT.toEntity(this);
return this.toEntity(videoEntity);
}
}

View file

@ -9,6 +9,8 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import static com.bgasol.model.file.video.mapstruct.VideoMapstruct.VIDEO_MAPSTRUCT;
@Setter
@Getter
@SuperBuilder
@ -46,16 +48,7 @@ public class VideoUpdateDto extends BaseUpdateDto<VideoEntity> {
@JsonIgnore
@Schema(hidden = true)
public VideoEntity toEntity() {
VideoEntity videoEntity = VideoEntity.builder()
.name(name)
.width(width)
.height(height)
.duration(duration)
.format(format)
.bitrate(bitrate)
.fps(fps)
.codec(codec)
.fileId(fileId).build();
VideoEntity videoEntity = VIDEO_MAPSTRUCT.toEntity(this);
return this.toEntity(videoEntity);
}
}

View file

@ -0,0 +1,17 @@
package com.bgasol.model.file.video.mapstruct;
import com.bgasol.model.file.video.dto.VideoCreateDto;
import com.bgasol.model.file.video.dto.VideoUpdateDto;
import com.bgasol.model.file.video.entity.VideoEntity;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@Mapper()
public interface VideoMapstruct {
VideoMapstruct VIDEO_MAPSTRUCT = Mappers.getMapper(VideoMapstruct.class);
VideoEntity toEntity(VideoCreateDto dto);
VideoEntity toEntity(VideoUpdateDto dto);
}