syntax = "v1"

import "common.api"

info (
	title:   "聚玩评价服务"
	desc:    "处理订单评价与评分。ID 字段（int64）以 string 传输"
	author:  "Asadz"
	version: "1.0"
)

type (
	ReviewPathId {
		Id int64 `path:"id"`
	}
	Review {
		Id           int64  `json:"id,string"`
		OrderId      int64  `json:"orderId,string"`
		FromUserId   int64  `json:"fromUserId,string"`
		FromUserName string `json:"fromUserName"`
		Rating       int    `json:"rating"`
		Content      string `json:"content"`
		Sealed       bool   `json:"sealed"`
		CreatedAt    string `json:"createdAt"`
	}
	ReviewListResp {
		Items []Review `json:"items"`
		Meta  PageMeta `json:"meta"`
	}
	SubmitReviewReq {
		ReviewPathId
		Rating  int    `json:"rating"`
		Content string `json:"content,optional"`
	}
	GetOrderReviewsReq {
		ReviewPathId
	}
	ListUserReviewsReq {
		ReviewPathId
		PageReq
	}
)

@server (
	prefix: api/v1
	group:  review
)
service review-api {
	@doc "提交评价"
	@handler SubmitReview
	post /orders/:id/review (SubmitReviewReq) returns (EmptyResp)

	@doc "获取订单评价"
	@handler GetOrderReviews
	get /orders/:id/reviews (GetOrderReviewsReq) returns (ReviewListResp)
}

@server (
	prefix: api/v1
	group:  review
)
service review-api {
	@doc "获取公开评价列表"
	@handler ListReviews
	get /reviews (PageReq) returns (ReviewListResp)

	@doc "获取用户收到的评价"
	@handler ListUserReviews
	get /users/:id/reviews (ListUserReviewsReq) returns (ReviewListResp)
}

