feat: 添加搜索收藏微服务

This commit is contained in:
zetaloop
2026-04-24 13:24:58 +08:00
parent 91fdd2a498
commit 53d0e791b4
58 changed files with 6239 additions and 57 deletions
+65 -56
View File
@@ -1,72 +1,81 @@
syntax = "v1"
import "common.api"
type (
PathIDReq {
Id int64 `path:"id"`
}
SearchReq {
PageReq
Q string `form:"q"`
MinPrice float64 `form:"min,optional"`
MaxPrice float64 `form:"max,optional"`
OnlyOnline bool `form:"onlyOnline,optional"`
Sort string `form:"sort,optional"`
}
SearchResp {
Items []interface{} `json:"items"` // Mixed items
Meta PageMeta `json:"meta"`
}
FavoriteReq {
TargetType string `json:"targetType"` // player, shop
TargetId int64 `json:"targetId"`
}
FavoriteCheckReq {
PathIDReq
TargetType string `form:"targetType"`
TargetId int64 `form:"targetId"`
}
FavoriteCheckResp {
Favorited bool `json:"favorited"`
}
PathIDReq {
Id int64 `path:"id"`
}
SearchReq {
PageReq
Q string `form:"q,optional"`
MinPrice float64 `form:"min,optional"`
MaxPrice float64 `form:"max,optional"`
OnlyOnline bool `form:"onlyOnline,optional"`
Sort string `form:"sort,optional"`
}
SearchResp {
Items []interface{} `json:"items"` // Mixed items
Meta PageMeta `json:"meta"`
}
Favorite {
Id string `json:"id"`
UserId string `json:"userId"`
TargetType string `json:"targetType"`
TargetId string `json:"targetId"`
CreatedAt string `json:"createdAt"`
}
FavoriteListResp {
Items []Favorite `json:"items"`
Meta PageMeta `json:"meta"`
}
FavoriteReq {
TargetType string `json:"targetType"` // player, shop
TargetId string `json:"targetId"`
}
FavoriteCheckReq {
PathIDReq
TargetType string `form:"targetType"`
TargetId string `form:"targetId"`
}
FavoriteCheckResp {
Favorited bool `json:"favorited"`
}
)
@server(
prefix: api/v1
group: search
@server (
prefix: api/v1
group: search
)
service search-api {
@doc "统一搜索"
@handler Search
get /search (SearchReq) returns (SearchResp)
@doc "统一搜索"
@handler Search
get /search (SearchReq) returns (SearchResp)
@doc "首页推荐"
@handler Recommendations
get /recommendations/home (PageReq) returns (SearchResp)
@doc "首页推荐"
@handler Recommendations
get /recommendations/home (PageReq) returns (SearchResp)
}
@server(
prefix: api/v1
group: favorites
@server (
prefix: api/v1
group: favorites
)
service search-api {
@doc "获取收藏列表"
@handler ListFavorites
get /favorites (PageReq) returns (SearchResp)
@doc "获取收藏列表"
@handler ListFavorites
get /favorites (PageReq) returns (FavoriteListResp)
@doc "添加收藏"
@handler AddFavorite
post /favorites (FavoriteReq) returns (EmptyResp)
@doc "添加收藏"
@handler AddFavorite
post /favorites (FavoriteReq) returns (EmptyResp)
@doc "取消收藏"
@handler RemoveFavorite
delete /favorites/:id (PathIDReq) returns (EmptyResp)
@doc "取消收藏"
@handler RemoveFavorite
delete /favorites/:id (PathIDReq) returns (EmptyResp)
@doc "检查收藏状态"
@handler CheckFavorite
get /users/:id/favorites/check (FavoriteCheckReq) returns (FavoriteCheckResp)
}
@doc "检查收藏状态"
@handler CheckFavorite
get /users/:id/favorites/check (FavoriteCheckReq) returns (FavoriteCheckResp)
}
+67
View File
@@ -0,0 +1,67 @@
syntax = "proto3";
option go_package ="./pb";
package pb;
// ------------------------------------
// Messages
// ------------------------------------
//--------------------------------favorites--------------------------------
message Favorites {
int64 id = 1;
int64 userId = 2;
string targetType = 3;
int64 targetId = 4;
int64 createdAt = 5;
}
message AddFavoritesReq {
int64 userId = 1;
string targetType = 2;
int64 targetId = 3;
}
message AddFavoritesResp {
int64 id = 1;
}
message DelFavoritesReq {
int64 id = 1;
}
message DelFavoritesResp {
}
message GetFavoritesByIdReq {
int64 id = 1;
}
message GetFavoritesByIdResp {
Favorites favorites = 1;
}
message SearchFavoritesReq {
int64 offset = 1;
int64 limit = 2;
optional int64 id = 3;
optional int64 userId = 4;
optional string targetType = 5;
optional int64 targetId = 6;
}
message SearchFavoritesResp {
repeated Favorites favorites = 1;
}
// ------------------------------------
// Rpc Func
// ------------------------------------
service searchService {
rpc AddFavorites(AddFavoritesReq) returns (AddFavoritesResp);
rpc DelFavorites(DelFavoritesReq) returns (DelFavoritesResp);
rpc GetFavoritesById(GetFavoritesByIdReq) returns (GetFavoritesByIdResp);
rpc SearchFavorites(SearchFavoritesReq) returns (SearchFavoritesResp);
}