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
1b34119e
Commit
1b34119e
authored
Oct 27, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update activity store definition
parent
9d2b785b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
7 deletions
+106
-7
activity.go
store/activity.go
+25
-3
activity.go
store/db/mysql/activity.go
+18
-2
common.go
store/db/mysql/common.go
+9
-0
activity.go
store/db/sqlite/activity.go
+21
-2
activity_test.go
test/store/activity_test.go
+33
-0
No files found.
store/activity.go
View file @
1b34119e
...
...
@@ -2,8 +2,30 @@ package store
import
(
"context"
storepb
"github.com/usememos/memos/proto/gen/store"
)
type
ActivityType
string
const
(
ActivityTypeMemoComment
ActivityType
=
"MEMO_COMMENT"
)
func
(
t
ActivityType
)
String
()
string
{
return
string
(
t
)
}
type
ActivityLevel
string
const
(
ActivityLevelInfo
ActivityLevel
=
"INFO"
)
func
(
l
ActivityLevel
)
String
()
string
{
return
string
(
l
)
}
type
Activity
struct
{
ID
int32
...
...
@@ -12,9 +34,9 @@ type Activity struct {
CreatedTs
int64
// Domain specific fields
Type
string
Level
string
Payload
string
Type
ActivityType
Level
ActivityLevel
Payload
*
storepb
.
ActivityPayload
}
type
FindActivity
struct
{
...
...
store/db/mysql/activity.go
View file @
1b34119e
...
...
@@ -5,14 +5,24 @@ import (
"strings"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
storepb
"github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
func
(
d
*
DB
)
CreateActivity
(
ctx
context
.
Context
,
create
*
store
.
Activity
)
(
*
store
.
Activity
,
error
)
{
payloadString
:=
"{}"
if
create
.
Payload
!=
nil
{
bytes
,
err
:=
protojson
.
Marshal
(
create
.
Payload
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to marshal activity payload"
)
}
payloadString
=
string
(
bytes
)
}
fields
:=
[]
string
{
"`creator_id`"
,
"`type`"
,
"`level`"
,
"`payload`"
}
placeholder
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
}
args
:=
[]
any
{
create
.
CreatorID
,
create
.
Type
,
create
.
Level
,
create
.
Payload
}
args
:=
[]
any
{
create
.
CreatorID
,
create
.
Type
.
String
(),
create
.
Level
.
String
(),
payloadString
}
if
create
.
ID
!=
0
{
fields
=
append
(
fields
,
"`id`"
)
...
...
@@ -64,17 +74,23 @@ func (d *DB) ListActivities(ctx context.Context, find *store.FindActivity) ([]*s
list
:=
[]
*
store
.
Activity
{}
for
rows
.
Next
()
{
activity
:=
&
store
.
Activity
{}
var
payloadBytes
[]
byte
if
err
:=
rows
.
Scan
(
&
activity
.
ID
,
&
activity
.
CreatorID
,
&
activity
.
Type
,
&
activity
.
Level
,
&
activity
.
Payload
,
&
payloadBytes
,
&
activity
.
CreatedTs
,
);
err
!=
nil
{
return
nil
,
err
}
payload
:=
&
storepb
.
ActivityPayload
{}
if
err
:=
protojsonUnmarshaler
.
Unmarshal
(
payloadBytes
,
payload
);
err
!=
nil
{
return
nil
,
err
}
activity
.
Payload
=
payload
list
=
append
(
list
,
activity
)
}
...
...
store/db/mysql/common.go
0 → 100644
View file @
1b34119e
package
mysql
import
"google.golang.org/protobuf/encoding/protojson"
var
(
protojsonUnmarshaler
=
protojson
.
UnmarshalOptions
{
DiscardUnknown
:
true
,
}
)
store/db/sqlite/activity.go
View file @
1b34119e
...
...
@@ -4,13 +4,26 @@ import (
"context"
"strings"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
storepb
"github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
func
(
d
*
DB
)
CreateActivity
(
ctx
context
.
Context
,
create
*
store
.
Activity
)
(
*
store
.
Activity
,
error
)
{
payloadString
:=
"{}"
if
create
.
Payload
!=
nil
{
bytes
,
err
:=
protojson
.
Marshal
(
create
.
Payload
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"failed to marshal activity payload"
)
}
payloadString
=
string
(
bytes
)
}
fields
:=
[]
string
{
"`creator_id`"
,
"`type`"
,
"`level`"
,
"`payload`"
}
placeholder
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
}
args
:=
[]
any
{
create
.
CreatorID
,
create
.
Type
,
create
.
Level
,
create
.
Payload
}
args
:=
[]
any
{
create
.
CreatorID
,
create
.
Type
.
String
(),
create
.
Level
.
String
(),
payloadString
}
if
create
.
ID
!=
0
{
fields
=
append
(
fields
,
"`id`"
)
...
...
@@ -52,17 +65,23 @@ func (d *DB) ListActivities(ctx context.Context, find *store.FindActivity) ([]*s
list
:=
[]
*
store
.
Activity
{}
for
rows
.
Next
()
{
activity
:=
&
store
.
Activity
{}
var
payloadBytes
[]
byte
if
err
:=
rows
.
Scan
(
&
activity
.
ID
,
&
activity
.
CreatorID
,
&
activity
.
Type
,
&
activity
.
Level
,
&
activity
.
Payload
,
&
payloadBytes
,
&
activity
.
CreatedTs
,
);
err
!=
nil
{
return
nil
,
err
}
payload
:=
&
storepb
.
ActivityPayload
{}
if
err
:=
protojsonUnmarshaler
.
Unmarshal
(
payloadBytes
,
payload
);
err
!=
nil
{
return
nil
,
err
}
activity
.
Payload
=
payload
list
=
append
(
list
,
activity
)
}
...
...
test/store/activity_test.go
0 → 100644
View file @
1b34119e
package
teststore
import
(
"context"
"testing"
"github.com/stretchr/testify/require"
storepb
"github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
)
func
TestActivityStore
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
ts
:=
NewTestingStore
(
ctx
,
t
)
user
,
err
:=
createTestingHostUser
(
ctx
,
ts
)
require
.
NoError
(
t
,
err
)
create
:=
&
store
.
Activity
{
CreatorID
:
user
.
ID
,
Type
:
store
.
ActivityTypeMemoComment
,
Level
:
store
.
ActivityLevelInfo
,
Payload
:
&
storepb
.
ActivityPayload
{},
}
activity
,
err
:=
ts
.
CreateActivity
(
ctx
,
create
)
require
.
NoError
(
t
,
err
)
require
.
NotNil
(
t
,
activity
)
activities
,
err
:=
ts
.
ListActivities
(
ctx
,
&
store
.
FindActivity
{
ID
:
&
activity
.
ID
,
})
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
1
,
len
(
activities
))
require
.
Equal
(
t
,
activity
,
activities
[
0
])
}
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