Messaging/pkg/services/attachments.go

31 lines
778 B
Go
Raw Normal View History

2024-03-26 15:05:13 +00:00
package services
import (
2024-05-26 15:01:20 +00:00
"context"
2024-03-26 15:05:13 +00:00
2024-05-26 15:01:20 +00:00
"git.solsynth.dev/hydrogen/messaging/pkg/grpc"
pcpb "git.solsynth.dev/hydrogen/paperclip/pkg/grpc/proto"
"github.com/samber/lo"
2024-03-26 15:05:13 +00:00
)
2024-05-26 15:01:20 +00:00
func GetAttachmentByID(id uint) (*pcpb.Attachment, error) {
return grpc.Attachments.GetAttachment(context.Background(), &pcpb.AttachmentLookupRequest{
Id: lo.ToPtr(uint64(id)),
})
2024-03-26 15:05:13 +00:00
}
2024-05-26 15:01:20 +00:00
func GetAttachmentByUUID(uuid string) (*pcpb.Attachment, error) {
return grpc.Attachments.GetAttachment(context.Background(), &pcpb.AttachmentLookupRequest{
Uuid: &uuid,
})
2024-03-26 15:05:13 +00:00
}
2024-05-26 15:01:20 +00:00
func CheckAttachmentByIDExists(id uint, usage string) bool {
_, err := grpc.Attachments.CheckAttachmentExists(context.Background(), &pcpb.AttachmentLookupRequest{
Id: lo.ToPtr(uint64(id)),
Usage: &usage,
})
2024-03-26 15:05:13 +00:00
2024-05-26 15:01:20 +00:00
return err == nil
2024-03-26 15:05:13 +00:00
}