From 574bebf92bd5aa046e8850001f7735d4a6d00180 Mon Sep 17 00:00:00 2001 From: deancn Date: Sat, 12 Mar 2022 20:08:25 +0800 Subject: [PATCH 1/2] update --- internal/controller/lost.go | 29 +++++++++++++++++++++++++++++ pkg/schema/vo_lost.go | 19 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/internal/controller/lost.go b/internal/controller/lost.go index 6968597..693cfbe 100644 --- a/internal/controller/lost.go +++ b/internal/controller/lost.go @@ -31,6 +31,7 @@ func (c LostController) Routes() chi.Router { r := chi.NewRouter() r.Get("/", c.List) + r.Post("/create", c.Create) r.Get("/{lost_id}", c.Show) r.Get("/{lost_id}/share/{share_key}/callback", c.ShareCallback) r.Get("/{lost_id}/"+aggregate.LOST_WXMP_CODE_FILENAME, c.GetMpCode) @@ -120,6 +121,34 @@ func (c LostController) Show(w http.ResponseWriter, r *http.Request) { render.JSON(w, r, resp) } +// LostCreate +// @Summary 新建失踪信息 +// @Description 失踪信息 详情。 +// @Tags lost +// @Accept json +// @Produce json +// @Param schema.LostCreateReq body schema.LostCreateReq true "body" +// @Success 200 {object} schema.LostGetResponse +// @Router /v1/lost/create [post] +func (c LostController) Create(w http.ResponseWriter, r *http.Request) { + resp := schema.LostGetResponse{ + Success: false, + } + + // Todo: 保存失踪信息。 + item, err := c.aggr.Losts().GetByID(r.Context(), uint(1)) + if err != nil { + log.Println(err) + + return + } + + resp.Success = true + resp.Data = item + + render.JSON(w, r, resp) +} + // [TODO] LostShareCallback // @Summary 失踪信息 分享后回传 // @Description 分享后回传,通过缓存+IP+Key来去重。share_key为详情页中 wx_more 里的 share_key. diff --git a/pkg/schema/vo_lost.go b/pkg/schema/vo_lost.go index 258ed4c..193be7f 100644 --- a/pkg/schema/vo_lost.go +++ b/pkg/schema/vo_lost.go @@ -27,6 +27,25 @@ type LostGetResponse struct { Success bool `json:"success"` } +type LostCreateReq struct { + Name string `json:"name"` + Sex uint `json:"sex"` + Age int `json:"age"` + AddressDetails string `json:"address_details"` + MissedProvince string `json:"missed_province"` + MissedCity string `json:"missed_city"` + BirthedAt uint `json:"birthed_at"` + MissedAt uint `json:"missed_at"` + Character uint `json:"character"` + Height uint `json:"height"` + DataFrom string `json:"data_from"` + Follower string `json:"follower"` + Imgs []string `json:"imgs"` +} + +type LostCreateResp struct { +} + type LostMpCode struct { } From ca42039d02574bbe5b143bb09764e97e2f855c2f Mon Sep 17 00:00:00 2001 From: deancn Date: Sat, 12 Mar 2022 20:15:28 +0800 Subject: [PATCH 2/2] update --- internal/controller/lost.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/lost.go b/internal/controller/lost.go index 693cfbe..ba0b090 100644 --- a/internal/controller/lost.go +++ b/internal/controller/lost.go @@ -136,7 +136,7 @@ func (c LostController) Create(w http.ResponseWriter, r *http.Request) { } // Todo: 保存失踪信息。 - item, err := c.aggr.Losts().GetByID(r.Context(), uint(1)) + item, err := c.aggr.Losts().GetByID(r.Context(), uint(5)) if err != nil { log.Println(err)