113 lines
3.3 KiB
Go
113 lines
3.3 KiB
Go
|
|
package request
|
||
|
|
|
||
|
|
import (
|
||
|
|
"narasi-ahli-be/app/database/entity"
|
||
|
|
"narasi-ahli-be/utils/paginator"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
type AiChatFilesGeneric interface {
|
||
|
|
ToEntity()
|
||
|
|
}
|
||
|
|
|
||
|
|
type AiChatFilesQueryRequest struct {
|
||
|
|
MessageId *int `json:"messageId"`
|
||
|
|
FileName *string `json:"fileName"`
|
||
|
|
StatusId *int `json:"statusId"`
|
||
|
|
IsPublish *bool `json:"isPublish"`
|
||
|
|
Pagination *paginator.Pagination `json:"pagination"`
|
||
|
|
}
|
||
|
|
|
||
|
|
type AiChatFilesCreateRequest struct {
|
||
|
|
MessageId uint `json:"messageId" validate:"required"`
|
||
|
|
StatusId int `json:"statusId" validate:"required"`
|
||
|
|
UploadId *string `json:"uploadId"`
|
||
|
|
FilePath *string `json:"filePath"`
|
||
|
|
FileUrl *string `json:"fileUrl"`
|
||
|
|
FileName *string `json:"fileName"`
|
||
|
|
FileThumbnail *string `json:"fileThumbnail"`
|
||
|
|
FileAlt *string `json:"fileAlt"`
|
||
|
|
WidthPixel *string `json:"widthPixel"`
|
||
|
|
HeightPixel *string `json:"heightPixel"`
|
||
|
|
Size *string `json:"size"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (req AiChatFilesCreateRequest) ToEntity() *entity.AiChatFiles {
|
||
|
|
return &entity.AiChatFiles{
|
||
|
|
MessageId: req.MessageId,
|
||
|
|
UploadID: req.UploadId,
|
||
|
|
FilePath: req.FilePath,
|
||
|
|
FileUrl: req.FileUrl,
|
||
|
|
FileName: req.FileName,
|
||
|
|
FileThumbnail: req.FileThumbnail,
|
||
|
|
FileAlt: req.FileAlt,
|
||
|
|
Size: req.Size,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type AiChatFilesUpdateRequest struct {
|
||
|
|
ID uint `json:"id" validate:"required"`
|
||
|
|
MessageId uint `json:"messageId" validate:"required"`
|
||
|
|
StatusId int `json:"statusId" validate:"required"`
|
||
|
|
FilePath *string `json:"filePath"`
|
||
|
|
FileUrl *string `json:"fileUrl"`
|
||
|
|
FileName *string `json:"fileName"`
|
||
|
|
FileThumbnail *string `json:"fileThumbnail"`
|
||
|
|
FileAlt *string `json:"fileAlt"`
|
||
|
|
WidthPixel *string `json:"widthPixel"`
|
||
|
|
HeightPixel *string `json:"heightPixel"`
|
||
|
|
Size *string `json:"size"`
|
||
|
|
IsPublish *bool `json:"isPublish" validate:"required"`
|
||
|
|
PublishedAt *time.Time `json:"publishedAt" validate:"required"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (req AiChatFilesUpdateRequest) ToEntity() *entity.AiChatFiles {
|
||
|
|
return &entity.AiChatFiles{
|
||
|
|
ID: req.ID,
|
||
|
|
MessageId: req.MessageId,
|
||
|
|
FilePath: req.FilePath,
|
||
|
|
FileUrl: req.FileUrl,
|
||
|
|
FileName: req.FileName,
|
||
|
|
FileThumbnail: req.FileThumbnail,
|
||
|
|
FileAlt: req.FileAlt,
|
||
|
|
Size: req.Size,
|
||
|
|
UpdatedAt: time.Now(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
type AiChatFilesQueryRequestContext struct {
|
||
|
|
MessageId string `json:"messageId"`
|
||
|
|
FileName string `json:"fileName"`
|
||
|
|
StatusId string `json:"statusId"`
|
||
|
|
IsPublish string `json:"isPublish"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (req AiChatFilesQueryRequestContext) ToParamRequest() AiChatFilesQueryRequest {
|
||
|
|
var request AiChatFilesQueryRequest
|
||
|
|
|
||
|
|
if messageIdStr := req.MessageId; messageIdStr != "" {
|
||
|
|
messageId, err := strconv.Atoi(messageIdStr)
|
||
|
|
if err == nil {
|
||
|
|
request.MessageId = &messageId
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if fileName := req.FileName; fileName != "" {
|
||
|
|
request.FileName = &fileName
|
||
|
|
}
|
||
|
|
if statusIdStr := req.StatusId; statusIdStr != "" {
|
||
|
|
statusId, err := strconv.Atoi(statusIdStr)
|
||
|
|
if err == nil {
|
||
|
|
request.StatusId = &statusId
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if isPublishStr := req.IsPublish; isPublishStr != "" {
|
||
|
|
isPublish, err := strconv.ParseBool(isPublishStr)
|
||
|
|
if err == nil {
|
||
|
|
request.IsPublish = &isPublish
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return request
|
||
|
|
}
|