Skip to content

Commit

Permalink
renamed GetTopNews -> GetTopNewsAlert
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Sep 12, 2023
1 parent b6c2e3c commit 8262664
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 75 deletions.
37 changes: 23 additions & 14 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.

11 changes: 8 additions & 3 deletions server/api/tumdev/campus_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

service Campus {
rpc GetTopNews (google.protobuf.Empty) returns (GetTopNewsReply) {
rpc GetTopNewsAlert (google.protobuf.Empty) returns (GetTopNewsAlertReply) {
option (google.api.http) = {
get: "/news/top"
get: "/news/alerts/top"
response_body: "alert"
};
}

Expand Down Expand Up @@ -386,7 +387,11 @@ message NewsSource {
string icon = 3;
}

message GetTopNewsReply {
message GetTopNewsAlertReply {
NewsAlert alert = 1;
}

message NewsAlert {
string image_url = 1;
string link = 2;
google.protobuf.Timestamp created = 3;
Expand Down
66 changes: 37 additions & 29 deletions server/api/tumdev/campus_backend.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -835,18 +835,14 @@
]
}
},
"/news/sources": {
"/news/alerts/top": {
"get": {
"operationId": "Campus_GetNewsSources",
"operationId": "Campus_GetTopNewsAlert",
"responses": {
"200": {
"description": "",
"schema": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/apiNewsSource"
}
"$ref": "#/definitions/apiNewsAlert"
}
},
"default": {
Expand All @@ -861,14 +857,18 @@
]
}
},
"/news/top": {
"/news/sources": {
"get": {
"operationId": "Campus_GetTopNews",
"operationId": "Campus_GetNewsSources",
"responses": {
"200": {
"description": "A successful response.",
"description": "",
"schema": {
"$ref": "#/definitions/apiGetTopNewsReply"
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/apiNewsSource"
}
}
},
"default": {
Expand Down Expand Up @@ -1706,26 +1706,11 @@
}
}
},
"apiGetTopNewsReply": {
"apiGetTopNewsAlertReply": {
"type": "object",
"properties": {
"imageUrl": {
"type": "string"
},
"link": {
"type": "string"
},
"created": {
"type": "string",
"format": "date-time"
},
"from": {
"type": "string",
"format": "date-time"
},
"to": {
"type": "string",
"format": "date-time"
"alert": {
"$ref": "#/definitions/apiNewsAlert"
}
}
},
Expand Down Expand Up @@ -1911,6 +1896,29 @@
}
}
},
"apiNewsAlert": {
"type": "object",
"properties": {
"imageUrl": {
"type": "string"
},
"link": {
"type": "string"
},
"created": {
"type": "string",
"format": "date-time"
},
"from": {
"type": "string",
"format": "date-time"
},
"to": {
"type": "string",
"format": "date-time"
}
}
},
"apiNewsSource": {
"type": "object",
"properties": {
Expand Down
28 changes: 14 additions & 14 deletions server/api/tumdev/campus_backend_grpc.pb.go

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

25 changes: 24 additions & 1 deletion server/backend/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,30 @@ func (s *CampusServer) GetNewsSources(ctx context.Context, _ *emptypb.Empty) (ne
return &pb.NewsSourceReply{Sources: resp}, nil
}

func (s *CampusServer) GetTopNews(ctx context.Context, _ *emptypb.Empty) (*pb.GetTopNewsReply, error) {
func (s *CampusServer) GetTopNewsAlert(ctx context.Context, _ *emptypb.Empty) (*pb.GetTopNewsAlertReply, error) {
if err := s.checkDevice(ctx); err != nil {
return nil, err
}

var res *model.NewsAlert
err := s.db.Joins("Files").Where("NOW() between `from` and `to`").First(&res).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, "no currenty active top news")
} else if err != nil {
log.WithError(err).Error("could not GetTopNewsAlert")
return nil, status.Error(codes.Internal, "could not GetTopNewsAlert")
}

return &pb.GetTopNewsAlertReply{Alert: &pb.NewsAlert{
ImageUrl: res.Files.URL.String,
Link: res.Link.String,
Created: timestamppb.New(res.Created),
From: timestamppb.New(res.From),
To: timestamppb.New(res.To),
}}, nil
}

func (s *CampusServer) GetNewsAlerts(ctx context.Context, _ *pb.GetNewsAlertsRequest) (*pb.GetNewsAlertsReply, error) {
if err := s.checkDevice(ctx); err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 8262664

Please sign in to comment.