mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
refactor: tweak resource state in api
This commit is contained in:
@@ -15,22 +15,22 @@ const (
|
||||
DefaultPageSize = 10
|
||||
)
|
||||
|
||||
func convertRowStatusFromStore(rowStatus store.RowStatus) v1pb.RowStatus {
|
||||
func convertStateFromStore(rowStatus store.RowStatus) v1pb.State {
|
||||
switch rowStatus {
|
||||
case store.Normal:
|
||||
return v1pb.RowStatus_ACTIVE
|
||||
return v1pb.State_NORMAL
|
||||
case store.Archived:
|
||||
return v1pb.RowStatus_ARCHIVED
|
||||
return v1pb.State_ARCHIVED
|
||||
default:
|
||||
return v1pb.RowStatus_ROW_STATUS_UNSPECIFIED
|
||||
return v1pb.State_STATE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func convertRowStatusToStore(rowStatus v1pb.RowStatus) store.RowStatus {
|
||||
switch rowStatus {
|
||||
case v1pb.RowStatus_ACTIVE:
|
||||
func convertStateToStore(state v1pb.State) store.RowStatus {
|
||||
switch state {
|
||||
case v1pb.State_NORMAL:
|
||||
return store.Normal
|
||||
case v1pb.RowStatus_ARCHIVED:
|
||||
case v1pb.State_ARCHIVED:
|
||||
return store.Archived
|
||||
default:
|
||||
return store.Normal
|
||||
|
@@ -271,8 +271,8 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
|
||||
return nil, status.Errorf(codes.PermissionDenied, "disable public memos system setting is enabled")
|
||||
}
|
||||
update.Visibility = &visibility
|
||||
} else if path == "row_status" {
|
||||
rowStatus := convertRowStatusToStore(request.Memo.RowStatus)
|
||||
} else if path == "state" {
|
||||
rowStatus := convertStateToStore(request.Memo.State)
|
||||
update.RowStatus = &rowStatus
|
||||
} else if path == "create_time" {
|
||||
createdTs := request.Memo.CreateTime.AsTime().Unix()
|
||||
|
@@ -30,7 +30,7 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
|
||||
memoMessage := &v1pb.Memo{
|
||||
Name: name,
|
||||
Uid: memo.UID,
|
||||
RowStatus: convertRowStatusFromStore(memo.RowStatus),
|
||||
State: convertStateFromStore(memo.RowStatus),
|
||||
Creator: fmt.Sprintf("%s%d", UserNamePrefix, memo.CreatorID),
|
||||
CreateTime: timestamppb.New(time.Unix(memo.CreatedTs, 0)),
|
||||
UpdateTime: timestamppb.New(time.Unix(memo.UpdatedTs, 0)),
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
apiv1 "github.com/usememos/memos/proto/gen/api/v1"
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
@@ -141,7 +142,7 @@ var MemoFilterCELAttributes = []cel.EnvOption{
|
||||
cel.Variable("display_time_after", cel.IntType),
|
||||
cel.Variable("creator", cel.StringType),
|
||||
cel.Variable("uid", cel.StringType),
|
||||
cel.Variable("row_status", cel.StringType),
|
||||
cel.Variable("state", cel.StringType),
|
||||
cel.Variable("random", cel.BoolType),
|
||||
cel.Variable("limit", cel.IntType),
|
||||
cel.Variable("include_comments", cel.BoolType),
|
||||
@@ -229,9 +230,9 @@ func findMemoField(callExpr *expr.Expr_Call, filter *MemoFilter) {
|
||||
} else if idExpr.Name == "creator" {
|
||||
creator := callExpr.Args[1].GetConstExpr().GetStringValue()
|
||||
filter.Creator = &creator
|
||||
} else if idExpr.Name == "row_status" {
|
||||
rowStatus := store.RowStatus(callExpr.Args[1].GetConstExpr().GetStringValue())
|
||||
filter.RowStatus = &rowStatus
|
||||
} else if idExpr.Name == "state" {
|
||||
state := convertStateToStore(apiv1.State(apiv1.State_value[callExpr.Args[1].GetConstExpr().GetStringValue()]))
|
||||
filter.RowStatus = &state
|
||||
} else if idExpr.Name == "random" {
|
||||
value := callExpr.Args[1].GetConstExpr().GetBoolValue()
|
||||
filter.Random = value
|
||||
|
@@ -229,8 +229,8 @@ func (s *APIV1Service) UpdateUser(ctx context.Context, request *v1pb.UpdateUserR
|
||||
}
|
||||
passwordHashStr := string(passwordHash)
|
||||
update.PasswordHash = &passwordHashStr
|
||||
} else if field == "row_status" {
|
||||
rowStatus := convertRowStatusToStore(request.User.RowStatus)
|
||||
} else if field == "state" {
|
||||
rowStatus := convertStateToStore(request.User.State)
|
||||
update.RowStatus = &rowStatus
|
||||
} else {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid update path: %s", field)
|
||||
@@ -557,7 +557,7 @@ func convertUserFromStore(user *store.User) *v1pb.User {
|
||||
userpb := &v1pb.User{
|
||||
Name: fmt.Sprintf("%s%d", UserNamePrefix, user.ID),
|
||||
Id: user.ID,
|
||||
RowStatus: convertRowStatusFromStore(user.RowStatus),
|
||||
State: convertStateFromStore(user.RowStatus),
|
||||
CreateTime: timestamppb.New(time.Unix(user.CreatedTs, 0)),
|
||||
UpdateTime: timestamppb.New(time.Unix(user.UpdatedTs, 0)),
|
||||
Role: convertUserRoleFromStore(user.Role),
|
||||
|
@@ -74,9 +74,6 @@ func (s *APIV1Service) UpdateWebhook(ctx context.Context, request *v1pb.UpdateWe
|
||||
update := &store.UpdateWebhook{}
|
||||
for _, field := range request.UpdateMask.Paths {
|
||||
switch field {
|
||||
case "row_status":
|
||||
rowStatus := store.RowStatus(request.Webhook.RowStatus.String())
|
||||
update.RowStatus = &rowStatus
|
||||
case "name":
|
||||
update.Name = &request.Webhook.Name
|
||||
case "url":
|
||||
@@ -106,7 +103,7 @@ func convertWebhookFromStore(webhook *store.Webhook) *v1pb.Webhook {
|
||||
Id: webhook.ID,
|
||||
CreateTime: timestamppb.New(time.Unix(webhook.CreatedTs, 0)),
|
||||
UpdateTime: timestamppb.New(time.Unix(webhook.UpdatedTs, 0)),
|
||||
RowStatus: convertRowStatusFromStore(webhook.RowStatus),
|
||||
State: convertStateFromStore(webhook.RowStatus),
|
||||
CreatorId: webhook.CreatorID,
|
||||
Name: webhook.Name,
|
||||
Url: webhook.URL,
|
||||
|
Reference in New Issue
Block a user