package core

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/api/client"
	"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
)

type ListNoticeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListNoticeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListNoticeLogic {
	return &ListNoticeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListNoticeLogic) ListNotice(req *clientCore.ListNoticeReq) (*clientCore.ListNoticeResp, error) {
	var notices []clientCore.NoticeInfo

	var resp clientCore.ListNoticeResp

	l.svcCtx.DbEngin.Raw("select * from t_notice order by created_time desc").Scan(&notices)
	for _, notice := range notices {
		resp.Data = append(resp.Data, notice)
	}
	resp.Code = 200
	resp.Msg = "success"
	return &resp, nil
}
