diff --git a/controllers/threads_controller.go b/controllers/threads_controller.go index c622b07..e930d14 100644 --- a/controllers/threads_controller.go +++ b/controllers/threads_controller.go @@ -320,7 +320,7 @@ func UpdateThread(c *gin.Context) { } post := Repositories.Post{ IsParent: false, - ParentID: threadID, + ParentID: &threadID, Title: "", Text: text, IsSage: isSage, diff --git a/repositories/posts_repository.go b/repositories/posts_repository.go index 9edebcd..77e625f 100644 --- a/repositories/posts_repository.go +++ b/repositories/posts_repository.go @@ -115,7 +115,8 @@ func (r *PostsRepository) GetThreadByPostID(ID int) ([]Post, error) { text, is_sage, created_at, - is_parent + is_parent, + parent_id FROM posts WHERE (id = $1 AND is_parent = true AND is_deleted != true) @@ -142,6 +143,7 @@ func (r *PostsRepository) GetThreadByPostID(ID int) ([]Post, error) { &post.IsSage, &post.CreatedAt, &post.IsParent, + &post.ParentID, ) if err != nil { return nil, err diff --git a/repositories/seeds.go b/repositories/seeds.go index bc9bed8..e2b7be1 100644 --- a/repositories/seeds.go +++ b/repositories/seeds.go @@ -47,7 +47,7 @@ func getPost(id int, pid *int) Post { return Post{ ID: id, IsParent: isParent, - ParentID: parentID, + ParentID: &parentID, IsDeleted: false, Title: randSeq(rand.Intn(100)), Text: randSeq(rand.Intn(100)), diff --git a/repositories/structs.go b/repositories/structs.go index c00c149..121f908 100644 --- a/repositories/structs.go +++ b/repositories/structs.go @@ -9,7 +9,7 @@ import "time" type Post struct { ID int `json:"id"` IsParent bool `json:"-"` - ParentID int `json:"parentId"` + ParentID *int `json:"parentId"` IsDeleted bool `json:"-"` Title string `json:"title"` Text string `json:"text"` @@ -23,7 +23,7 @@ func (p Post) GetThreadID() int { if p.IsParent { return p.ID } - return p.ParentID + return *p.ParentID } type File struct { diff --git a/utils/utils.go b/utils/utils.go index 503333d..e00a325 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -75,11 +75,11 @@ func ValidatePost(title, text string, files []*multipart.FileHeader) string { return Repositories.InvalidTextOrFilesErrorMessage } - if len(title) > 100 { + if len([]rune(title)) > 100 { return Repositories.InvalidTitleLengthErrorMessage } - if len(text) > 1000 { + if len([]rune(text)) > 1000 { return Repositories.InvalidTextLengthErrorMessage }