-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.go
66 lines (56 loc) · 2.17 KB
/
post.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package models
import (
"github.com/google/uuid"
"time"
)
type Post struct {
Id uuid.UUID `gorm:"column:id;primary_key"`
Username string `gorm:"column:username"`
User User `gorm:"foreignKey:username;references:username"`
Content string `gorm:"column:content;type:varchar(256);null"`
ImageUrl string `gorm:"column:image_url;type:varchar(128);null"`
Hashtags []Hashtag `gorm:"many2many:post_hashtags;onDelete:CASCADE"` // gorm handles the join table, onDelete:CASCADE deletes the hashtags if the post is deleted
CreatedAt time.Time `gorm:"column:created_at;not_null"`
LocationId *uuid.UUID `gorm:"column:location_id;null"`
Location Location `gorm:"foreignKey:location_id;references:id"`
}
type PostCreateRequestDTO struct {
Content string `json:"content" binding:"required"`
Location *LocationDTO `json:"location" `
}
type PostResponseDTO struct {
PostId uuid.UUID `json:"postId"`
Author *AuthorDTO `json:"author"`
CreationDate time.Time `json:"creationDate"`
Content string `json:"content"`
Location *LocationDTO `json:"location"`
}
type AuthorDTO struct { // to be used in post response dto
Username string `json:"username"`
Nickname string `json:"nickname"`
ProfilePictureUrl string `json:"profilePictureUrl"`
}
type UserFeedDTO struct { // to be used for response to user feed request
Records []UserFeedRecordDTO `json:"records"`
Pagination *UserFeedPaginationDTO `json:"pagination"`
}
type UserFeedRecordDTO struct {
PostId string `json:"postId"`
CreationDate time.Time `json:"creationDate"`
Content string `json:"content"`
Location *LocationDTO `json:"location"`
}
type UserFeedPaginationDTO struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
Records int64 `json:"records"`
}
type GeneralFeedDTO struct { // to be used for response to general feed request
Records []PostResponseDTO `json:"records"`
Pagination *GeneralFeedPaginationDTO `json:"pagination"`
}
type GeneralFeedPaginationDTO struct {
LastPostId string `json:"lastPostId"`
Limit int `json:"limit"`
Records int64 `json:"records"`
}