You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.2 KiB

  1. package shows
  2. import (
  3. "context"
  4. "github.com/gogf/gf/v2/frame/g"
  5. "practice_Go/internal/dao"
  6. "practice_Go/internal/model/do"
  7. "practice_Go/internal/model/entity"
  8. "practice_Go/internal/service"
  9. )
  10. func init() {
  11. //GoFrame没有自动注册, 将sShow结构体的实例注册到服务中, 供其他部分访问
  12. service.RegisterShows(&sShow{}) //GoFrame没有自动注册 另外还需要在logic包下创建一个logic.go文件,并在其中导入本文件所在的shows包
  13. }
  14. // 定义一个sShow结构体,供其他部分访问下面的方法
  15. type sShow struct{}
  16. // 定义一个方法,用于获取所有节目
  17. func (s sShow) GetShows(ctx context.Context) (shows []entity.GoShows, err error) {
  18. // 使用dao包中的GoShows结构体,在指定的上下文中扫描数据,并将结果存储在shows变量中
  19. flagType := g.RequestFromCtx(ctx).Get("flagType").Int()
  20. if flagType != 0 {
  21. err = dao.GoShows.Ctx(ctx).With(entity.GoUsers{}, entity.GoClubs{}).Where("flag_type", flagType).Scan(&shows) //err用于存储过程中可能出现的错误,结果直接存到shows中了
  22. } else {
  23. err = dao.GoShows.Ctx(ctx).With(entity.GoUsers{}).With(entity.GoClubs{}).Scan(&shows)
  24. }
  25. // 返回结果
  26. return
  27. }
  28. // 定义一个方法,用于获取视频列表
  29. func (s sShow) GetVideos(ctx context.Context) (videos []entity.GoShows, err error) {
  30. // 使用dao包中的GoShows结构体,在指定的上下文中扫描视频列表
  31. flagType := g.RequestFromCtx(ctx).Get("flagType").Int()
  32. if flagType != 0 {
  33. err = dao.GoShows.Ctx(ctx).With(entity.GoUsers{}, entity.GoClubs{}).Where("flag_type", flagType).OrderDesc("release_time").Scan(&videos) //err用于存储过程中可能出现的错误,结果直接存到shows中了
  34. } else {
  35. err = dao.GoShows.Ctx(ctx).With(entity.GoUsers{}).With(entity.GoClubs{}).OrderDesc("release_time").Scan(&videos)
  36. }
  37. // 返回视频列表和错误信息
  38. return
  39. }
  40. func (s sShow) AddShow(ctx context.Context, show do.GoShows) (err error) {
  41. //TODO implement me
  42. panic("implement me")
  43. }
  44. func (s sShow) EditShow(ctx context.Context, show do.GoShows) (err error) {
  45. //TODO implement me
  46. panic("implement me")
  47. }
  48. func (s sShow) DeleteShow(ctx context.Context) (err error) {
  49. //TODO implement me
  50. panic("implement me")
  51. }