@@ -2,20 +2,23 @@ package routes
22
33import (
44 "context"
5+ "errors"
56 "regexp"
67 "unicode/utf8"
78
8- "github.com/f1monkey/spellchecker"
9+ "github.com/f1monkey/spellchecker-web/internal/spellchecker "
910 "github.com/swaggest/usecase"
1011 "github.com/swaggest/usecase/status"
1112)
1213
13- type SpellcheckerFixRequest struct {
14+ type DictionaryFixRequest struct {
15+ Code string `path:"code" minLength:"1"`
16+
1417 Text string `json:"text" description:"Phrase to be checked"`
1518 Limit int `json:"limit" default:"5" desciption:"Max suggestions per word"`
1619}
1720
18- type SpellcheckerFixResponse struct {
21+ type DictionaryFixResponse struct {
1922 Fixes []Fix `json:"fixes" description:"List of detected issues."`
2023}
2124
@@ -33,13 +36,20 @@ type SpellcheckerSuggestion struct {
3336
3437var wordSymbols = regexp .MustCompile (`[-\pL]+` )
3538
36- func SpellcheckerFix ( sc * spellchecker.Spellchecker ) usecase.Interactor {
39+ func dictionaryFix ( registry * spellchecker.Registry ) usecase.Interactor {
3740 const (
3841 errorUnknownWord = "unknown_word"
3942 errorInvalidWord = "invalid_word"
4043 )
4144
42- u := usecase .NewInteractor (func (ctx context.Context , input SpellcheckerFixRequest , output * SpellcheckerFixResponse ) error {
45+ u := usecase .NewInteractor (func (ctx context.Context , input DictionaryFixRequest , output * DictionaryFixResponse ) error {
46+ sc , err := registry .Get (input .Code )
47+ if errors .Is (spellchecker .ErrNotFound , err ) {
48+ return status .Wrap (err , status .NotFound )
49+ } else if err != nil {
50+ return status .Wrap (err , status .Internal )
51+ }
52+
4353 if input .Text == "" {
4454 return nil
4555 }
0 commit comments