mirror of
https://github.com/usememos/memos.git
synced 2025-01-04 12:35:14 +03:00
chore: update memo view activity
This commit is contained in:
parent
de5eccf9d6
commit
7549c807ac
@ -25,6 +25,8 @@ const (
|
|||||||
|
|
||||||
// ActivityMemoCreate is the type for creating memos.
|
// ActivityMemoCreate is the type for creating memos.
|
||||||
ActivityMemoCreate ActivityType = "memo.create"
|
ActivityMemoCreate ActivityType = "memo.create"
|
||||||
|
// ActivityMemoView is the type for viewing memos.
|
||||||
|
ActivityMemoView ActivityType = "memo.view"
|
||||||
// ActivityMemoUpdate is the type for updating memos.
|
// ActivityMemoUpdate is the type for updating memos.
|
||||||
ActivityMemoUpdate ActivityType = "memo.update"
|
ActivityMemoUpdate ActivityType = "memo.update"
|
||||||
// ActivityMemoDelete is the type for deleting memos.
|
// ActivityMemoDelete is the type for deleting memos.
|
||||||
@ -87,8 +89,11 @@ type ActivityUserAuthSignUpPayload struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ActivityMemoCreatePayload struct {
|
type ActivityMemoCreatePayload struct {
|
||||||
Content string `json:"content"`
|
MemoID int32 `json:"memoId"`
|
||||||
Visibility string `json:"visibility"`
|
}
|
||||||
|
|
||||||
|
type ActivityMemoViewPayload struct {
|
||||||
|
MemoID int32 `json:"memoId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActivityResourceCreatePayload struct {
|
type ActivityResourceCreatePayload struct {
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package v1
|
package v1
|
||||||
|
|
||||||
// UnknownID is the ID for unknowns.
|
|
||||||
const UnknownID = -1
|
|
||||||
|
|
||||||
// RowStatus is the status for a row.
|
// RowStatus is the status for a row.
|
||||||
type RowStatus string
|
type RowStatus string
|
||||||
|
|
||||||
|
@ -555,6 +555,9 @@ func (s *APIV1Service) GetMemo(c echo.Context) error {
|
|||||||
return echo.NewHTTPError(http.StatusForbidden, "this memo is protected, missing user in session")
|
return echo.NewHTTPError(http.StatusForbidden, "this memo is protected, missing user in session")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := s.createMemoViewActivity(c, memo, userID); err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create activity").SetInternal(err)
|
||||||
|
}
|
||||||
memoResponse, err := s.convertMemoFromStore(ctx, memo)
|
memoResponse, err := s.convertMemoFromStore(ctx, memo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose memo response").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compose memo response").SetInternal(err)
|
||||||
@ -753,8 +756,7 @@ func (s *APIV1Service) UpdateMemo(c echo.Context) error {
|
|||||||
|
|
||||||
func (s *APIV1Service) createMemoCreateActivity(ctx context.Context, memo *store.Memo) error {
|
func (s *APIV1Service) createMemoCreateActivity(ctx context.Context, memo *store.Memo) error {
|
||||||
payload := ActivityMemoCreatePayload{
|
payload := ActivityMemoCreatePayload{
|
||||||
Content: memo.Content,
|
MemoID: memo.ID,
|
||||||
Visibility: memo.Visibility.String(),
|
|
||||||
}
|
}
|
||||||
payloadBytes, err := json.Marshal(payload)
|
payloadBytes, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -772,6 +774,27 @@ func (s *APIV1Service) createMemoCreateActivity(ctx context.Context, memo *store
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *APIV1Service) createMemoViewActivity(c echo.Context, memo *store.Memo, userID int32) error {
|
||||||
|
ctx := c.Request().Context()
|
||||||
|
payload := ActivityMemoViewPayload{
|
||||||
|
MemoID: memo.ID,
|
||||||
|
}
|
||||||
|
payloadBytes, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to marshal activity payload")
|
||||||
|
}
|
||||||
|
activity, err := s.Store.CreateActivity(ctx, &store.Activity{
|
||||||
|
CreatorID: userID,
|
||||||
|
Type: string(ActivityMemoView),
|
||||||
|
Level: string(ActivityInfo),
|
||||||
|
Payload: string(payloadBytes),
|
||||||
|
})
|
||||||
|
if err != nil || activity == nil {
|
||||||
|
return errors.Wrap(err, "failed to create activity")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Memo) (*Memo, error) {
|
func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Memo) (*Memo, error) {
|
||||||
memoResponse := &Memo{
|
memoResponse := &Memo{
|
||||||
ID: memo.ID,
|
ID: memo.ID,
|
||||||
|
@ -221,10 +221,9 @@ func (s *Server) createServerStartActivity(ctx context.Context) error {
|
|||||||
return errors.Wrap(err, "failed to marshal activity payload")
|
return errors.Wrap(err, "failed to marshal activity payload")
|
||||||
}
|
}
|
||||||
activity, err := s.Store.CreateActivity(ctx, &store.Activity{
|
activity, err := s.Store.CreateActivity(ctx, &store.Activity{
|
||||||
CreatorID: apiv1.UnknownID,
|
Type: apiv1.ActivityServerStart.String(),
|
||||||
Type: apiv1.ActivityServerStart.String(),
|
Level: apiv1.ActivityInfo.String(),
|
||||||
Level: apiv1.ActivityInfo.String(),
|
Payload: string(payloadBytes),
|
||||||
Payload: string(payloadBytes),
|
|
||||||
})
|
})
|
||||||
if err != nil || activity == nil {
|
if err != nil || activity == nil {
|
||||||
return errors.Wrap(err, "failed to create activity")
|
return errors.Wrap(err, "failed to create activity")
|
||||||
|
Loading…
Reference in New Issue
Block a user