|
|
|
@ -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")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
if err != nil {
|
|
|
|
|
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 {
|
|
|
|
|
payload := ActivityMemoCreatePayload{
|
|
|
|
|
Content: memo.Content,
|
|
|
|
|
Visibility: memo.Visibility.String(),
|
|
|
|
|
MemoID: memo.ID,
|
|
|
|
|
}
|
|
|
|
|
payloadBytes, err := json.Marshal(payload)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -772,6 +774,27 @@ func (s *APIV1Service) createMemoCreateActivity(ctx context.Context, memo *store
|
|
|
|
|
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) {
|
|
|
|
|
memoResponse := &Memo{
|
|
|
|
|
ID: memo.ID,
|
|
|
|
|