Skip to content

Commit c48a30b

Browse files
committed
feat: spellcheck engine migration to LanguageTool with batch support
1 parent d4b61e8 commit c48a30b

3 files changed

Lines changed: 13 additions & 16 deletions

File tree

apps/api/services/text/spellcheck/service.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,16 @@ func (s *Service) Check(text string) (Result, error) {
7272
// CheckBatch processes multiple texts and returns spell-check results for each.
7373
// It returns an error only if LanguageTool is unreachable; individual texts do
7474
// not produce per-item errors.
75-
func (s *Service) CheckBatch(texts []string) (BatchCheckResponse, error) {
75+
func (s *Service) CheckBatch(texts []string) ([]Result, error) {
7676
results := make([]Result, 0, len(texts))
7777
for _, text := range texts {
7878
result, err := s.Check(text)
7979
if err != nil {
80-
return BatchCheckResponse{}, err
80+
return nil, err
8181
}
8282
results = append(results, result)
8383
}
84-
return BatchCheckResponse{
85-
Results: results,
86-
Total: len(results),
87-
}, nil
84+
return results, nil
8885
}
8986

9087
// buildResult converts LanguageTool matches into our Result type.

apps/api/services/text/spellcheck/transport_http.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ func RegisterRoutes(r chi.Router, svc *Service) {
1717
))
1818

1919
r.Post("/spellcheck/batch", httpx.HandleBatch(
20-
func(_ context.Context, req BatchCheckRequest) (BatchCheckResponse, int, error) {
21-
res, err := svc.CheckBatch(req.Texts)
22-
return res, len(req.Texts), err
20+
func(_ context.Context, req BatchCheckRequest) (BatchCheckResponse, error) {
21+
results, err := svc.CheckBatch(req.Texts)
22+
if err != nil {
23+
return BatchCheckResponse{}, err
24+
}
25+
return BatchCheckResponse{Results: results}, nil
2326
},
2427
))
2528
}

apps/api/services/text/spellcheck/type.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package spellcheck
22

3+
import "requiems-api/platform/httpx"
4+
35
// Request is the input for the spell check endpoint.
46
type Request struct {
57
Text string `json:"text" validate:"required"`
@@ -29,10 +31,5 @@ type BatchCheckRequest struct {
2931
Texts []string `json:"texts" validate:"required,min=1,max=50,dive,required"`
3032
}
3133

32-
// BatchCheckResponse is the response for a batch spell check request.
33-
type BatchCheckResponse struct {
34-
Results []Result `json:"results"`
35-
Total int `json:"total"`
36-
}
37-
38-
func (BatchCheckResponse) IsData() {}
34+
// BatchCheckResponse is the standard batch envelope for spell-check results.
35+
type BatchCheckResponse = httpx.BatchResponse[Result]

0 commit comments

Comments
 (0)