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
f16123a6
Unverified
Commit
f16123a6
authored
Jan 03, 2023
by
boojack
Committed by
GitHub
Jan 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update memo create activity (#903)
parent
d50ad943
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
4 deletions
+32
-4
activity.go
api/activity.go
+5
-0
memo.go
server/memo.go
+23
-4
activity.go
store/activity.go
+4
-0
No files found.
api/activity.go
View file @
f16123a6
...
...
@@ -87,6 +87,11 @@ type ActivityUserAuthSignUpPayload struct {
IP
string
`json:"ip"`
}
type
ActivityMemoCreatePayload
struct
{
Content
string
`json:"content"`
Visibility
string
`json:"visibility"`
}
type
ActivityShortcutCreatePayload
struct
{
Title
string
`json:"title"`
Payload
string
`json:"payload"`
...
...
server/memo.go
View file @
f16123a6
...
...
@@ -9,9 +9,9 @@ import (
"strings"
"time"
"github.com/pkg/errors"
"github.com/usememos/memos/api"
"github.com/usememos/memos/common"
metric
"github.com/usememos/memos/plugin/metrics"
"github.com/labstack/echo/v4"
)
...
...
@@ -60,9 +60,9 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create memo"
)
.
SetInternal
(
err
)
}
s
.
Collector
.
Collect
(
ctx
,
&
metric
.
Metric
{
Name
:
"memo created"
,
}
)
if
err
:=
s
.
createMemoCreateActivity
(
c
,
memo
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create activity"
)
.
SetInternal
(
err
)
}
for
_
,
resourceID
:=
range
memoCreate
.
ResourceIDList
{
if
_
,
err
:=
s
.
Store
.
UpsertMemoResource
(
ctx
,
&
api
.
MemoResourceUpsert
{
...
...
@@ -565,3 +565,22 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
c
.
JSON
(
http
.
StatusOK
,
true
)
})
}
func
(
s
*
Server
)
createMemoCreateActivity
(
c
echo
.
Context
,
memo
*
api
.
Memo
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
payload
:=
api
.
ActivityMemoCreatePayload
{
Content
:
memo
.
Content
,
Visibility
:
memo
.
Visibility
.
String
(),
}
payloadStr
,
err
:=
json
.
Marshal
(
payload
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to marshal activity payload"
)
}
_
,
err
=
s
.
Store
.
CreateActivity
(
ctx
,
&
api
.
ActivityCreate
{
CreatorID
:
memo
.
CreatorID
,
Type
:
api
.
ActivityMemoCreate
,
Level
:
api
.
ActivityInfo
,
Payload
:
string
(
payloadStr
),
})
return
err
}
store/activity.go
View file @
f16123a6
...
...
@@ -38,6 +38,10 @@ func (raw *activityRaw) toActivity() *api.Activity {
// CreateActivity creates an instance of Activity.
func
(
s
*
Store
)
CreateActivity
(
ctx
context
.
Context
,
create
*
api
.
ActivityCreate
)
(
*
api
.
Activity
,
error
)
{
if
s
.
profile
.
Mode
!=
"dev"
{
return
nil
,
nil
}
tx
,
err
:=
s
.
db
.
BeginTx
(
ctx
,
nil
)
if
err
!=
nil
{
return
nil
,
FormatError
(
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