feat(auth): add mini program test code endpoint (#51)
This commit is contained in:
@@ -155,6 +155,11 @@ type updateProfileRequest struct {
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
}
|
||||
|
||||
type miniProgramCodeQuery struct {
|
||||
Path string `form:"path"`
|
||||
Width int `form:"width"`
|
||||
}
|
||||
|
||||
func (h *AuthHandler) UpdateProfile(c *gin.Context) {
|
||||
user := middleware.MustCurrentUser(c)
|
||||
|
||||
@@ -181,3 +186,23 @@ func (h *AuthHandler) UpdateProfile(c *gin.Context) {
|
||||
"avatar_url": updated.AvatarURL,
|
||||
}))
|
||||
}
|
||||
|
||||
func (h *AuthHandler) GetMiniProgramTestCode(c *gin.Context) {
|
||||
user := middleware.MustCurrentUser(c)
|
||||
|
||||
var query miniProgramCodeQuery
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
codeBytes, err := h.authService.GetMiniProgramTestCode(c.Request.Context(), user.ID, query.Path, query.Width)
|
||||
if err != nil {
|
||||
log.Printf("[get_mini_program_test_code] error: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取小程序码失败"))
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Cache-Control", "no-store")
|
||||
c.Data(http.StatusOK, "image/png", codeBytes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user