Skip to content

Commit

Permalink
Merge branch 'main' into chore/statistics-views
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm authored Oct 16, 2023
2 parents 9ff7f2c + 57774cd commit 26ed7c7
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 321 deletions.
405 changes: 214 additions & 191 deletions server/api/tumdev/campus_backend.pb.go

Large diffs are not rendered by default.

42 changes: 4 additions & 38 deletions server/api/tumdev/campus_backend.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions server/api/tumdev/campus_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ service Campus {

rpc ListNews(ListNewsRequest) returns (ListNewsReply) {
option (google.api.http) = {
get: "/news/{last_news_id}",
get: "/news",
response_body: "news"
};
}
Expand Down Expand Up @@ -240,7 +240,12 @@ message News {
string link = 4;
// where a news thumbnail is stored. empty string means no image is available
string image_url = 5;
string source = 6;
// the id of the news source
string source_id = 6;
// where the icon can be found
string source_icon_url = 9;
// human readable title of the news source
string source_title = 10;
// when the news item was created in OUR database
google.protobuf.Timestamp created = 7;
// the date of the news item
Expand Down
85 changes: 47 additions & 38 deletions server/api/tumdev/campus_backend.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -681,17 +681,17 @@
]
}
},
"/news/alerts": {
"/news": {
"get": {
"operationId": "Campus_ListNewsAlerts",
"operationId": "Campus_ListNews",
"responses": {
"200": {
"description": "",
"schema": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/apiNewsAlert"
"$ref": "#/definitions/apiNews"
}
}
},
Expand All @@ -704,30 +704,46 @@
},
"parameters": [
{
"name": "lastNewsAlertId",
"name": "lastNewsId",
"description": "the last id of the news item received. 0 to get all news items",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "newsSource",
"description": "filter by news source id. 0 to get all news items",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "oldestDateAt",
"description": "the oldest time you want to be included in the response",
"in": "query",
"required": false,
"type": "string",
"format": "date-time"
}
],
"tags": [
"Campus"
]
}
},
"/news/sources": {
"/news/alerts": {
"get": {
"operationId": "Campus_ListNewsSources",
"operationId": "Campus_ListNewsAlerts",
"responses": {
"200": {
"description": "",
"schema": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/apiNewsSource"
"$ref": "#/definitions/apiNewsAlert"
}
}
},
Expand All @@ -738,22 +754,32 @@
}
}
},
"parameters": [
{
"name": "lastNewsAlertId",
"description": "the last id of the news item received. 0 to get all news items",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"tags": [
"Campus"
]
}
},
"/news/{lastNewsId}": {
"/news/sources": {
"get": {
"operationId": "Campus_ListNews",
"operationId": "Campus_ListNewsSources",
"responses": {
"200": {
"description": "",
"schema": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/apiNews"
"$ref": "#/definitions/apiNewsSource"
}
}
},
Expand All @@ -764,32 +790,6 @@
}
}
},
"parameters": [
{
"name": "lastNewsId",
"description": "the last id of the news item received. 0 to get all news items",
"in": "path",
"required": true,
"type": "integer",
"format": "int32"
},
{
"name": "newsSource",
"description": "filter by news source id. 0 to get all news items",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "oldestDateAt",
"description": "the oldest time you want to be included in the response",
"in": "query",
"required": false,
"type": "string",
"format": "date-time"
}
],
"tags": [
"Campus"
]
Expand Down Expand Up @@ -1629,8 +1629,17 @@
"type": "string",
"title": "where a news thumbnail is stored. empty string means no image is available"
},
"source": {
"type": "string"
"sourceId": {
"type": "string",
"title": "the id of the news source"
},
"sourceIconUrl": {
"type": "string",
"title": "where the icon can be found"
},
"sourceTitle": {
"type": "string",
"title": "human readable title of the news source"
},
"created": {
"type": "string",
Expand Down
6 changes: 3 additions & 3 deletions server/backend/cron/feedback_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ func (c *CronService) feedbackEmailCron() error {

var results []model.Feedback
if err := c.db.Find(&results, "processed = false").Scan(&results).Error; err != nil {
log.WithError(err).Fatal("could not get unprocessed feedback")
log.WithError(err).Error("could not get unprocessed feedback")
return err
}
parsedHtmlBody, parsedTxtBody, err := parseTemplates()
if err != nil {
log.WithError(err).Fatal("could not parse email templates")
log.WithError(err).Error("could not parse email templates")
return err
}

Expand Down Expand Up @@ -138,7 +138,7 @@ func (c *CronService) feedbackEmailCron() error {
func setupSMTPDialer() (*gomail.Dialer, error) {
smtpPort, err := strconv.Atoi(os.Getenv("SMTP_PORT"))
if err != nil {
log.WithError(err).Fatal("SMTP_PORT is not an integer")
log.WithError(err).Error("SMTP_PORT is not an integer")
return nil, err
}
d := gomail.NewDialer(os.Getenv("SMTP_URL"), smtpPort, os.Getenv("SMTP_USERNAME"), os.Getenv("SMTP_PASSWORD"))
Expand Down
19 changes: 10 additions & 9 deletions server/backend/cron/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,16 @@ func (c *CronService) parseNewsFeed(source model.NewsSource) error {
}

newsItem := model.News{
Date: *item.PublishedParsed,
Created: time.Now(),
Title: item.Title,
Description: bluemonday.StrictPolicy().Sanitize(item.Description),
Src: source.Source,
Link: item.Link,
Image: enclosureUrl,
FileID: fileID,
File: file,
Date: *item.PublishedParsed,
Created: time.Now(),
Title: item.Title,
Description: bluemonday.StrictPolicy().Sanitize(item.Description),
NewsSourceID: source.Source,
NewsSource: source,
Link: item.Link,
Image: enclosureUrl,
FileID: fileID,
File: file,
}
newNews = append(newNews, newsItem)
}
Expand Down
3 changes: 1 addition & 2 deletions server/backend/movie.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package backend

import (
"context"
"fmt"

pb "github.com/TUM-Dev/Campus-Backend/server/api/tumdev"
"github.com/TUM-Dev/Campus-Backend/server/model"
Expand Down Expand Up @@ -36,7 +35,7 @@ func (s *CampusServer) ListMovies(ctx context.Context, req *pb.ListMoviesRequest
Actors: movie.Actors,
ImdbRating: movie.ImdbRating,
Description: movie.Description,
CoverUrl: fmt.Sprintf("https://api.tum.app/files/%s%s", movie.File.Path, movie.File.Name),
CoverUrl: movie.File.FullExternalUrl(),
CoverId: movie.File.File,
Link: movie.Link,
})
Expand Down
26 changes: 14 additions & 12 deletions server/backend/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *CampusServer) ListNewsSources(ctx context.Context, _ *pb.ListNewsSource
resp = append(resp, &pb.NewsSource{
Source: fmt.Sprintf("%d", source.Source),
Title: source.Title,
IconUrl: fmt.Sprintf("https://api.tum.app/files/%s%s", source.File.Path, source.File.Name),
IconUrl: source.File.FullExternalUrl(),
})
}
return &pb.ListNewsSourcesReply{Sources: resp}, nil
Expand All @@ -45,7 +45,7 @@ func (s *CampusServer) ListNews(ctx context.Context, req *pb.ListNewsRequest) (*
}

var newsEntries []model.News
tx := s.db.WithContext(ctx).Joins("File")
tx := s.db.WithContext(ctx).Joins("File").Joins("NewsSource").Joins("NewsSource.File")
if req.NewsSource != 0 {
tx = tx.Where("src = ?", req.NewsSource)
}
Expand All @@ -65,17 +65,19 @@ func (s *CampusServer) ListNews(ctx context.Context, req *pb.ListNewsRequest) (*
log.WithField("title", item.Title).Trace("sending news")
imgUrl := ""
if item.File != nil {
imgUrl = fmt.Sprintf("https://api.tum.app/files/%s%s", item.File.Path, item.File.Name)
imgUrl = item.File.FullExternalUrl()
}
resp[i] = &pb.News{
Id: item.News,
Title: item.Title,
Text: item.Description,
Link: item.Link,
ImageUrl: imgUrl,
Source: fmt.Sprintf("%d", item.Src),
Created: timestamppb.New(item.Created),
Date: timestamppb.New(item.Date),
Id: item.News,
Title: item.Title,
Text: item.Description,
Link: item.Link,
ImageUrl: imgUrl,
SourceId: fmt.Sprintf("%d", item.NewsSource.Source),
SourceTitle: item.NewsSource.Title,
SourceIconUrl: item.NewsSource.File.FullExternalUrl(),
Created: timestamppb.New(item.Created),
Date: timestamppb.New(item.Date),
}
}
return &pb.ListNewsReply{News: resp}, nil
Expand All @@ -101,7 +103,7 @@ func (s *CampusServer) ListNewsAlerts(ctx context.Context, req *pb.ListNewsAlert
var alerts []*pb.NewsAlert
for _, alert := range res {
alerts = append(alerts, &pb.NewsAlert{
ImageUrl: fmt.Sprintf("https://api.tum.app/files/%s%s", alert.File.Path, alert.File.Name),
ImageUrl: alert.File.FullExternalUrl(),
Link: alert.Link.String,
Created: timestamppb.New(alert.Created),
From: timestamppb.New(alert.From),
Expand Down
Loading

0 comments on commit 26ed7c7

Please sign in to comment.