mirror of https://github.com/halo-dev/halo
Add all enum type converter
parent
3714e8e5bf
commit
4f11942c9c
|
@ -2,6 +2,7 @@ package cc.ryanc.halo.model.dto;
|
|||
|
||||
import cc.ryanc.halo.model.dto.base.OutputConverter;
|
||||
import cc.ryanc.halo.model.entity.Attachment;
|
||||
import cc.ryanc.halo.model.enums.AttachmentType;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
@ -27,9 +28,11 @@ public class AttachmentOutputDTO implements OutputConverter<AttachmentOutputDTO,
|
|||
|
||||
private String suffix;
|
||||
|
||||
private String dimension;
|
||||
private Integer width;
|
||||
|
||||
private String size;
|
||||
private Integer height;
|
||||
|
||||
private Integer type;
|
||||
private Long size;
|
||||
|
||||
private AttachmentType type;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package cc.ryanc.halo.model.enums.converter;
|
||||
|
||||
import cc.ryanc.halo.model.enums.ValueEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.persistence.AttributeConverter;
|
||||
|
||||
/**
|
||||
* Abstract converter.
|
||||
*
|
||||
* @param <E> enum generic
|
||||
* @param <V> value generic
|
||||
* @author johnniang
|
||||
* @date 12/6/18
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractConverter<E extends ValueEnum<V>, V> implements AttributeConverter<E, V> {
|
||||
|
||||
private final Class<E> clazz;
|
||||
|
||||
protected AbstractConverter(Class<E> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V convertToDatabaseColumn(E attribute) {
|
||||
log.debug("Convert to database column: [{}], class type: [{}]", attribute, clazz.getSimpleName());
|
||||
return attribute == null ? null : attribute.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public E convertToEntityAttribute(V dbData) {
|
||||
log.debug("Convert to entity attribute: [{}], class type: [{}]", dbData, clazz.getSimpleName());
|
||||
return dbData == null ? null : ValueEnum.valueToEnum(clazz, dbData);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cc.ryanc.halo.model.enums.converter;
|
||||
|
||||
import cc.ryanc.halo.model.enums.AttachmentType;
|
||||
|
||||
import javax.persistence.Converter;
|
||||
|
||||
/**
|
||||
* Attachment type converter
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/27/19
|
||||
*/
|
||||
@Converter(autoApply = true)
|
||||
public class AttachmentTypeConverter extends AbstractConverter<AttachmentType, Integer> {
|
||||
|
||||
public AttachmentTypeConverter() {
|
||||
super(AttachmentType.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cc.ryanc.halo.model.enums.converter;
|
||||
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
|
||||
import javax.persistence.Converter;
|
||||
|
||||
/**
|
||||
* Comment status converter.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/27/19
|
||||
*/
|
||||
@Converter(autoApply = true)
|
||||
public class CommentStatusConverter extends AbstractConverter<CommentStatus, Integer> {
|
||||
|
||||
public CommentStatusConverter() {
|
||||
super(CommentStatus.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cc.ryanc.halo.model.enums.converter;
|
||||
|
||||
import cc.ryanc.halo.model.enums.LogType;
|
||||
|
||||
import javax.persistence.Converter;
|
||||
|
||||
/**
|
||||
* Log type converter.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/27/19
|
||||
*/
|
||||
@Converter(autoApply = true)
|
||||
public class LogTypeConverter extends AbstractConverter<LogType, Integer> {
|
||||
|
||||
public LogTypeConverter() {
|
||||
super(LogType.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cc.ryanc.halo.model.enums.converter;
|
||||
|
||||
import cc.ryanc.halo.model.enums.PostCreateFrom;
|
||||
|
||||
import javax.persistence.Converter;
|
||||
|
||||
/**
|
||||
* Post create from converter.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/27/19
|
||||
*/
|
||||
@Converter(autoApply = true)
|
||||
public class PostCreateFromConverter extends AbstractConverter<PostCreateFrom, Integer> {
|
||||
|
||||
public PostCreateFromConverter() {
|
||||
super(PostCreateFrom.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cc.ryanc.halo.model.enums.converter;
|
||||
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
|
||||
import javax.persistence.Converter;
|
||||
|
||||
/**
|
||||
* PostStatus converter.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/27/19
|
||||
*/
|
||||
@Converter(autoApply = true)
|
||||
public class PostStatusConverter extends AbstractConverter<PostStatus, Integer> {
|
||||
|
||||
public PostStatusConverter() {
|
||||
super(PostStatus.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cc.ryanc.halo.model.enums.converter;
|
||||
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
|
||||
import javax.persistence.Converter;
|
||||
|
||||
/**
|
||||
* PostType converter.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 3/27/19
|
||||
*/
|
||||
@Converter(autoApply = true)
|
||||
public class PostTypeConverter extends AbstractConverter<PostType, Integer> {
|
||||
|
||||
public PostTypeConverter() {
|
||||
super(PostType.class);
|
||||
}
|
||||
}
|
|
@ -79,6 +79,8 @@ public class AttachmentServiceImpl extends AbstractCrudService<Attachment, Integ
|
|||
attachment.setSize(uploadResult.getSize());
|
||||
attachment.setType(attachmentType);
|
||||
|
||||
log.debug("Creating attachment: [{}]", attachment);
|
||||
|
||||
// Create and return
|
||||
return create(attachment);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue