Compare commits
2 Commits
payment-hi
...
api-lang-l
| Author | SHA1 | Date | |
|---|---|---|---|
| 72a5ac52b0 | |||
| c6540a658b |
4
app.go
4
app.go
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
// @title Service APIs
|
||||
// @version 1.0
|
||||
// @description Online payment system admin API.
|
||||
// @description Online payment system admin API. Localized fields ({en, ru, tm} objects) come back as a plain string in the language of the `lang` query parameter: tm, ru or en (default tm), falling back to tm, ru, en when that translation is empty. lang=all returns the full {en, ru, tm} objects (for edit forms); any other value is 400.
|
||||
// @host localhost:5005
|
||||
// @BasePath /api/admin
|
||||
// @securityDefinitions.apikey BearerAuth
|
||||
@@ -62,7 +62,7 @@ func main() {
|
||||
|
||||
docs.SwaggerInfo.Title = "Service APIs"
|
||||
docs.SwaggerInfo.Version = "1.0"
|
||||
docs.SwaggerInfo.Description = "Online payment system admin API."
|
||||
docs.SwaggerInfo.Description = "Online payment system admin API. Localized fields ({en, ru, tm} objects) come back as a plain string in the language of the `lang` query parameter: tm, ru or en (default tm), falling back to tm, ru, en when that translation is empty. lang=all returns the full {en, ru, tm} objects (for edit forms); any other value is 400."
|
||||
docs.SwaggerInfo.Host = "localhost:" + cfg.Listen.Port
|
||||
docs.SwaggerInfo.BasePath = "/api/admin"
|
||||
docs.SwaggerInfo.Schemes = []string{"http"}
|
||||
|
||||
24
docs/docs.go
24
docs/docs.go
@@ -8340,7 +8340,7 @@ const docTemplate = `{
|
||||
"type": "boolean"
|
||||
},
|
||||
"address": {
|
||||
"$ref": "#/definitions/branches.LocalizedText"
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"billingPassword": {
|
||||
"type": "string"
|
||||
@@ -8367,7 +8367,7 @@ const docTemplate = `{
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"$ref": "#/definitions/branches.LocalizedText"
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"phoneNumbers": {
|
||||
"type": "string"
|
||||
@@ -8383,20 +8383,6 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"branches.LocalizedText": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"en": {
|
||||
"type": "string"
|
||||
},
|
||||
"ru": {
|
||||
"type": "string"
|
||||
},
|
||||
"tm": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"branches.UpdateBranchDTO": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -8409,7 +8395,7 @@ const docTemplate = `{
|
||||
"type": "boolean"
|
||||
},
|
||||
"address": {
|
||||
"$ref": "#/definitions/branches.LocalizedText"
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"billingPassword": {
|
||||
"type": "string"
|
||||
@@ -8436,7 +8422,7 @@ const docTemplate = `{
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"$ref": "#/definitions/branches.LocalizedText"
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"phoneNumbers": {
|
||||
"type": "string"
|
||||
@@ -11281,7 +11267,7 @@ var SwaggerInfo = &swag.Spec{
|
||||
BasePath: "/api/admin",
|
||||
Schemes: []string{},
|
||||
Title: "Service APIs",
|
||||
Description: "Online payment system admin API.",
|
||||
Description: "Online payment system admin API. Localized fields ({en, ru, tm} objects) come back as a plain string in the language of the `lang` query parameter: tm, ru or en (default tm), falling back to tm, ru, en when that translation is empty. lang=all returns the full {en, ru, tm} objects (for edit forms); any other value is 400.",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
LeftDelim: "{{",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "Online payment system admin API.",
|
||||
"description": "Online payment system admin API. Localized fields ({en, ru, tm} objects) come back as a plain string in the language of the `lang` query parameter: tm, ru or en (default tm), falling back to tm, ru, en when that translation is empty. lang=all returns the full {en, ru, tm} objects (for edit forms); any other value is 400.",
|
||||
"title": "Service APIs",
|
||||
"contact": {},
|
||||
"version": "1.0"
|
||||
@@ -8334,7 +8334,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"address": {
|
||||
"$ref": "#/definitions/branches.LocalizedText"
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"billingPassword": {
|
||||
"type": "string"
|
||||
@@ -8361,7 +8361,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"$ref": "#/definitions/branches.LocalizedText"
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"phoneNumbers": {
|
||||
"type": "string"
|
||||
@@ -8377,20 +8377,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"branches.LocalizedText": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"en": {
|
||||
"type": "string"
|
||||
},
|
||||
"ru": {
|
||||
"type": "string"
|
||||
},
|
||||
"tm": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"branches.UpdateBranchDTO": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
@@ -8403,7 +8389,7 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"address": {
|
||||
"$ref": "#/definitions/branches.LocalizedText"
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"billingPassword": {
|
||||
"type": "string"
|
||||
@@ -8430,7 +8416,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"$ref": "#/definitions/branches.LocalizedText"
|
||||
"$ref": "#/definitions/shared.LocalizedText"
|
||||
},
|
||||
"phoneNumbers": {
|
||||
"type": "string"
|
||||
|
||||
@@ -112,7 +112,7 @@ definitions:
|
||||
active:
|
||||
type: boolean
|
||||
address:
|
||||
$ref: '#/definitions/branches.LocalizedText'
|
||||
$ref: '#/definitions/shared.LocalizedText'
|
||||
billingPassword:
|
||||
type: string
|
||||
billingSberPassword:
|
||||
@@ -130,7 +130,7 @@ definitions:
|
||||
billingVisaMasterUsername:
|
||||
type: string
|
||||
name:
|
||||
$ref: '#/definitions/branches.LocalizedText'
|
||||
$ref: '#/definitions/shared.LocalizedText'
|
||||
phoneNumbers:
|
||||
type: string
|
||||
provinceId:
|
||||
@@ -145,21 +145,12 @@ definitions:
|
||||
- region
|
||||
- uniqueCode
|
||||
type: object
|
||||
branches.LocalizedText:
|
||||
properties:
|
||||
en:
|
||||
type: string
|
||||
ru:
|
||||
type: string
|
||||
tm:
|
||||
type: string
|
||||
type: object
|
||||
branches.UpdateBranchDTO:
|
||||
properties:
|
||||
active:
|
||||
type: boolean
|
||||
address:
|
||||
$ref: '#/definitions/branches.LocalizedText'
|
||||
$ref: '#/definitions/shared.LocalizedText'
|
||||
billingPassword:
|
||||
type: string
|
||||
billingSberPassword:
|
||||
@@ -177,7 +168,7 @@ definitions:
|
||||
billingVisaMasterUsername:
|
||||
type: string
|
||||
name:
|
||||
$ref: '#/definitions/branches.LocalizedText'
|
||||
$ref: '#/definitions/shared.LocalizedText'
|
||||
phoneNumbers:
|
||||
type: string
|
||||
provinceId:
|
||||
@@ -2168,7 +2159,11 @@ definitions:
|
||||
host: localhost:5005
|
||||
info:
|
||||
contact: {}
|
||||
description: Online payment system admin API.
|
||||
description: 'Online payment system admin API. Localized fields ({en, ru, tm} objects)
|
||||
come back as a plain string in the language of the `lang` query parameter: tm,
|
||||
ru or en (default tm), falling back to tm, ru, en when that translation is empty.
|
||||
lang=all returns the full {en, ru, tm} objects (for edit forms); any other value
|
||||
is 400.'
|
||||
title: Service APIs
|
||||
version: "1.0"
|
||||
paths:
|
||||
|
||||
230
internal/appresult/lang.go
Normal file
230
internal/appresult/lang.go
Normal file
@@ -0,0 +1,230 @@
|
||||
package appresult
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// DefaultLang is the language localized fields collapse to when the caller
|
||||
// passes no ?lang=.
|
||||
const DefaultLang = "tm"
|
||||
|
||||
// LangAll keeps every localized field as its full {en, ru, tm} object - what
|
||||
// admin edit forms need to fill all three inputs.
|
||||
const LangAll = "all"
|
||||
|
||||
// langFallback is the order empty translations are filled from.
|
||||
var langFallback = []string{"tm", "ru", "en"}
|
||||
|
||||
// Localize collapses every {"en", "ru", "tm"} object (shared.LocalizedText)
|
||||
// in a JSON response into the plain string for ?lang= (tm, ru or en;
|
||||
// default tm), so clients only download the language they show. ?lang=all
|
||||
// leaves responses untouched. It rewrites the encoded body rather than the
|
||||
// DTOs, so every module gets it without knowing about it; non-JSON
|
||||
// responses (files, images) are streamed through as-is.
|
||||
func Localize() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
lang := strings.ToLower(strings.TrimSpace(c.Query("lang")))
|
||||
switch lang {
|
||||
case "":
|
||||
lang = DefaultLang
|
||||
case "tm", "ru", "en":
|
||||
case LangAll:
|
||||
c.Next()
|
||||
return
|
||||
default:
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, ErrMissingParam)
|
||||
return
|
||||
}
|
||||
|
||||
w := &localizeWriter{ResponseWriter: c.Writer}
|
||||
c.Writer = w
|
||||
c.Next()
|
||||
c.Writer = w.ResponseWriter
|
||||
w.flush(lang)
|
||||
}
|
||||
}
|
||||
|
||||
// localizeWriter buffers JSON bodies until the handler is done, so they can
|
||||
// be rewritten as a whole; anything else goes straight to the client.
|
||||
type localizeWriter struct {
|
||||
gin.ResponseWriter
|
||||
decided bool
|
||||
buffer bool
|
||||
body bytes.Buffer
|
||||
}
|
||||
|
||||
func (w *localizeWriter) Write(data []byte) (int, error) {
|
||||
if !w.decided {
|
||||
w.decided = true
|
||||
w.buffer = strings.HasPrefix(w.Header().Get("Content-Type"), "application/json")
|
||||
}
|
||||
if !w.buffer {
|
||||
return w.ResponseWriter.Write(data)
|
||||
}
|
||||
return w.body.Write(data)
|
||||
}
|
||||
|
||||
func (w *localizeWriter) WriteString(s string) (int, error) {
|
||||
return w.Write([]byte(s))
|
||||
}
|
||||
|
||||
func (w *localizeWriter) flush(lang string) {
|
||||
if w.body.Len() == 0 {
|
||||
return
|
||||
}
|
||||
out, err := localizeJSON(w.body.Bytes(), lang)
|
||||
if err != nil {
|
||||
out = w.body.Bytes()
|
||||
}
|
||||
w.ResponseWriter.Write(out)
|
||||
}
|
||||
|
||||
// localizeJSON re-encodes data token by token - keeping key order and
|
||||
// number precision - with localized objects replaced by their lang string.
|
||||
func localizeJSON(data []byte, lang string) ([]byte, error) {
|
||||
dec := json.NewDecoder(bytes.NewReader(data))
|
||||
dec.UseNumber()
|
||||
var out bytes.Buffer
|
||||
if err := localizeValue(dec, &out, lang); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Bytes(), nil
|
||||
}
|
||||
|
||||
func localizeValue(dec *json.Decoder, out *bytes.Buffer, lang string) error {
|
||||
tok, err := dec.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch t := tok.(type) {
|
||||
case json.Delim:
|
||||
if t == '[' {
|
||||
return localizeArray(dec, out, lang)
|
||||
}
|
||||
return localizeObject(dec, out, lang)
|
||||
case string:
|
||||
return writeString(out, t)
|
||||
case json.Number:
|
||||
out.WriteString(t.String())
|
||||
case bool:
|
||||
if t {
|
||||
out.WriteString("true")
|
||||
} else {
|
||||
out.WriteString("false")
|
||||
}
|
||||
case nil:
|
||||
out.WriteString("null")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func localizeArray(dec *json.Decoder, out *bytes.Buffer, lang string) error {
|
||||
out.WriteByte('[')
|
||||
for i := 0; dec.More(); i++ {
|
||||
if i > 0 {
|
||||
out.WriteByte(',')
|
||||
}
|
||||
if err := localizeValue(dec, out, lang); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := dec.Token(); err != nil { // ']'
|
||||
return err
|
||||
}
|
||||
out.WriteByte(']')
|
||||
return nil
|
||||
}
|
||||
|
||||
type jsonField struct {
|
||||
key string
|
||||
value []byte
|
||||
}
|
||||
|
||||
func localizeObject(dec *json.Decoder, out *bytes.Buffer, lang string) error {
|
||||
var fields []jsonField
|
||||
for dec.More() {
|
||||
keyTok, err := dec.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var value bytes.Buffer
|
||||
if err := localizeValue(dec, &value, lang); err != nil {
|
||||
return err
|
||||
}
|
||||
fields = append(fields, jsonField{key: keyTok.(string), value: value.Bytes()})
|
||||
}
|
||||
if _, err := dec.Token(); err != nil { // '}'
|
||||
return err
|
||||
}
|
||||
|
||||
if text, ok := pickLocalized(fields, lang); ok {
|
||||
return writeString(out, text)
|
||||
}
|
||||
|
||||
out.WriteByte('{')
|
||||
for i, f := range fields {
|
||||
if i > 0 {
|
||||
out.WriteByte(',')
|
||||
}
|
||||
if err := writeString(out, f.key); err != nil {
|
||||
return err
|
||||
}
|
||||
out.WriteByte(':')
|
||||
out.Write(f.value)
|
||||
}
|
||||
out.WriteByte('}')
|
||||
return nil
|
||||
}
|
||||
|
||||
// pickLocalized reports whether fields is exactly a {en, ru, tm} object of
|
||||
// strings/nulls and, if so, returns lang's text - falling back through
|
||||
// langFallback when it's empty.
|
||||
func pickLocalized(fields []jsonField, lang string) (string, bool) {
|
||||
if len(fields) != 3 {
|
||||
return "", false
|
||||
}
|
||||
texts := make(map[string]string, 3)
|
||||
for _, f := range fields {
|
||||
if f.key != "en" && f.key != "ru" && f.key != "tm" {
|
||||
return "", false
|
||||
}
|
||||
if _, dup := texts[f.key]; dup {
|
||||
return "", false
|
||||
}
|
||||
var text *string
|
||||
if err := json.Unmarshal(f.value, &text); err != nil {
|
||||
return "", false
|
||||
}
|
||||
texts[f.key] = ""
|
||||
if text != nil {
|
||||
texts[f.key] = *text
|
||||
}
|
||||
}
|
||||
|
||||
if text := texts[lang]; text != "" {
|
||||
return text, true
|
||||
}
|
||||
for _, l := range langFallback {
|
||||
if text := texts[l]; text != "" {
|
||||
return text, true
|
||||
}
|
||||
}
|
||||
return "", true
|
||||
}
|
||||
|
||||
// writeString encodes s the way gin's c.JSON does (json.Marshal, HTML
|
||||
// escaped), so rewritten bodies match untouched ones byte for byte.
|
||||
func writeString(out *bytes.Buffer, s string) error {
|
||||
encoded, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out.Write(encoded)
|
||||
return nil
|
||||
}
|
||||
106
internal/appresult/lang_test.go
Normal file
106
internal/appresult/lang_test.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package appresult
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func serve(t *testing.T, query string, handler gin.HandlerFunc) *httptest.ResponseRecorder {
|
||||
t.Helper()
|
||||
gin.SetMode(gin.TestMode)
|
||||
router := gin.New()
|
||||
router.Use(Localize())
|
||||
router.GET("/x", handler)
|
||||
|
||||
rec := httptest.NewRecorder()
|
||||
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/x"+query, nil))
|
||||
return rec
|
||||
}
|
||||
|
||||
func jsonHandler(body string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "application/json; charset=utf-8", []byte(body))
|
||||
}
|
||||
}
|
||||
|
||||
const branchBody = `{"id":1,"name":{"en":"Branch","ru":"Филиал","tm":"Şahamça"}}`
|
||||
|
||||
func TestLocalizeLanguages(t *testing.T) {
|
||||
tests := []struct {
|
||||
query string
|
||||
want string
|
||||
}{
|
||||
{"", `{"id":1,"name":"Şahamça"}`},
|
||||
{"?lang=tm", `{"id":1,"name":"Şahamça"}`},
|
||||
{"?lang=ru", `{"id":1,"name":"Филиал"}`},
|
||||
{"?lang=EN", `{"id":1,"name":"Branch"}`},
|
||||
{"?lang=all", branchBody},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
rec := serve(t, tt.query, jsonHandler(branchBody))
|
||||
if rec.Code != http.StatusOK || rec.Body.String() != tt.want {
|
||||
t.Errorf("%q: got %d %s, want %s", tt.query, rec.Code, rec.Body.String(), tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalizeRejectsUnknownLang(t *testing.T) {
|
||||
called := false
|
||||
rec := serve(t, "?lang=xx", func(c *gin.Context) { called = true })
|
||||
if rec.Code != http.StatusBadRequest || called {
|
||||
t.Fatalf("got %d (handler called: %v), want 400 without calling the handler", rec.Code, called)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalizeFallback(t *testing.T) {
|
||||
tests := []struct {
|
||||
body string
|
||||
want string
|
||||
}{
|
||||
{`{"tm":"","ru":"Филиал","en":"Branch"}`, `"Филиал"`},
|
||||
{`{"tm":null,"ru":"","en":"Branch"}`, `"Branch"`},
|
||||
{`{"tm":"","ru":"","en":""}`, `""`},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := serve(t, "", jsonHandler(tt.body)).Body.String(); got != tt.want {
|
||||
t.Errorf("%s: got %s, want %s", tt.body, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalizeKeepsStructure(t *testing.T) {
|
||||
body := `{"z":9007199254740993,"a":[{"b":{"en":"E","ru":"R","tm":"T"},"f":1.10}],` +
|
||||
`"extra":{"en":"E","ru":"R","tm":"T","id":2},"partial":{"en":"E","ru":"R"},` +
|
||||
`"nested":{"en":{"x":1},"ru":"R","tm":"T"},"ok":true,"none":null,"html":"<a&b>"}`
|
||||
want := `{"z":9007199254740993,"a":[{"b":"T","f":1.10}],` +
|
||||
`"extra":{"en":"E","ru":"R","tm":"T","id":2},"partial":{"en":"E","ru":"R"},` +
|
||||
`"nested":{"en":{"x":1},"ru":"R","tm":"T"},"ok":true,"none":null,"html":` + "\"\\u003ca\\u0026b\\u003e\"}"
|
||||
if got := serve(t, "", jsonHandler(body)).Body.String(); got != want {
|
||||
t.Fatalf("got %s\nwant %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalizeMatchesGinJSON(t *testing.T) {
|
||||
rec := serve(t, "?lang=ru", func(c *gin.Context) {
|
||||
c.JSON(http.StatusCreated, SuccessWithData(map[string]interface{}{
|
||||
"name": map[string]string{"en": "Branch", "ru": "Филиал", "tm": "Şahamça"},
|
||||
}))
|
||||
})
|
||||
want := `{"status":true,"message":"Request completed successfully.","code":"SS-10000","data":{"name":"Филиал"}}`
|
||||
if rec.Code != http.StatusCreated || rec.Body.String() != want {
|
||||
t.Fatalf("got %d %s, want 201 %s", rec.Code, rec.Body.String(), want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalizeSkipsNonJSON(t *testing.T) {
|
||||
body := `{"en":"E","ru":"R","tm":"T"}`
|
||||
rec := serve(t, "", func(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "text/plain", []byte(body))
|
||||
})
|
||||
if rec.Body.String() != body {
|
||||
t.Fatalf("got %s, want body untouched", rec.Body.String())
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"online-back/internal/analytics"
|
||||
analyticsdb "online-back/internal/analytics/db"
|
||||
"online-back/internal/appresult"
|
||||
"online-back/internal/backup"
|
||||
backupdb "online-back/internal/backup/db"
|
||||
"online-back/internal/cards"
|
||||
@@ -65,6 +66,8 @@ func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin.
|
||||
}))
|
||||
|
||||
adminGroup := router.Group(adminAPIPrefix)
|
||||
// First, so it sees every admin response; /swagger stays outside it.
|
||||
adminGroup.Use(appresult.Localize())
|
||||
adminGroup.Use(activitylog.Record(activitylogdb.NewRepository(client, logger), logger))
|
||||
if err := perm.Sync(context.Background(), client); err != nil {
|
||||
logger.Fatalf("rbac: sync permission catalog: %v", err)
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package auth
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"online-back/internal/shared"
|
||||
)
|
||||
|
||||
type LoginDTO struct {
|
||||
Name string `json:"name"`
|
||||
@@ -12,12 +16,6 @@ type RefreshTokenDTO struct {
|
||||
RefreshToken string `json:"refreshToken" binding:"required"`
|
||||
}
|
||||
|
||||
type LocalizedText struct {
|
||||
En string `json:"en"`
|
||||
Ru string `json:"ru"`
|
||||
Tm string `json:"tm"`
|
||||
}
|
||||
|
||||
type ProfileRoleDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
Code string `json:"code"`
|
||||
@@ -27,9 +25,9 @@ type ProfileRoleDTO struct {
|
||||
}
|
||||
|
||||
type ProfileBranchDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name LocalizedText `json:"name"`
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name shared.LocalizedText `json:"name"`
|
||||
}
|
||||
|
||||
// ProfilePermissionDTO is one module the caller can open; the front-end
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package user
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
type LocalizedText struct {
|
||||
En string `json:"en"`
|
||||
Ru string `json:"ru"`
|
||||
Tm string `json:"tm"`
|
||||
}
|
||||
"online-back/internal/shared"
|
||||
)
|
||||
|
||||
type StaffBranchDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name LocalizedText `json:"name"`
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name shared.LocalizedText `json:"name"`
|
||||
}
|
||||
|
||||
type UserPermissionDTO struct {
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
package userbranch
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
type LocalizedText struct {
|
||||
En string `json:"en"`
|
||||
Ru string `json:"ru"`
|
||||
Tm string `json:"tm"`
|
||||
}
|
||||
"online-back/internal/shared"
|
||||
)
|
||||
|
||||
type UserBranchDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
UserId int64 `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
BranchId int64 `json:"branchId"`
|
||||
BranchName LocalizedText `json:"branchName"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
Id int64 `json:"id"`
|
||||
UserId int64 `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
BranchId int64 `json:"branchId"`
|
||||
BranchName shared.LocalizedText `json:"branchName"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type CreateUserBranchDTO struct {
|
||||
|
||||
@@ -273,7 +273,7 @@ func (r *repository) ensureProvince(ctx context.Context, provinceID *int64) erro
|
||||
return err
|
||||
}
|
||||
|
||||
func marshalBranchJSON(name, address branches.LocalizedText) ([]byte, []byte, error) {
|
||||
func marshalBranchJSON(name, address shared.LocalizedText) ([]byte, []byte, error) {
|
||||
nameJSON, err := json.Marshal(name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -1,64 +1,60 @@
|
||||
package branches
|
||||
|
||||
type LocalizedText struct {
|
||||
En string `json:"en"`
|
||||
Ru string `json:"ru"`
|
||||
Tm string `json:"tm"`
|
||||
}
|
||||
import "online-back/internal/shared"
|
||||
|
||||
type BranchDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name LocalizedText `json:"name"`
|
||||
Address LocalizedText `json:"address"`
|
||||
Region string `json:"region"`
|
||||
ProvinceId *int64 `json:"provinceId"`
|
||||
ProvinceName LocalizedText `json:"provinceName"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
BillingUsername string `json:"billingUsername"`
|
||||
BillingPassword string `json:"billingPassword"`
|
||||
BillingSberUsername string `json:"billingSberUsername"`
|
||||
BillingSberPassword string `json:"billingSberPassword"`
|
||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||
Active bool `json:"active"`
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name shared.LocalizedText `json:"name"`
|
||||
Address shared.LocalizedText `json:"address"`
|
||||
Region string `json:"region"`
|
||||
ProvinceId *int64 `json:"provinceId"`
|
||||
ProvinceName shared.LocalizedText `json:"provinceName"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
BillingUsername string `json:"billingUsername"`
|
||||
BillingPassword string `json:"billingPassword"`
|
||||
BillingSberUsername string `json:"billingSberUsername"`
|
||||
BillingSberPassword string `json:"billingSberPassword"`
|
||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
type CreateBranchDTO struct {
|
||||
UniqueCode string `json:"uniqueCode" binding:"required,numeric,len=4"`
|
||||
Name LocalizedText `json:"name" binding:"required"`
|
||||
Address LocalizedText `json:"address" binding:"required"`
|
||||
Region string `json:"region" binding:"required"`
|
||||
ProvinceId *int64 `json:"provinceId"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
BillingUsername string `json:"billingUsername"`
|
||||
BillingPassword string `json:"billingPassword"`
|
||||
BillingSberUsername string `json:"billingSberUsername"`
|
||||
BillingSberPassword string `json:"billingSberPassword"`
|
||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||
Active *bool `json:"active"`
|
||||
UniqueCode string `json:"uniqueCode" binding:"required,numeric,len=4"`
|
||||
Name shared.LocalizedText `json:"name" binding:"required"`
|
||||
Address shared.LocalizedText `json:"address" binding:"required"`
|
||||
Region string `json:"region" binding:"required"`
|
||||
ProvinceId *int64 `json:"provinceId"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
BillingUsername string `json:"billingUsername"`
|
||||
BillingPassword string `json:"billingPassword"`
|
||||
BillingSberUsername string `json:"billingSberUsername"`
|
||||
BillingSberPassword string `json:"billingSberPassword"`
|
||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||
Active *bool `json:"active"`
|
||||
}
|
||||
|
||||
type UpdateBranchDTO struct {
|
||||
Name LocalizedText `json:"name" binding:"required"`
|
||||
Address LocalizedText `json:"address" binding:"required"`
|
||||
Region string `json:"region" binding:"required"`
|
||||
ProvinceId *int64 `json:"provinceId"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
BillingUsername string `json:"billingUsername"`
|
||||
BillingPassword string `json:"billingPassword"`
|
||||
BillingSberUsername string `json:"billingSberUsername"`
|
||||
BillingSberPassword string `json:"billingSberPassword"`
|
||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||
Active bool `json:"active"`
|
||||
Name shared.LocalizedText `json:"name" binding:"required"`
|
||||
Address shared.LocalizedText `json:"address" binding:"required"`
|
||||
Region string `json:"region" binding:"required"`
|
||||
ProvinceId *int64 `json:"provinceId"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
BillingUsername string `json:"billingUsername"`
|
||||
BillingPassword string `json:"billingPassword"`
|
||||
BillingSberUsername string `json:"billingSberUsername"`
|
||||
BillingSberPassword string `json:"billingSberPassword"`
|
||||
BillingVisaMasterUsername string `json:"billingVisaMasterUsername"`
|
||||
BillingVisaMasterPassword string `json:"billingVisaMasterPassword"`
|
||||
BillingSwiftUsername string `json:"billingSwiftUsername"`
|
||||
BillingSwiftPassword string `json:"billingSwiftPassword"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
type ListFilter struct {
|
||||
@@ -74,12 +70,12 @@ type ListFilter struct {
|
||||
// BranchListItemDTO is the list row; address, region and billing credentials
|
||||
// come from GET /branches/:id.
|
||||
type BranchListItemDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name LocalizedText `json:"name"`
|
||||
ProvinceName LocalizedText `json:"provinceName"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
Active bool `json:"active"`
|
||||
Id int64 `json:"id"`
|
||||
UniqueCode string `json:"uniqueCode"`
|
||||
Name shared.LocalizedText `json:"name"`
|
||||
ProvinceName shared.LocalizedText `json:"provinceName"`
|
||||
PhoneNumbers string `json:"phoneNumbers"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
type ListBranchDTO struct {
|
||||
|
||||
Reference in New Issue
Block a user