mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
feat: remake mocks only on posts
This commit is contained in:
parent
045dcf6fd2
commit
872a6b58df
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -46,12 +46,10 @@
|
||||
<div class="container">
|
||||
<div class="row row-cols-auto gy-4">
|
||||
|
||||
{{range $Thread := .}}
|
||||
{{range $Post := .}}
|
||||
<div class="col col-sm-6 col-md-4 col-lg-3">
|
||||
{{$FirstPost := index $Thread.Posts 0}}
|
||||
|
||||
<div class="card">
|
||||
{{$FirstFile := index $FirstPost.Files 0}}
|
||||
{{$FirstFile := index $Post.Files 0}}
|
||||
|
||||
<img
|
||||
src="{{$FirstFile.Name}}"
|
||||
@ -59,9 +57,9 @@
|
||||
alt="Uploaded picture"
|
||||
>
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{$FirstPost.Title}}</h5>
|
||||
<p class="card-text">{{$FirstPost.Text}}</p>
|
||||
<a href="/{{$Thread.ID}}" class="btn btn-outline-primary">Open</a>
|
||||
<h5 class="card-title">{{$Post.Title}}</h5>
|
||||
<p class="card-text">{{$Post.Text}}</p>
|
||||
<a href="/{{$Post.ID}}" class="btn btn-outline-primary">Open</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user