Update usage grpc call

This commit is contained in:
2025-03-10 22:15:59 +08:00
parent 69be460e13
commit e3ca50c4ae
6 changed files with 248 additions and 60 deletions

View File

@ -5,6 +5,7 @@ import (
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/services"
"git.solsynth.dev/hypernet/paperclip/pkg/proto"
"github.com/rs/zerolog/log"
"github.com/samber/lo"
@ -91,6 +92,19 @@ func (v *Server) UpdateVisibility(ctx context.Context, request *proto.UpdateVisi
}, nil
}
func (v *Server) UpdateUsage(ctx context.Context, request *proto.UpdateUsageRequest) (*proto.UpdateUsageResponse, error) {
id := lo.Map(request.GetId(), func(item uint64, _ int) uint {
return uint(item)
})
if rows, err := services.CountAttachmentUsage(id, int(request.GetDelta())); err != nil {
return nil, status.Error(codes.Internal, err.Error())
} else {
return &proto.UpdateUsageResponse{
Count: int32(rows),
}, nil
}
}
func (v *Server) DeleteAttachment(ctx context.Context, request *proto.DeleteAttachmentRequest) (*proto.DeleteAttachmentResponse, error) {
tx := database.C
if len(request.Id) == 0 && len(request.Rid) == 0 {