-
Notifications
You must be signed in to change notification settings - Fork 13
/
update.go
43 lines (35 loc) · 1.29 KB
/
update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package translation
import (
"context"
"fmt"
"github.com/coretrix/hitrix/pkg/dto/translation"
"github.com/coretrix/hitrix/pkg/entity"
"github.com/coretrix/hitrix/pkg/errors"
"github.com/coretrix/hitrix/service"
)
func Update(ctx context.Context, request *translation.RequestUpdateTranslation, id uint64) (*translation.ResponseTranslation, error) {
ormService := service.DI().OrmEngineForContext(ctx)
translationTextEntity := &entity.TranslationTextEntity{}
found := ormService.LoadByID(id, translationTextEntity)
if !found {
return nil,
errors.HandleCustomErrors(map[string]string{"ID": fmt.Sprintf("City with id %v does not exists", id)})
}
translationTextEntity.Lang = request.Lang.String()
translationTextEntity.Key = request.Key.String()
translationTextEntity.Text = request.Text
translationTextEntity.Status = entity.TranslationStatusTranslated.String()
err := ormService.FlushWithCheck(translationTextEntity)
if err != nil {
return nil, errors.HandleFlushWithCheckError(
err,
errors.HandleCustomErrors(map[string]string{"Lang": "text with this lang and key already exists"}),
)
}
return &translation.ResponseTranslation{
ID: translationTextEntity.ID,
Lang: translationTextEntity.Lang,
Key: translationTextEntity.Key,
Text: translationTextEntity.Text,
}, nil
}