mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-24 13:38:48 +02:00
feat:#44 updated grpc and function for error handling
This commit is contained in:
@ -30,6 +30,7 @@ type Feed struct {
|
|||||||
Retrieved string `protobuf:"bytes,3,opt,name=retrieved,proto3" json:"retrieved,omitempty"`
|
Retrieved string `protobuf:"bytes,3,opt,name=retrieved,proto3" json:"retrieved,omitempty"`
|
||||||
Created string `protobuf:"bytes,4,opt,name=created,proto3" json:"created,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"`
|
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() {
|
func (x *Feed) Reset() {
|
||||||
@ -99,6 +100,13 @@ func (x *Feed) GetUpdated() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *Feed) GetDeleted() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.Deleted
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type GetFeedRequest struct {
|
type GetFeedRequest struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@ -196,7 +204,7 @@ func (x *GetFeedResponse) GetFeed() *Feed {
|
|||||||
var File_feeds_proto protoreflect.FileDescriptor
|
var File_feeds_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_feeds_proto_rawDesc = []byte{
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20,
|
||||||
0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
0x01, 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x22, 0x20, 0x0a, 0x0e,
|
||||||
0x52, 0x02, 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52,
|
0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e,
|
||||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x66, 0x65, 0x65, 0x64, 0x18,
|
0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2c,
|
||||||
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x46, 0x65, 0x65, 0x64, 0x52, 0x04, 0x66, 0x65,
|
0x0a, 0x0f, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||||
0x65, 0x64, 0x32, 0x3d, 0x0a, 0x0b, 0x46, 0x65, 0x65, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
|
0x65, 0x12, 0x19, 0x0a, 0x04, 0x66, 0x65, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
|
||||||
0x65, 0x12, 0x2e, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0f, 0x2e, 0x47,
|
0x05, 0x2e, 0x46, 0x65, 0x65, 0x64, 0x52, 0x04, 0x66, 0x65, 0x65, 0x64, 0x32, 0x3d, 0x0a, 0x0b,
|
||||||
0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e,
|
0x46, 0x65, 0x65, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2e, 0x0a, 0x07, 0x47,
|
||||||
0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
|
0x65, 0x74, 0x46, 0x65, 0x65, 0x64, 0x12, 0x0f, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65, 0x64,
|
||||||
0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x68, 0x74, 0x77, 0x6b, 0x61, 0x6c, 0x65, 0x6e, 0x64, 0x65, 0x72,
|
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x47, 0x65, 0x74, 0x46, 0x65, 0x65,
|
||||||
0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x62,
|
0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x1c, 0x5a, 0x1a, 0x68,
|
||||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
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 (
|
var (
|
||||||
|
@ -48,6 +48,7 @@ func FindFeedByToken(app *pocketbase.PocketBase, token string) (*model.Feed, err
|
|||||||
var feed model.Feed
|
var feed model.Feed
|
||||||
feed.Modules = record.GetString("modules")
|
feed.Modules = record.GetString("modules")
|
||||||
feed.Retrieved = record.GetDateTime("retrieved")
|
feed.Retrieved = record.GetDateTime("retrieved")
|
||||||
|
feed.Deleted = record.GetBool("deleted")
|
||||||
|
|
||||||
//update retrieved time if the is not marked as deleted
|
//update retrieved time if the is not marked as deleted
|
||||||
if !record.GetBool("deleted") {
|
if !record.GetBool("deleted") {
|
||||||
|
@ -39,5 +39,6 @@ func feedToProto(feed *model.Feed) *pb.Feed {
|
|||||||
Updated: feed.Updated.String(),
|
Updated: feed.Updated.String(),
|
||||||
Retrieved: feed.Retrieved.String(),
|
Retrieved: feed.Retrieved.String(),
|
||||||
Modules: feed.Modules,
|
Modules: feed.Modules,
|
||||||
|
Deleted: feed.Deleted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package connector
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"htwkalender/ical/model"
|
"htwkalender/ical/model"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
)
|
)
|
||||||
@ -29,9 +30,9 @@ func GetFeedByToken(host string, token string) (model.FeedRecord, error) {
|
|||||||
// /api/collections/feeds/records/{id}
|
// /api/collections/feeds/records/{id}
|
||||||
|
|
||||||
response, err := RequestApi(host, "/api/collections/feeds/records/"+token)
|
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)
|
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
|
// parse the response body json to FeedRecord struct
|
||||||
|
@ -64,5 +64,6 @@ func protoToFeed(feed *pb.Feed) (model.FeedRecord, error) {
|
|||||||
},
|
},
|
||||||
Retrieved: model.ToJSONTime(feed.Retrieved),
|
Retrieved: model.ToJSONTime(feed.Retrieved),
|
||||||
Modules: modules,
|
Modules: modules,
|
||||||
|
Deleted: feed.Deleted,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func Feed(app model.AppType, token string) (string, error) {
|
|||||||
func FeedRecord(app model.AppType, token string) (model.FeedRecord, error) {
|
func FeedRecord(app model.AppType, token string) (model.FeedRecord, error) {
|
||||||
|
|
||||||
feedRecord, err := connector.GetFeedByToken(app.DataManagerURL, token)
|
feedRecord, err := connector.GetFeedByToken(app.DataManagerURL, token)
|
||||||
if err != nil || feedRecord.Deleted {
|
if err != nil {
|
||||||
return model.FeedRecord{}, err
|
return model.FeedRecord{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,8 +79,12 @@ func AddFeedRoutes(app model.AppType) {
|
|||||||
token := c.Params("token")
|
token := c.Params("token")
|
||||||
results, err := ical.FeedRecord(app, token)
|
results, err := ical.FeedRecord(app, token)
|
||||||
|
|
||||||
|
if results.Deleted {
|
||||||
|
return c.SendStatus(fiber.StatusNotFound)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
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)
|
return c.SendStatus(fiber.StatusBadRequest)
|
||||||
}
|
}
|
||||||
c.Response().Header.Set("Content-type", "application/json; charset=UTF-8")
|
c.Response().Header.Set("Content-type", "application/json; charset=UTF-8")
|
||||||
|
@ -12,6 +12,7 @@ message Feed {
|
|||||||
string retrieved = 3;
|
string retrieved = 3;
|
||||||
string created = 4;
|
string created = 4;
|
||||||
string updated = 5;
|
string updated = 5;
|
||||||
|
bool deleted = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetFeedRequest {
|
message GetFeedRequest {
|
||||||
|
Reference in New Issue
Block a user