admin dcf9b4bcbf
All checks were successful
continuous-integration/drone/push Build is passing
v0.0.33 Уведомления о лайках
2025-09-18 10:13:33 +03:00

104 lines
3.5 KiB
Go

package domain
import (
"time"
)
// Пользователь
type User struct {
ID int `json:"id"`
Username string `json:"username"`
Avatar string `json:"avatar"`
Email string `json:"email"`
EmailConfirmationToken string `json:"-"`
EmailConfirmedAt *time.Time `json:"emailConfirmedAt,omitempty"`
Password string `json:"-"` // Пароль не должен возвращаться в ответах
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Пост в блоге
type Post struct {
ID int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
AuthorID int `json:"authorId"`
Author *User `json:"author,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Комментарий к посту
type Comment struct {
ID int `json:"id"`
Content string `json:"content"`
PostID int `json:"postId"`
AuthorID int `json:"authorId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
// Лайк к посту
type Like struct {
ID int `json:"id"`
PostID int `json:"postId"`
UserID int `json:"userId"`
CreatedAt time.Time `json:"createdAt"`
IsRead bool `json:"isRead"`
NotifiedAt time.Time `json:"notifiedAt"`
}
type LikeNotification struct {
ID int `json:"id"`
LikerID int `json:"-"` // Для внутреннего использования
Liker *User `json:"liker"` // Для GraphQL
LikerUsername string `json:"likerUsername"` // Добавьте это поле
LikerAvatar string `json:"likerAvatar"` // Добавьте это поле
PostID int `json:"-"` // Для внутреннего использования
Post *Post `json:"post"` // Для GraphQL
PostTitle string `json:"postTitle"` // Добавьте это поле
PostAuthorID int `json:"postAuthorId"` // Добавьте это поле
IsRead bool `json:"isRead"`
CreatedAt time.Time `json:"-"`
CreatedAtStr string `json:"createdAt"` // Для GraphQL
}
// Вспомогательные методы
func (n *LikeNotification) SetLiker(user *User) {
n.Liker = user
n.LikerID = user.ID
n.LikerUsername = user.Username // Добавьте эту строку
n.LikerAvatar = user.Avatar // Добавьте эту строку
}
func (n *LikeNotification) SetPost(post *Post) {
n.Post = post
n.PostID = post.ID
n.PostTitle = post.Title // Добавьте эту строку
n.PostAuthorID = post.AuthorID // Добавьте эту строку
}
func (n *LikeNotification) SetCreatedAtStr() {
n.CreatedAtStr = n.CreatedAt.Format(time.RFC3339)
}
// Токены для аутентификации
type Tokens struct {
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
AccessTokenExpires time.Time `json:"accessTokenExpires"`
RefreshTokenExpires time.Time `json:"refreshTokenExpires"`
EmailConfirmed bool `json:"emailConfirmed"`
}
type RegisterInput struct {
Username string `json:"username"`
Email string `json:"email"`
Password string `json:"password"`
}
type LoginInput struct {
Email string `json:"email"`
Password string `json:"password"`
}