Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
18107248
Commit
18107248
authored
Oct 27, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: rename list inbox
parent
4f1bb55e
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
225 additions
and
200 deletions
+225
-200
inbox_service .go
api/v2/inbox_service .go
+10
-7
inbox_service.proto
proto/api/v2/inbox_service.proto
+15
-12
README.md
proto/gen/api/v2/README.md
+12
-11
inbox_service.pb.go
proto/gen/api/v2/inbox_service.pb.go
+141
-123
inbox_service.pb.gw.go
proto/gen/api/v2/inbox_service.pb.gw.go
+25
-25
inbox_service_grpc.pb.go
proto/gen/api/v2/inbox_service_grpc.pb.go
+15
-15
inbox.go
store/db/mysql/inbox.go
+1
-1
inbox.go
store/db/sqlite/inbox.go
+1
-1
driver.go
store/driver.go
+1
-1
inbox.go
store/inbox.go
+2
-2
inbox_test.go
test/store/inbox_test.go
+2
-2
No files found.
api/v2/inbox_service .go
View file @
18107248
...
...
@@ -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
.
ListInbox
Response
,
error
)
{
func
(
s
*
APIV2Service
)
ListInbox
es
(
ctx
context
.
Context
,
_
*
apiv2pb
.
ListInboxesRequest
)
(
*
apiv2pb
.
ListInboxes
Response
,
error
)
{
user
,
err
:=
getCurrentUser
(
ctx
,
s
.
Store
)
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to get user"
)
}
inbox
List
,
err
:=
s
.
Store
.
ListInbox
(
ctx
,
&
store
.
FindInbox
{
inbox
es
,
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
.
ListInbox
es
Response
{
Inbox
es
:
[]
*
apiv2pb
.
Inbox
{},
}
for
_
,
inbox
:=
range
inbox
List
{
for
_
,
inbox
:=
range
inbox
es
{
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
.
Inbox
es
=
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
(
"inbox
es
/%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
...
...
proto/api/v2/inbox_service.proto
View file @
18107248
...
...
@@ -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
(
ListInbox
Response
)
{
option
(
google.api.http
)
=
{
get
:
"/api/v2/inbox"
};
rpc
ListInbox
es
(
ListInboxesRequest
)
returns
(
ListInboxes
Response
)
{
option
(
google.api.http
)
=
{
get
:
"/api/v2/inbox
es
"
};
}
rpc
UpdateInbox
(
UpdateInboxRequest
)
returns
(
UpdateInboxResponse
)
{
option
(
google.api.http
)
=
{
patch
:
"/v2/inbox"
patch
:
"/v2/inbox
es
"
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=inbox
es
/*}"
};
option
(
google.api.method_signature
)
=
"name"
;
}
}
message
Inbox
{
// The name of the inbox.
// Format: inbox/{id}
// Format: inbox
es
/{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
ListInbox
es
Request
{
// Format: users/{username}
string
user
=
1
;
}
message
ListInboxResponse
{
repeated
Inbox
inbox
=
1
;
message
ListInbox
es
Response
{
repeated
Inbox
inbox
es
=
1
;
}
message
UpdateInboxRequest
{
...
...
@@ -74,7 +77,7 @@ message UpdateInboxResponse {
message
DeleteInboxRequest
{
// The name of the inbox to delete.
// Format: inbox/{inbox}
// Format: inbox
es
/{inbox}
string
name
=
1
;
}
...
...
proto/gen/api/v2/README.md
View file @
18107248
...
...
@@ -10,8 +10,8 @@
-
[
DeleteInboxRequest
](
#memos-api-v2-DeleteInboxRequest
)
-
[
DeleteInboxResponse
](
#memos-api-v2-DeleteInboxResponse
)
-
[
Inbox
](
#memos-api-v2-Inbox
)
-
[
ListInbox
Request
](
#memos-api-v2-ListInbox
Request
)
-
[
ListInbox
Response
](
#memos-api-v2-ListInbox
Response
)
-
[
ListInbox
esRequest
](
#memos-api-v2-ListInboxes
Request
)
-
[
ListInbox
esResponse
](
#memos-api-v2-ListInboxes
Response
)
-
[
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: inbox
es
/{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: inbox
es
/{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-ListInbox
es
Request"
></a>
### ListInboxRequest
### ListInbox
es
Request
| 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-ListInbox
es
Response"
></a>
### ListInboxResponse
### ListInbox
es
Response
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| inbox |
[
Inbox
](
#memos-api-v2-Inbox
)
| repeated | |
| inbox
es
|
[
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-ListInbox
Response
)
| |
| ListInbox
es |
[
ListInboxesRequest
](
#memos-api-v2-ListInboxesRequest
)
|
[
ListInboxesResponse
](
#memos-api-v2-ListInboxes
Response
)
| |
| UpdateInbox |
[
UpdateInboxRequest
](
#memos-api-v2-UpdateInboxRequest
)
|
[
UpdateInboxResponse
](
#memos-api-v2-UpdateInboxResponse
)
| |
| DeleteInbox |
[
DeleteInboxRequest
](
#memos-api-v2-DeleteInboxRequest
)
|
[
DeleteInboxResponse
](
#memos-api-v2-DeleteInboxResponse
)
| |
...
...
proto/gen/api/v2/inbox_service.pb.go
View file @
18107248
This diff is collapsed.
Click to expand it.
proto/gen/api/v2/inbox_service.pb.gw.go
View file @
18107248
This diff is collapsed.
Click to expand it.
proto/gen/api/v2/inbox_service_grpc.pb.go
View file @
18107248
...
...
@@ -19,7 +19,7 @@ import (
const
_
=
grpc
.
SupportPackageIsVersion7
const
(
InboxService_ListInbox
_FullMethodName
=
"/memos.api.v2.InboxService/ListInbox
"
InboxService_ListInbox
es_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
)
(
*
ListInbox
Response
,
error
)
ListInbox
es
(
ctx
context
.
Context
,
in
*
ListInboxesRequest
,
opts
...
grpc
.
CallOption
)
(
*
ListInboxes
Response
,
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
)
(
*
ListInbox
Response
,
error
)
{
out
:=
new
(
ListInboxResponse
)
err
:=
c
.
cc
.
Invoke
(
ctx
,
InboxService_ListInbox_FullMethodName
,
in
,
out
,
opts
...
)
func
(
c
*
inboxServiceClient
)
ListInbox
es
(
ctx
context
.
Context
,
in
*
ListInboxesRequest
,
opts
...
grpc
.
CallOption
)
(
*
ListInboxes
Response
,
error
)
{
out
:=
new
(
ListInbox
es
Response
)
err
:=
c
.
cc
.
Invoke
(
ctx
,
InboxService_ListInbox
es
_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
)
(
*
ListInbox
Response
,
error
)
ListInbox
es
(
context
.
Context
,
*
ListInboxesRequest
)
(
*
ListInboxes
Response
,
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
)
(
*
ListInbox
Response
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method ListInbox not implemented"
)
func
(
UnimplementedInboxServiceServer
)
ListInbox
es
(
context
.
Context
,
*
ListInboxesRequest
)
(
*
ListInboxes
Response
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method ListInbox
es
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_ListInbox
es
_Handler
(
srv
interface
{},
ctx
context
.
Context
,
dec
func
(
interface
{})
error
,
interceptor
grpc
.
UnaryServerInterceptor
)
(
interface
{},
error
)
{
in
:=
new
(
ListInbox
es
Request
)
if
err
:=
dec
(
in
);
err
!=
nil
{
return
nil
,
err
}
if
interceptor
==
nil
{
return
srv
.
(
InboxServiceServer
)
.
ListInbox
(
ctx
,
in
)
return
srv
.
(
InboxServiceServer
)
.
ListInbox
es
(
ctx
,
in
)
}
info
:=
&
grpc
.
UnaryServerInfo
{
Server
:
srv
,
FullMethod
:
InboxService_ListInbox_FullMethodName
,
FullMethod
:
InboxService_ListInbox
es
_FullMethodName
,
}
handler
:=
func
(
ctx
context
.
Context
,
req
interface
{})
(
interface
{},
error
)
{
return
srv
.
(
InboxServiceServer
)
.
ListInbox
(
ctx
,
req
.
(
*
ListInbox
Request
))
return
srv
.
(
InboxServiceServer
)
.
ListInbox
es
(
ctx
,
req
.
(
*
ListInboxes
Request
))
}
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
:
"ListInbox
es
"
,
Handler
:
_InboxService_ListInbox
es
_Handler
,
},
{
MethodName
:
"UpdateInbox"
,
...
...
store/db/mysql/inbox.go
View file @
18107248
...
...
@@ -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
)
ListInbox
es
(
ctx
context
.
Context
,
find
*
store
.
FindInbox
)
([]
*
store
.
Inbox
,
error
)
{
return
nil
,
nil
}
...
...
store/db/sqlite/inbox.go
View file @
18107248
...
...
@@ -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
)
ListInbox
es
(
ctx
context
.
Context
,
find
*
store
.
FindInbox
)
([]
*
store
.
Inbox
,
error
)
{
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
if
find
.
ID
!=
nil
{
...
...
store/driver.go
View file @
18107248
...
...
@@ -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
)
ListInbox
es
(
ctx
context
.
Context
,
find
*
FindInbox
)
([]
*
Inbox
,
error
)
UpdateInbox
(
ctx
context
.
Context
,
update
*
UpdateInbox
)
(
*
Inbox
,
error
)
DeleteInbox
(
ctx
context
.
Context
,
delete
*
DeleteInbox
)
error
}
store/inbox.go
View file @
18107248
...
...
@@ -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
)
ListInbox
es
(
ctx
context
.
Context
,
find
*
FindInbox
)
([]
*
Inbox
,
error
)
{
return
s
.
driver
.
ListInbox
es
(
ctx
,
find
)
}
func
(
s
*
Store
)
UpdateInbox
(
ctx
context
.
Context
,
update
*
UpdateInbox
)
(
*
Inbox
,
error
)
{
...
...
test/store/inbox_test.go
View file @
18107248
...
...
@@ -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
.
ListInbox
es
(
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
.
ListInbox
es
(
ctx
,
&
store
.
FindInbox
{
ReceiverID
:
&
user
.
ID
,
})
require
.
NoError
(
t
,
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment