picture.go 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package app
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "lcfns/global"
  6. "lcfns/model/app"
  7. "lcfns/model/common/response"
  8. )
  9. type PictureApi struct {
  10. }
  11. func (pa *PictureApi) GetPicture(c *gin.Context) {
  12. code := c.Query("eventCode")
  13. var dataId int
  14. err := global.Db.Select("p.data_id").
  15. Table("event e JOIN picture p ON e.id = p.event_id").
  16. Where("e.event_code = ?", code).
  17. Find(&dataId).Error
  18. if err != nil {
  19. logrus.Error(err)
  20. response.Fail(c)
  21. return
  22. }
  23. var picData app.PictureData
  24. err = global.Db.Select("id, data").
  25. Model(&app.PictureData{}).
  26. Where("id = ?", dataId).
  27. Find(&picData).Error
  28. if err != nil {
  29. logrus.Error(err)
  30. response.Fail(c)
  31. return
  32. }
  33. c.Header("Content-Type", "image/jpeg;charset=UTF-8")
  34. //_, err = c.Writer.Write(picData.Data)
  35. //if err != nil {
  36. // logrus.Error(err)
  37. // response.FailWithMessage("获取失败", c)
  38. // return
  39. //}
  40. response.OkWithDetailed(picData.Data, "获取成功", c)
  41. }