-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support searching character & person (#671)
- Loading branch information
Showing
33 changed files
with
1,667 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package canal | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/trim21/errgo" | ||
"go.uber.org/zap" | ||
|
||
"github.com/bangumi/server/internal/model" | ||
"github.com/bangumi/server/internal/search" | ||
) | ||
|
||
type CharacterKey struct { | ||
ID model.CharacterID `json:"crt_id"` | ||
} | ||
|
||
func (e *eventHandler) OnCharacter(ctx context.Context, key json.RawMessage, payload Payload) error { | ||
var k CharacterKey | ||
if err := json.Unmarshal(key, &k); err != nil { | ||
return err | ||
} | ||
return e.onCharacterChange(ctx, k.ID, payload.Op) | ||
} | ||
|
||
func (e *eventHandler) onCharacterChange(ctx context.Context, characterID model.CharacterID, op string) error { | ||
switch op { | ||
case opCreate: | ||
if err := e.search.EventAdded(ctx, characterID, search.SearchTargetCharacter); err != nil { | ||
return errgo.Wrap(err, "search.OnCharacterAdded") | ||
} | ||
case opUpdate, opSnapshot: | ||
if err := e.search.EventUpdate(ctx, characterID, search.SearchTargetCharacter); err != nil { | ||
return errgo.Wrap(err, "search.OnCharacterUpdate") | ||
} | ||
case opDelete: | ||
if err := e.search.EventDelete(ctx, characterID, search.SearchTargetCharacter); err != nil { | ||
return errgo.Wrap(err, "search.OnCharacterDelete") | ||
} | ||
default: | ||
e.log.Warn("unexpected operator", zap.String("op", op)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package canal | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/trim21/errgo" | ||
"go.uber.org/zap" | ||
|
||
"github.com/bangumi/server/internal/model" | ||
"github.com/bangumi/server/internal/search" | ||
) | ||
|
||
type PersonKey struct { | ||
ID model.PersonID `json:"prsn_id"` | ||
} | ||
|
||
func (e *eventHandler) OnPerson(ctx context.Context, key json.RawMessage, payload Payload) error { | ||
var k PersonKey | ||
if err := json.Unmarshal(key, &k); err != nil { | ||
return err | ||
} | ||
return e.onPersonChange(ctx, k.ID, payload.Op) | ||
} | ||
|
||
func (e *eventHandler) onPersonChange(ctx context.Context, personID model.PersonID, op string) error { | ||
switch op { | ||
case opCreate: | ||
if err := e.search.EventAdded(ctx, personID, search.SearchTargetPerson); err != nil { | ||
return errgo.Wrap(err, "search.OnPersonAdded") | ||
} | ||
case opUpdate, opSnapshot: | ||
if err := e.search.EventUpdate(ctx, personID, search.SearchTargetPerson); err != nil { | ||
return errgo.Wrap(err, "search.OnPersonUpdate") | ||
} | ||
case opDelete: | ||
if err := e.search.EventDelete(ctx, personID, search.SearchTargetPerson); err != nil { | ||
return errgo.Wrap(err, "search.OnPersonDelete") | ||
} | ||
default: | ||
e.log.Warn("unexpected operator", zap.String("op", op)) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.