From dac40642e5dae25678451f111c597f46c59f328a Mon Sep 17 00:00:00 2001 From: lareii Date: Sat, 14 Sep 2024 22:57:03 +0300 Subject: [PATCH] feat(server): add role field to user models --- server/handlers/auth/feed.go | 1 + server/handlers/auth/me.go | 1 - server/handlers/auth/update.go | 1 - server/handlers/comments/create_comment.go | 1 + server/handlers/posts/get_post.go | 1 + server/handlers/posts/get_post_comments.go | 1 + server/handlers/posts/get_posts.go | 1 + server/handlers/users/follows.go | 1 - server/handlers/users/get_user.go | 1 - server/handlers/users/get_user_posts.go | 1 + server/handlers/users/get_users.go | 1 - server/models/comment.go | 1 + server/models/post.go | 1 + 13 files changed, 8 insertions(+), 5 deletions(-) diff --git a/server/handlers/auth/feed.go b/server/handlers/auth/feed.go index 0d55a54..ae04aa1 100644 --- a/server/handlers/auth/feed.go +++ b/server/handlers/auth/feed.go @@ -62,6 +62,7 @@ func GetFeed(c *fiber.Ctx) error { Author: models.PostResponseAuthor{ ID: author.ID, CreatedAt: author.CreatedAt, + Role: author.Role, DisplayName: author.DisplayName, Username: author.Username, About: author.About, diff --git a/server/handlers/auth/me.go b/server/handlers/auth/me.go index c4195d9..3fc0ddf 100644 --- a/server/handlers/auth/me.go +++ b/server/handlers/auth/me.go @@ -13,7 +13,6 @@ func User(c *fiber.Ctx) error { }) } - user.Role = "" user.Password = "" return c.Status(fiber.StatusOK).JSON(fiber.Map{ diff --git a/server/handlers/auth/update.go b/server/handlers/auth/update.go index 1f86237..6a63f54 100644 --- a/server/handlers/auth/update.go +++ b/server/handlers/auth/update.go @@ -95,7 +95,6 @@ func UpdateUser(c *fiber.Ctx) error { }) } - updatedUser.Role = "" updatedUser.Password = "" return c.JSON(fiber.Map{ diff --git a/server/handlers/comments/create_comment.go b/server/handlers/comments/create_comment.go index 278f56f..5aff680 100644 --- a/server/handlers/comments/create_comment.go +++ b/server/handlers/comments/create_comment.go @@ -69,6 +69,7 @@ func CreateComment(c *fiber.Ctx) error { Author: models.CommentResponseAuthor{ ID: user.ID, CreatedAt: user.CreatedAt, + Role: user.Role, DisplayName: user.DisplayName, Username: user.Username, About: user.About, diff --git a/server/handlers/posts/get_post.go b/server/handlers/posts/get_post.go index 063d6c4..7c14dde 100644 --- a/server/handlers/posts/get_post.go +++ b/server/handlers/posts/get_post.go @@ -39,6 +39,7 @@ func GetPost(c *fiber.Ctx) error { ID: author.ID, CreatedAt: author.CreatedAt, DisplayName: author.DisplayName, + Role: author.Role, Username: author.Username, About: author.About, Points: author.Points, diff --git a/server/handlers/posts/get_post_comments.go b/server/handlers/posts/get_post_comments.go index 54bec2f..8198a7f 100644 --- a/server/handlers/posts/get_post_comments.go +++ b/server/handlers/posts/get_post_comments.go @@ -58,6 +58,7 @@ func GetPostComments(c *fiber.Ctx) error { Author: models.CommentResponseAuthor{ ID: author.ID, CreatedAt: author.CreatedAt, + Role: author.Role, DisplayName: author.DisplayName, Username: author.Username, About: author.About, diff --git a/server/handlers/posts/get_posts.go b/server/handlers/posts/get_posts.go index af314a9..f01aa53 100644 --- a/server/handlers/posts/get_posts.go +++ b/server/handlers/posts/get_posts.go @@ -51,6 +51,7 @@ func GetPosts(c *fiber.Ctx) error { ID: author.ID, CreatedAt: author.CreatedAt, DisplayName: author.DisplayName, + Role: author.Role, Username: author.Username, About: author.About, Points: author.Points, diff --git a/server/handlers/users/follows.go b/server/handlers/users/follows.go index 835b6a9..09e66c6 100644 --- a/server/handlers/users/follows.go +++ b/server/handlers/users/follows.go @@ -49,7 +49,6 @@ func Follows(c *fiber.Ctx) error { var responseUsers []models.User for _, user := range users { - user.Role = "" user.Email = "" user.Password = "" diff --git a/server/handlers/users/get_user.go b/server/handlers/users/get_user.go index d39d05f..97c660f 100644 --- a/server/handlers/users/get_user.go +++ b/server/handlers/users/get_user.go @@ -19,7 +19,6 @@ func GetUser(c *fiber.Ctx) error { }) } - user.Role = "" user.Email = "" user.Password = "" diff --git a/server/handlers/users/get_user_posts.go b/server/handlers/users/get_user_posts.go index 6191a18..dfeec70 100644 --- a/server/handlers/users/get_user_posts.go +++ b/server/handlers/users/get_user_posts.go @@ -39,6 +39,7 @@ func GetUserPosts(c *fiber.Ctx) error { Author: models.PostResponseAuthor{ ID: user.ID, CreatedAt: user.CreatedAt, + Role: user.Role, DisplayName: user.DisplayName, Username: user.Username, About: user.About, diff --git a/server/handlers/users/get_users.go b/server/handlers/users/get_users.go index 851f784..0db7d62 100644 --- a/server/handlers/users/get_users.go +++ b/server/handlers/users/get_users.go @@ -19,7 +19,6 @@ func GetUsers(c *fiber.Ctx) error { var responseUsers []models.User for _, user := range users { - user.Role = "" user.Email = "" user.Password = "" diff --git a/server/models/comment.go b/server/models/comment.go index 9a1c693..1db61b9 100644 --- a/server/models/comment.go +++ b/server/models/comment.go @@ -39,6 +39,7 @@ type CommentResponseContent struct { type CommentResponseAuthor struct { ID primitive.ObjectID `json:"id"` CreatedAt primitive.Timestamp `json:"created_at"` + Role string `json:"role"` DisplayName string `json:"display_name"` Username string `json:"username"` About string `json:"about,omitempty"` diff --git a/server/models/post.go b/server/models/post.go index 6be4657..a94980e 100644 --- a/server/models/post.go +++ b/server/models/post.go @@ -39,6 +39,7 @@ type PostResponseContent struct { type PostResponseAuthor struct { ID primitive.ObjectID `json:"id"` CreatedAt primitive.Timestamp `json:"created_at"` + Role string `json:"role"` DisplayName string `json:"display_name"` Username string `json:"username"` About string `json:"about,omitempty"`