fix: parent id get for html template

This commit is contained in:
Yanislav Igonin 2022-02-03 17:22:46 +02:00
parent f4c2f9262e
commit 736be1f461
5 changed files with 9 additions and 7 deletions

View File

@ -320,7 +320,7 @@ func UpdateThread(c *gin.Context) {
} }
post := Repositories.Post{ post := Repositories.Post{
IsParent: false, IsParent: false,
ParentID: threadID, ParentID: &threadID,
Title: "", Title: "",
Text: text, Text: text,
IsSage: isSage, IsSage: isSage,

View File

@ -115,7 +115,8 @@ func (r *PostsRepository) GetThreadByPostID(ID int) ([]Post, error) {
text, text,
is_sage, is_sage,
created_at, created_at,
is_parent is_parent,
parent_id
FROM posts FROM posts
WHERE WHERE
(id = $1 AND is_parent = true AND is_deleted != true) (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.IsSage,
&post.CreatedAt, &post.CreatedAt,
&post.IsParent, &post.IsParent,
&post.ParentID,
) )
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -47,7 +47,7 @@ func getPost(id int, pid *int) Post {
return Post{ return Post{
ID: id, ID: id,
IsParent: isParent, IsParent: isParent,
ParentID: parentID, ParentID: &parentID,
IsDeleted: false, IsDeleted: false,
Title: randSeq(rand.Intn(100)), Title: randSeq(rand.Intn(100)),
Text: randSeq(rand.Intn(100)), Text: randSeq(rand.Intn(100)),

View File

@ -9,7 +9,7 @@ import "time"
type Post struct { type Post struct {
ID int `json:"id"` ID int `json:"id"`
IsParent bool `json:"-"` IsParent bool `json:"-"`
ParentID int `json:"parentId"` ParentID *int `json:"parentId"`
IsDeleted bool `json:"-"` IsDeleted bool `json:"-"`
Title string `json:"title"` Title string `json:"title"`
Text string `json:"text"` Text string `json:"text"`
@ -23,7 +23,7 @@ func (p Post) GetThreadID() int {
if p.IsParent { if p.IsParent {
return p.ID return p.ID
} }
return p.ParentID return *p.ParentID
} }
type File struct { type File struct {

View File

@ -75,11 +75,11 @@ func ValidatePost(title, text string, files []*multipart.FileHeader) string {
return Repositories.InvalidTextOrFilesErrorMessage return Repositories.InvalidTextOrFilesErrorMessage
} }
if len(title) > 100 { if len([]rune(title)) > 100 {
return Repositories.InvalidTitleLengthErrorMessage return Repositories.InvalidTitleLengthErrorMessage
} }
if len(text) > 1000 { if len([]rune(text)) > 1000 {
return Repositories.InvalidTextLengthErrorMessage return Repositories.InvalidTextLengthErrorMessage
} }