From d4bc51d730d64db6c4d77735eae31301eca6e6fa Mon Sep 17 00:00:00 2001 From: divyam234 Date: Mon, 2 Oct 2023 13:09:54 +0530 Subject: [PATCH] fix channelType --- mapper/main.go | 2 +- schemas/file.schema.go | 2 +- services/file.service.go | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/mapper/main.go b/mapper/main.go index 2e3193e..54635d7 100644 --- a/mapper/main.go +++ b/mapper/main.go @@ -31,7 +31,7 @@ func MapFileInToFile(file schemas.FileIn) models.File { UserID: file.UserID, ParentID: file.ParentID, Parts: file.Parts, - ChannelID: file.ChannelID, + ChannelID: &file.ChannelID, Status: file.Status, } } diff --git a/schemas/file.schema.go b/schemas/file.schema.go index 6056fab..4c35f47 100644 --- a/schemas/file.schema.go +++ b/schemas/file.schema.go @@ -35,7 +35,7 @@ type FileIn struct { Type string `json:"type" mapstructure:"type,omitempty"` Parts *models.Parts `json:"parts,omitempty" mapstructure:"parts,omitempty"` MimeType string `json:"mimeType" mapstructure:"mime_type,omitempty"` - ChannelID *int64 `json:"channelId,omitempty" mapstructure:"channel_id,omitempty"` + ChannelID int64 `json:"channelId" mapstructure:"channel_id,omitempty"` Path string `json:"path" mapstructure:"path,omitempty"` Size int64 `json:"size" mapstructure:"size,omitempty"` Starred *bool `json:"starred" mapstructure:"starred,omitempty"` diff --git a/services/file.service.go b/services/file.service.go index 235d81b..04e9f37 100644 --- a/services/file.service.go +++ b/services/file.service.go @@ -65,14 +65,18 @@ func (fs *FileService) CreateFile(c *gin.Context) (*schemas.FileOut, *types.AppE fileIn.Depth = utils.IntPointer(len(strings.Split(fileIn.Path, "/")) - 1) } else if fileIn.Type == "file" { fileIn.Path = "" - - channelId, err := GetDefaultChannel(c, userId) - - if err != nil { - return nil, &types.AppError{Error: err, Code: http.StatusInternalServerError} + var channelId int64 + var err error + if fileIn.ChannelID == 0 { + channelId, err = GetDefaultChannel(c, userId) + if err != nil { + return nil, &types.AppError{Error: err, Code: http.StatusInternalServerError} + } + } else { + channelId = fileIn.ChannelID } - fileIn.ChannelID = &channelId + fileIn.ChannelID = channelId } fileIn.UserID = userId