From 872a6b58dfd6f8575227ca05e3236e53edba65fb Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Tue, 31 Aug 2021 19:48:02 +0300 Subject: [PATCH] feat: remake mocks only on posts --- repositories/mocks.go | 31 +++++++++++------------------- repositories/structs.go | 12 ++++-------- repositories/threads_repository.go | 4 ++-- templates/index.html | 12 +++++------- 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/repositories/mocks.go b/repositories/mocks.go index 4a178bd..2599055 100644 --- a/repositories/mocks.go +++ b/repositories/mocks.go @@ -26,39 +26,30 @@ func getFile(id, postId int, name string) File { } } -func getPost(id, threadID int) Post { +func getPost(id int) Post { return Post{ - ID: id, - ThreadID: threadID, - Title: randSeq(rand.Intn(100)), - Text: randSeq(rand.Intn(100)), - IsSage: false, + ID: id, + IsParent: true, + ParentID: 0, + IsDeleted: false, + Title: randSeq(rand.Intn(100)), + Text: randSeq(rand.Intn(100)), + IsSage: false, Files: []File{ getFile(2, id, "https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png"), getFile(1, id, "https://memepedia.ru/wp-content/uploads/2018/03/ebanyy-rot-etogo-kazino.png"), }, CreatedAt: time.Now(), - } -} - -func getThread(id int) Thread { - return Thread{ - ID: id, - CreatedAt: time.Now(), UpdatedAt: time.Now(), - Posts: []Post{ - getPost(1, id), - getPost(1, id), - }, } } -var ThreadsDb = []Thread{} +var PostsDb = []Post{} func SeedMocks() { rand.Seed(time.Now().UnixNano()) - for i := 1; i < 100; i++ { - ThreadsDb = append(ThreadsDb, getThread(i)) + for i := 1; i < 10; i++ { + PostsDb = append(PostsDb, getPost(i)) } } diff --git a/repositories/structs.go b/repositories/structs.go index 42011f1..f8d3106 100644 --- a/repositories/structs.go +++ b/repositories/structs.go @@ -2,21 +2,17 @@ package repositories import "time" -type Thread struct { - ID int `json:"id"` - CreatedAt time.Time `json:"-"` - UpdatedAt time.Time `json:"-"` - Posts []Post `json:"posts"` -} - type Post struct { ID int `json:"id"` - ThreadID int `json:"-"` + IsParent bool `json:"-"` + ParentID int `json:"parentId"` + IsDeleted bool `json:"-"` Title string `json:"title"` Text string `json:"text"` IsSage bool `json:"isSage"` Files []File `json:"files"` CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"-"` } type File struct { diff --git a/repositories/threads_repository.go b/repositories/threads_repository.go index fe7bd43..7d0d7e0 100644 --- a/repositories/threads_repository.go +++ b/repositories/threads_repository.go @@ -4,7 +4,7 @@ type ThreadsRepository struct{} var Threads ThreadsRepository -func (r *ThreadsRepository) Get(limit, offset int) ([]Thread, error) { +func (r *ThreadsRepository) Get(limit, offset int) ([]Post, error) { // conn, err := Db.Pool.Acquire(context.TODO()) // if err != nil { // return nil, err @@ -76,7 +76,7 @@ func (r *ThreadsRepository) Get(limit, offset int) ([]Thread, error) { // } // rows.Close() - return ThreadsDb, nil + return PostsDb, nil // return nil, nil } diff --git a/templates/index.html b/templates/index.html index d2f1b4d..77a27c4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -46,12 +46,10 @@
- {{range $Thread := .}} + {{range $Post := .}}
- {{$FirstPost := index $Thread.Posts 0}} -
- {{$FirstFile := index $FirstPost.Files 0}} + {{$FirstFile := index $Post.Files 0}} Uploaded picture
-
{{$FirstPost.Title}}
-

{{$FirstPost.Text}}

- Open +
{{$Post.Title}}
+

{{$Post.Text}}

+ Open