mirror of
https://github.com/usememos/memos.git
synced 2024-12-19 00:51:30 +03:00
66e65e4dc1
* refactor: user api v1 * refactor: system setting to apiv1 * chore: remove unused definition * chore: update * chore: refactor: system setting * chore: update * refactor: migrate tag * feat: migrate activity store * refactor: migrate shortcut apiv1 * chore: update
51 lines
938 B
Go
51 lines
938 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type ActivityMessage struct {
|
|
ID int
|
|
|
|
// Standard fields
|
|
CreatorID int
|
|
CreatedTs int64
|
|
|
|
// Domain specific fields
|
|
Type string
|
|
Level string
|
|
Payload string
|
|
}
|
|
|
|
// CreateActivity creates an instance of Activity.
|
|
func (s *Store) CreateActivity(ctx context.Context, create *ActivityMessage) (*ActivityMessage, error) {
|
|
tx, err := s.db.BeginTx(ctx, nil)
|
|
if err != nil {
|
|
return nil, FormatError(err)
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
query := `
|
|
INSERT INTO activity (
|
|
creator_id,
|
|
type,
|
|
level,
|
|
payload
|
|
)
|
|
VALUES (?, ?, ?, ?)
|
|
RETURNING id, created_ts
|
|
`
|
|
if err := tx.QueryRowContext(ctx, query, create.CreatorID, create.Type, create.Level, create.Payload).Scan(
|
|
&create.ID,
|
|
&create.CreatedTs,
|
|
); err != nil {
|
|
return nil, FormatError(err)
|
|
}
|
|
|
|
if err := tx.Commit(); err != nil {
|
|
return nil, FormatError(err)
|
|
}
|
|
activityMessage := create
|
|
return activityMessage, nil
|
|
}
|