From b35abb2090030e47b255ccfc6a60acde617163fb Mon Sep 17 00:00:00 2001 From: yanghao05 Date: Fri, 25 Apr 2025 16:47:17 +0800 Subject: [PATCH] feat: add frpc --- backend/app/http/posts.go | 10 +++++++++- backend/app/http/routes.gen.go | 3 ++- backend/frpc.toml | 9 +++++++++ frontend/wechat/src/views/ArticleDetail.vue | 8 ++++---- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 backend/frpc.toml diff --git a/backend/app/http/posts.go b/backend/app/http/posts.go index 9ac8414..571cdc9 100644 --- a/backend/app/http/posts.go +++ b/backend/app/http/posts.go @@ -80,6 +80,7 @@ func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *Li } type PostItem struct { + Bought bool `json:"bought"` Title string `json:"title"` Description string `json:"description"` Content string `json:"content"` @@ -94,7 +95,8 @@ type PostItem struct { // Show // @Router /api/posts/:id [get] // @Bind id path -func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) { +// @Bind user local +func (ctl *posts) Show(ctx fiber.Ctx, id int64, user *model.Users) (*PostItem, error) { log.Infof("Fetching post with ID: %d", id) post, err := models.Posts.GetByID(ctx.Context(), id) if err != nil { @@ -102,6 +104,11 @@ func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) { return nil, err } + bought, err := models.Users.HasBought(ctx.Context(), user.ID, post.ID) + if err != nil { + return nil, err + } + medias, err := models.Posts.GetMediaByIds(ctx.Context(), post.HeadImages.Data) if err != nil { return nil, err @@ -125,6 +132,7 @@ func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*PostItem, error) { Likes: post.Likes, Tags: post.Tags.Data, HeadImages: mediaUrls, + Bought: bought, }, nil } diff --git a/backend/app/http/routes.gen.go b/backend/app/http/routes.gen.go index d2934d4..684a8ad 100644 --- a/backend/app/http/routes.gen.go +++ b/backend/app/http/routes.gen.go @@ -58,9 +58,10 @@ func (r *Routes) Register(router fiber.Router) { Local[*model.Users]("user"), )) - router.Get("/api/posts/:id", DataFunc1( + router.Get("/api/posts/:id", DataFunc2( r.posts.Show, PathParam[int64]("id"), + Local[*model.Users]("user"), )) router.Get("/api/posts/:id/play", DataFunc2( diff --git a/backend/frpc.toml b/backend/frpc.toml new file mode 100644 index 0000000..3c9646b --- /dev/null +++ b/backend/frpc.toml @@ -0,0 +1,9 @@ +serverAddr = "39.105.111.158" +serverPort = 1422 + +[[proxies]] +name = "test-http" +type = "tcp" +localIP = "127.0.0.1" +localPort = 8088 +remotePort = 1423 diff --git a/frontend/wechat/src/views/ArticleDetail.vue b/frontend/wechat/src/views/ArticleDetail.vue index 1c28ce1..24a80ce 100644 --- a/frontend/wechat/src/views/ArticleDetail.vue +++ b/frontend/wechat/src/views/ArticleDetail.vue @@ -120,14 +120,14 @@ onUnmounted(() => {
-
-
- ¥{{ article.price }} +
+ ¥{{ (article.price / 100).toFixed(2) }}