From 07cb675397dc568c3b3b3477273e1f60013b92e1 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 18 Sep 2023 19:16:07 +0200 Subject: [PATCH] fixed wrong naming --- server/backend/news.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/backend/news.go b/server/backend/news.go index c090dfdd..49155cf2 100644 --- a/server/backend/news.go +++ b/server/backend/news.go @@ -14,9 +14,9 @@ import ( "google.golang.org/protobuf/types/known/emptypb" ) -func (s *CampusServer) GetNewsSources(ctx context.Context, _ *emptypb.Empty) (newsSources *pb.NewsSourceReply, err error) { - if err = s.checkDevice(ctx); err != nil { - return +func (s *CampusServer) GetNewsSources(ctx context.Context, _ *emptypb.Empty) (*pb.NewsSourceReply, error) { + if err := s.checkDevice(ctx); err != nil { + return nil, err } var sources []model.NewsSource @@ -37,12 +37,12 @@ func (s *CampusServer) GetNewsSources(ctx context.Context, _ *emptypb.Empty) (ne return &pb.NewsSourceReply{Sources: resp}, nil } -func (s *CampusServer) GetNews(ctx context.Context, req *pb.GetNewsRequest) (newsSources *pb.GetNewsReply, err error) { - if err = s.checkDevice(ctx); err != nil { - return +func (s *CampusServer) GetNews(ctx context.Context, req *pb.GetNewsRequest) (*pb.GetNewsReply, error) { + if err := s.checkDevice(ctx); err != nil { + return nil, err } - var sources []model.News + var newsEntries []model.News // preloading files as the news images can be null // I could not get outer joins to work => we are currently doing unnecessary db calls tx := s.db.Preload("Files") @@ -52,13 +52,13 @@ func (s *CampusServer) GetNews(ctx context.Context, req *pb.GetNewsRequest) (new if req.LastNewsId != 0 { tx = tx.Where("news > ?", req.LastNewsId) } - if err := tx.Find(&sources).Error; err != nil { + if err := tx.Find(&newsEntries).Error; err != nil { log.WithError(err).Error("could not find news item") return nil, status.Error(codes.Internal, "could not GetNews") } - resp := make([]*pb.NewsItem, len(sources)) - for i, item := range sources { + resp := make([]*pb.NewsItem, len(newsEntries)) + for i, item := range newsEntries { log.WithField("title", item.Title).Trace("sending news") resp[i] = &pb.NewsItem{ Id: item.News,