feat:#44 updated grpc and function for error handling

This commit is contained in:
Elmar Kresse
2024-07-13 19:18:14 +02:00
parent 5f713c4dff
commit c0e09c47bf
8 changed files with 36 additions and 17 deletions

View File

@ -30,6 +30,7 @@ type Feed struct {
Retrieved string `protobuf:"bytes,3,opt,name=retrieved,proto3" json:"retrieved,omitempty"`
Created string `protobuf:"bytes,4,opt,name=created,proto3" json:"created,omitempty"`
Updated string `protobuf:"bytes,5,opt,name=updated,proto3" json:"updated,omitempty"`
Deleted bool `protobuf:"varint,6,opt,name=deleted,proto3" json:"deleted,omitempty"`
}
func (x *Feed) Reset() {
@ -99,6 +100,13 @@ func (x *Feed) GetUpdated() string {
return ""
}
func (x *Feed) GetDeleted() bool {
if x != nil {
return x.Deleted
}
return false
}
type GetFeedRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -196,7 +204,7 @@ func (x *GetFeedResponse) GetFeed() *Feed {
var File_feeds_proto protoreflect.FileDescriptor
var file_feeds_proto_rawDesc = []byte{
0x0a, 0x0b, 0x66, 0x65, 0x65, 0x64, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x82, 0x01,
0x0a, 0x0b, 0x66, 0x65, 0x65, 0x64, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x9c, 0x01,
0x0a, 0x04, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73,
@ -205,18 +213,20 @@ var file_feeds_proto_rawDesc = []byte{
0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x75, 0x70, 0x64, 0x61,
0x74, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x75, 0x70, 0x64, 0x61, 0x74,
0x65, 0x64, 0x22, 0x20, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x02, 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52,
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x66, 0x65, 0x65, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x46, 0x65, 0x65, 0x64, 0x52, 0x04, 0x66, 0x65,
0x65, 0x64, 0x32, 0x3d, 0x0a, 0x0b, 0x46, 0x65, 0x65, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x12, 0x2e, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0f, 0x2e, 0x47,
0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e,
0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x68, 0x74, 0x77, 0x6b, 0x61, 0x6c, 0x65, 0x6e, 0x64, 0x65, 0x72,
0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20,
0x01, 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x22, 0x20, 0x0a, 0x0e,
0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e,
0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2c,
0x0a, 0x0f, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x19, 0x0a, 0x04, 0x66, 0x65, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x05, 0x2e, 0x46, 0x65, 0x65, 0x64, 0x52, 0x04, 0x66, 0x65, 0x65, 0x64, 0x32, 0x3d, 0x0a, 0x0b,
0x46, 0x65, 0x65, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x47,
0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0f, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65,
0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x68,
0x74, 0x77, 0x6b, 0x61, 0x6c, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f,
0x6e, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (

View File

@ -48,6 +48,7 @@ func FindFeedByToken(app *pocketbase.PocketBase, token string) (*model.Feed, err
var feed model.Feed
feed.Modules = record.GetString("modules")
feed.Retrieved = record.GetDateTime("retrieved")
feed.Deleted = record.GetBool("deleted")
//update retrieved time if the is not marked as deleted
if !record.GetBool("deleted") {

View File

@ -39,5 +39,6 @@ func feedToProto(feed *model.Feed) *pb.Feed {
Updated: feed.Updated.String(),
Retrieved: feed.Retrieved.String(),
Modules: feed.Modules,
Deleted: feed.Deleted,
}
}

View File

@ -19,6 +19,7 @@ package connector
import (
"encoding/json"
"errors"
"fmt"
"htwkalender/ical/model"
"log/slog"
)
@ -29,9 +30,9 @@ func GetFeedByToken(host string, token string) (model.FeedRecord, error) {
// /api/collections/feeds/records/{id}
response, err := RequestApi(host, "/api/collections/feeds/records/"+token)
if err != nil {
if err != nil || response.StatusCode() != 200 {
slog.Error("Failed to get feed record", "error", err)
return model.FeedRecord{}, err
return model.FeedRecord{}, fmt.Errorf("failed to get feed record")
}
// parse the response body json to FeedRecord struct

View File

@ -64,5 +64,6 @@ func protoToFeed(feed *pb.Feed) (model.FeedRecord, error) {
},
Retrieved: model.ToJSONTime(feed.Retrieved),
Modules: modules,
Deleted: feed.Deleted,
}, nil
}

View File

@ -68,7 +68,7 @@ func Feed(app model.AppType, token string) (string, error) {
func FeedRecord(app model.AppType, token string) (model.FeedRecord, error) {
feedRecord, err := connector.GetFeedByToken(app.DataManagerURL, token)
if err != nil || feedRecord.Deleted {
if err != nil {
return model.FeedRecord{}, err
}

View File

@ -79,8 +79,12 @@ func AddFeedRoutes(app model.AppType) {
token := c.Params("token")
results, err := ical.FeedRecord(app, token)
if results.Deleted {
return c.SendStatus(fiber.StatusNotFound)
}
if err != nil {
slog.Error("Failed to get feed", "error", err, "token", token)
slog.Error("Failed to get feed record", "error", err, "token", token)
return c.SendStatus(fiber.StatusBadRequest)
}
c.Response().Header.Set("Content-type", "application/json; charset=UTF-8")

View File

@ -12,6 +12,7 @@ message Feed {
string retrieved = 3;
string created = 4;
string updated = 5;
bool deleted = 6;
}
message GetFeedRequest {