2023-04-25 23:27:38 +08:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MemoRelationType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
MemoRelationReference MemoRelationType = "REFERENCE"
|
|
|
|
MemoRelationAdditional MemoRelationType = "ADDITIONAL"
|
|
|
|
)
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
type MemoRelation struct {
|
2023-08-04 21:55:07 +08:00
|
|
|
MemoID int32
|
|
|
|
RelatedMemoID int32
|
2023-04-25 23:27:38 +08:00
|
|
|
Type MemoRelationType
|
|
|
|
}
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
type FindMemoRelation struct {
|
2023-08-04 21:55:07 +08:00
|
|
|
MemoID *int32
|
|
|
|
RelatedMemoID *int32
|
2023-04-25 23:27:38 +08:00
|
|
|
Type *MemoRelationType
|
|
|
|
}
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
type DeleteMemoRelation struct {
|
2023-08-04 21:55:07 +08:00
|
|
|
MemoID *int32
|
|
|
|
RelatedMemoID *int32
|
2023-04-25 23:27:38 +08:00
|
|
|
Type *MemoRelationType
|
|
|
|
}
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
func (s *Store) UpsertMemoRelation(ctx context.Context, create *MemoRelation) (*MemoRelation, error) {
|
2023-09-27 08:43:46 +08:00
|
|
|
return s.driver.UpsertMemoRelation(ctx, create)
|
2023-04-25 23:27:38 +08:00
|
|
|
}
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
func (s *Store) ListMemoRelations(ctx context.Context, find *FindMemoRelation) ([]*MemoRelation, error) {
|
2023-09-27 08:43:46 +08:00
|
|
|
return s.driver.ListMemoRelations(ctx, find)
|
2023-04-25 23:27:38 +08:00
|
|
|
}
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
func (s *Store) GetMemoRelation(ctx context.Context, find *FindMemoRelation) (*MemoRelation, error) {
|
2023-07-20 23:15:56 +08:00
|
|
|
list, err := s.ListMemoRelations(ctx, find)
|
2023-04-25 23:27:38 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(list) == 0 {
|
2023-07-06 21:56:42 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2023-04-25 23:27:38 +08:00
|
|
|
return list[0], nil
|
|
|
|
}
|
|
|
|
|
2023-07-06 21:56:42 +08:00
|
|
|
func (s *Store) DeleteMemoRelation(ctx context.Context, delete *DeleteMemoRelation) error {
|
2023-09-27 08:43:46 +08:00
|
|
|
return s.driver.DeleteMemoRelation(ctx, delete)
|
2023-04-25 23:27:38 +08:00
|
|
|
}
|