Commit 18107248 authored by Steven's avatar Steven

chore: rename list inbox

parent 4f1bb55e
......@@ -3,37 +3,39 @@ package v2
import (
"context"
"fmt"
"time"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
"github.com/usememos/memos/store"
)
func (s *APIV2Service) ListInbox(ctx context.Context, _ *apiv2pb.ListInboxRequest) (*apiv2pb.ListInboxResponse, error) {
func (s *APIV2Service) ListInboxes(ctx context.Context, _ *apiv2pb.ListInboxesRequest) (*apiv2pb.ListInboxesResponse, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get user")
}
inboxList, err := s.Store.ListInbox(ctx, &store.FindInbox{
inboxes, err := s.Store.ListInboxes(ctx, &store.FindInbox{
ReceiverID: &user.ID,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list inbox: %v", err)
}
response := &apiv2pb.ListInboxResponse{
Inbox: []*apiv2pb.Inbox{},
response := &apiv2pb.ListInboxesResponse{
Inboxes: []*apiv2pb.Inbox{},
}
for _, inbox := range inboxList {
for _, inbox := range inboxes {
inboxMessage, err := s.convertInboxFromStore(ctx, inbox)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert inbox from store: %v", err)
}
response.Inbox = append(response.Inbox, inboxMessage)
response.Inboxes = append(response.Inboxes, inboxMessage)
}
return response, nil
......@@ -103,10 +105,11 @@ func (s *APIV2Service) convertInboxFromStore(ctx context.Context, inbox *store.I
}
return &apiv2pb.Inbox{
Name: fmt.Sprintf("inbox/%d", inbox.ID),
Name: fmt.Sprintf("inboxes/%d", inbox.ID),
Sender: fmt.Sprintf("users/%s", sender.Username),
Receiver: fmt.Sprintf("users/%s", receiver.Username),
Status: convertInboxStatusFromStore(inbox.Status),
CreateTime: timestamppb.New(time.Unix(inbox.CreatedTs, 0)),
Type: apiv2pb.Inbox_Type(inbox.Message.Type),
ActivityId: inbox.Message.ActivityId,
}, nil
......
......@@ -5,31 +5,32 @@ package memos.api.v2;
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
option go_package = "gen/api/v2";
service InboxService {
rpc ListInbox(ListInboxRequest) returns (ListInboxResponse) {
option (google.api.http) = {get: "/api/v2/inbox"};
rpc ListInboxes(ListInboxesRequest) returns (ListInboxesResponse) {
option (google.api.http) = {get: "/api/v2/inboxes"};
}
rpc UpdateInbox(UpdateInboxRequest) returns (UpdateInboxResponse) {
option (google.api.http) = {
patch: "/v2/inbox"
patch: "/v2/inboxes"
body: "inbox"
};
option (google.api.method_signature) = "inbox,update_mask";
}
rpc DeleteInbox(DeleteInboxRequest) returns (DeleteInboxResponse) {
option (google.api.http) = {delete: "/v2/{name=inbox/*}"};
option (google.api.http) = {delete: "/v2/{name=inboxes/*}"};
option (google.api.method_signature) = "name";
}
}
message Inbox {
// The name of the inbox.
// Format: inbox/{id}
// Format: inboxes/{id}
string name = 1;
// Format: users/{username}
string sender = 2;
......@@ -44,22 +45,24 @@ message Inbox {
}
Status status = 4;
google.protobuf.Timestamp create_time = 5;
enum Type {
TYPE_UNSPECIFIED = 0;
TYPE_MEMO_COMMENT = 1;
}
Type type = 5;
Type type = 6;
optional int32 activity_id = 6;
optional int32 activity_id = 7;
}
message ListInboxRequest {
// Format: /users/{username}
message ListInboxesRequest {
// Format: users/{username}
string user = 1;
}
message ListInboxResponse {
repeated Inbox inbox = 1;
message ListInboxesResponse {
repeated Inbox inboxes = 1;
}
message UpdateInboxRequest {
......@@ -74,7 +77,7 @@ message UpdateInboxResponse {
message DeleteInboxRequest {
// The name of the inbox to delete.
// Format: inbox/{inbox}
// Format: inboxes/{inbox}
string name = 1;
}
......
......@@ -10,8 +10,8 @@
- [DeleteInboxRequest](#memos-api-v2-DeleteInboxRequest)
- [DeleteInboxResponse](#memos-api-v2-DeleteInboxResponse)
- [Inbox](#memos-api-v2-Inbox)
- [ListInboxRequest](#memos-api-v2-ListInboxRequest)
- [ListInboxResponse](#memos-api-v2-ListInboxResponse)
- [ListInboxesRequest](#memos-api-v2-ListInboxesRequest)
- [ListInboxesResponse](#memos-api-v2-ListInboxesResponse)
- [UpdateInboxRequest](#memos-api-v2-UpdateInboxRequest)
- [UpdateInboxResponse](#memos-api-v2-UpdateInboxResponse)
......@@ -138,7 +138,7 @@
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the inbox to delete. Format: inbox/{inbox} |
| name | [string](#string) | | The name of the inbox to delete. Format: inboxes/{inbox} |
......@@ -163,10 +163,11 @@
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | The name of the inbox. Format: inbox/{id} |
| name | [string](#string) | | The name of the inbox. Format: inboxes/{id} |
| sender | [string](#string) | | Format: users/{username} |
| receiver | [string](#string) | | Format: users/{username} |
| status | [Inbox.Status](#memos-api-v2-Inbox-Status) | | |
| create_time | [google.protobuf.Timestamp](#google-protobuf-Timestamp) | | |
| type | [Inbox.Type](#memos-api-v2-Inbox-Type) | | |
| activity_id | [int32](#int32) | optional | |
......@@ -175,30 +176,30 @@
<a name="memos-api-v2-ListInboxRequest"></a>
<a name="memos-api-v2-ListInboxesRequest"></a>
### ListInboxRequest
### ListInboxesRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| user | [string](#string) | | Format: /users/{username} |
| user | [string](#string) | | Format: users/{username} |
<a name="memos-api-v2-ListInboxResponse"></a>
<a name="memos-api-v2-ListInboxesResponse"></a>
### ListInboxResponse
### ListInboxesResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| inbox | [Inbox](#memos-api-v2-Inbox) | repeated | |
| inboxes | [Inbox](#memos-api-v2-Inbox) | repeated | |
......@@ -275,7 +276,7 @@
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| ListInbox | [ListInboxRequest](#memos-api-v2-ListInboxRequest) | [ListInboxResponse](#memos-api-v2-ListInboxResponse) | |
| ListInboxes | [ListInboxesRequest](#memos-api-v2-ListInboxesRequest) | [ListInboxesResponse](#memos-api-v2-ListInboxesResponse) | |
| UpdateInbox | [UpdateInboxRequest](#memos-api-v2-UpdateInboxRequest) | [UpdateInboxResponse](#memos-api-v2-UpdateInboxResponse) | |
| DeleteInbox | [DeleteInboxRequest](#memos-api-v2-DeleteInboxRequest) | [DeleteInboxResponse](#memos-api-v2-DeleteInboxResponse) | |
......
This diff is collapsed.
This diff is collapsed.
......@@ -19,7 +19,7 @@ import (
const _ = grpc.SupportPackageIsVersion7
const (
InboxService_ListInbox_FullMethodName = "/memos.api.v2.InboxService/ListInbox"
InboxService_ListInboxes_FullMethodName = "/memos.api.v2.InboxService/ListInboxes"
InboxService_UpdateInbox_FullMethodName = "/memos.api.v2.InboxService/UpdateInbox"
InboxService_DeleteInbox_FullMethodName = "/memos.api.v2.InboxService/DeleteInbox"
)
......@@ -28,7 +28,7 @@ const (
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type InboxServiceClient interface {
ListInbox(ctx context.Context, in *ListInboxRequest, opts ...grpc.CallOption) (*ListInboxResponse, error)
ListInboxes(ctx context.Context, in *ListInboxesRequest, opts ...grpc.CallOption) (*ListInboxesResponse, error)
UpdateInbox(ctx context.Context, in *UpdateInboxRequest, opts ...grpc.CallOption) (*UpdateInboxResponse, error)
DeleteInbox(ctx context.Context, in *DeleteInboxRequest, opts ...grpc.CallOption) (*DeleteInboxResponse, error)
}
......@@ -41,9 +41,9 @@ func NewInboxServiceClient(cc grpc.ClientConnInterface) InboxServiceClient {
return &inboxServiceClient{cc}
}
func (c *inboxServiceClient) ListInbox(ctx context.Context, in *ListInboxRequest, opts ...grpc.CallOption) (*ListInboxResponse, error) {
out := new(ListInboxResponse)
err := c.cc.Invoke(ctx, InboxService_ListInbox_FullMethodName, in, out, opts...)
func (c *inboxServiceClient) ListInboxes(ctx context.Context, in *ListInboxesRequest, opts ...grpc.CallOption) (*ListInboxesResponse, error) {
out := new(ListInboxesResponse)
err := c.cc.Invoke(ctx, InboxService_ListInboxes_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
......@@ -72,7 +72,7 @@ func (c *inboxServiceClient) DeleteInbox(ctx context.Context, in *DeleteInboxReq
// All implementations must embed UnimplementedInboxServiceServer
// for forward compatibility
type InboxServiceServer interface {
ListInbox(context.Context, *ListInboxRequest) (*ListInboxResponse, error)
ListInboxes(context.Context, *ListInboxesRequest) (*ListInboxesResponse, error)
UpdateInbox(context.Context, *UpdateInboxRequest) (*UpdateInboxResponse, error)
DeleteInbox(context.Context, *DeleteInboxRequest) (*DeleteInboxResponse, error)
mustEmbedUnimplementedInboxServiceServer()
......@@ -82,8 +82,8 @@ type InboxServiceServer interface {
type UnimplementedInboxServiceServer struct {
}
func (UnimplementedInboxServiceServer) ListInbox(context.Context, *ListInboxRequest) (*ListInboxResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListInbox not implemented")
func (UnimplementedInboxServiceServer) ListInboxes(context.Context, *ListInboxesRequest) (*ListInboxesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListInboxes not implemented")
}
func (UnimplementedInboxServiceServer) UpdateInbox(context.Context, *UpdateInboxRequest) (*UpdateInboxResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateInbox not implemented")
......@@ -104,20 +104,20 @@ func RegisterInboxServiceServer(s grpc.ServiceRegistrar, srv InboxServiceServer)
s.RegisterService(&InboxService_ServiceDesc, srv)
}
func _InboxService_ListInbox_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListInboxRequest)
func _InboxService_ListInboxes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListInboxesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(InboxServiceServer).ListInbox(ctx, in)
return srv.(InboxServiceServer).ListInboxes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: InboxService_ListInbox_FullMethodName,
FullMethod: InboxService_ListInboxes_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(InboxServiceServer).ListInbox(ctx, req.(*ListInboxRequest))
return srv.(InboxServiceServer).ListInboxes(ctx, req.(*ListInboxesRequest))
}
return interceptor(ctx, in, info, handler)
}
......@@ -166,8 +166,8 @@ var InboxService_ServiceDesc = grpc.ServiceDesc{
HandlerType: (*InboxServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "ListInbox",
Handler: _InboxService_ListInbox_Handler,
MethodName: "ListInboxes",
Handler: _InboxService_ListInboxes_Handler,
},
{
MethodName: "UpdateInbox",
......
......@@ -12,7 +12,7 @@ func (d *DB) CreateInbox(ctx context.Context, create *store.Inbox) (*store.Inbox
}
// nolint
func (d *DB) ListInbox(ctx context.Context, find *store.FindInbox) ([]*store.Inbox, error) {
func (d *DB) ListInboxes(ctx context.Context, find *store.FindInbox) ([]*store.Inbox, error) {
return nil, nil
}
......
......@@ -36,7 +36,7 @@ func (d *DB) CreateInbox(ctx context.Context, create *store.Inbox) (*store.Inbox
return create, nil
}
func (d *DB) ListInbox(ctx context.Context, find *store.FindInbox) ([]*store.Inbox, error) {
func (d *DB) ListInboxes(ctx context.Context, find *store.FindInbox) ([]*store.Inbox, error) {
where, args := []string{"1 = 1"}, []any{}
if find.ID != nil {
......
......@@ -84,7 +84,7 @@ type Driver interface {
// Inbox model related methods.
CreateInbox(ctx context.Context, create *Inbox) (*Inbox, error)
ListInbox(ctx context.Context, find *FindInbox) ([]*Inbox, error)
ListInboxes(ctx context.Context, find *FindInbox) ([]*Inbox, error)
UpdateInbox(ctx context.Context, update *UpdateInbox) (*Inbox, error)
DeleteInbox(ctx context.Context, delete *DeleteInbox) error
}
......@@ -44,8 +44,8 @@ func (s *Store) CreateInbox(ctx context.Context, create *Inbox) (*Inbox, error)
return s.driver.CreateInbox(ctx, create)
}
func (s *Store) ListInbox(ctx context.Context, find *FindInbox) ([]*Inbox, error) {
return s.driver.ListInbox(ctx, find)
func (s *Store) ListInboxes(ctx context.Context, find *FindInbox) ([]*Inbox, error) {
return s.driver.ListInboxes(ctx, find)
}
func (s *Store) UpdateInbox(ctx context.Context, update *UpdateInbox) (*Inbox, error) {
......
......@@ -28,7 +28,7 @@ func TestInboxStore(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, inbox)
require.Equal(t, create.Message, inbox.Message)
inboxes, err := ts.ListInbox(ctx, &store.FindInbox{
inboxes, err := ts.ListInboxes(ctx, &store.FindInbox{
ReceiverID: &user.ID,
})
require.NoError(t, err)
......@@ -45,7 +45,7 @@ func TestInboxStore(t *testing.T) {
ID: inbox.ID,
})
require.NoError(t, err)
inboxes, err = ts.ListInbox(ctx, &store.FindInbox{
inboxes, err = ts.ListInboxes(ctx, &store.FindInbox{
ReceiverID: &user.ID,
})
require.NoError(t, err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment