Skip to content

resource

muune edited this page Mar 6, 2019 · 24 revisions

resource ์ดˆ๊ธฐ ์…‹ํŒ…

Ch.res

resource ์ˆ˜๋™์œผ๋กœ ๋งŒ๋“ค๊ธฐ

resource ์ดˆ๊ธฐ ์…‹ํŒ…

  • Ch ์ƒ์„ฑ์ž์—์„œ ๋‘๋ฒˆ์งธ ์ธ์ž๋กœ ๋ฐ›์€ path์—์„œ ๊ฐ๊ฐ์˜ resource(i18n, font, style, shape, api, ruleset, query, db)๊ฐ€ ์ฒ˜๋ฆฌ๋œ๋‹ค.
  • ์ฒ˜์Œ์— ๋กœ์ปฌํŒŒ์ผ์— ์žˆ๋Š” json์„ ์ฝ์–ด์˜ค๊ณ , ๊ฐ๊ฐ์˜ resource์— ๋”ฐ๋ผ ๋ฆฌ์†Œ์Šค๊ฐ€ Resํ˜•ํƒœ๋กœ ์ƒ์„ฑ๋˜์„œ DB์— id์™€ ๋‚ด์šฉ์ด ๋“ค์–ด๊ฐ„๋‹ค.
  • ์ธํ„ฐ๋„ท์ด ์‚ฌ์šฉ์ด ์•ˆ ๋˜๋Š” ํ™˜๊ฒฝ์ด๋ฉด ์ด ๋กœ์ปฌํŒŒ์ผ์˜ ๋‚ด์šฉ๋“ค๋กœ๋งŒ ์‹คํ–‰์ด ๋œ๋‹ค.
  • ํ˜ธ์ŠคํŠธ ์ฝ”๋“œ์—์„œ gateway๋กœ ์„ ์–ธํ•œ api๋กœ ํ†ต์‹ ํ•ด์„œ json์„ ๋ถˆ๋Ÿฌ์˜ค๊ณ  ์ด ๋‚ด์šฉ์œผ๋กœ ๋ฆฌ์†Œ์Šค๊ฐ€ Resํ˜•ํƒœ๋กœ DB์— ์‚ญ์ œ, ๋ณ€๊ฒฝ, ์ถ”๊ฐ€๋œ๋‹ค. * ์•„๋ž˜ Ch.res.load() ์ฐธ๊ณ 
  • ์ฐธ๊ณ  Chela init
//App.kt
//Ch(application:Application, path:String = "")
Ch(this, "setting.json")
// setting.json
// "inited"๊ฐ€ db์— ์ €์žฅ๋  ๋•Œ์˜ key
{
  "inited": {
    "api": {
      "gateway": {
        "url": "http://www.bsidesoft.com:9980/seller2/api/gateway",
        "method": "POST",
        "requestTask": "akey|sheader|gateway|aes",
        "responseTask": "pkey|aes|json|error|data",
        "request": {
          "id": {}
        }
      }
    },
    "i18n": {
      "language": "en",
      "footer": {
        "ver": 1,
        "isOne": "en",
        "data": {
          "en": {
            "footer": "2019 ยฉZalagar Seoul All Rights Reserved."
          }
        }
      }
    },
    "shape": {
      "inputFocus": {
        "corner": "5dp",
        "strokeWidth": "1.5dp",
        "strokeColor": "#18ba9b",
        "solid": "#ffffff"
      }
    },
    "font": {
      "nn": "https://www.bsidesoft.com/hika/nanum.png"
    },
    "style": {
      "actionbar": {
        "background": "#18ba9b"
      },
      "alert": {
        "background": "#fa635c",
        "textColor": "#ffffff",
        "textSize": "12dp"
      }
    },
    "db": {
      "seller": {
        "isDefault": true,
        "asset": "seller.mp4",
        "keyProvider": "base"
      }
    }
  }
}

Ch.res

Ch.res.load()

Ch.res.load(res:JSONObject)
  • Resource json์„ ๋ถˆ๋Ÿฌ์˜จ๋‹ค.
  • ๊ฐ๊ฐ์˜ Resource(i18n, font, style, shape, api, ruleset, query, db)์— ๋”ฐ๋ผ ๋ฆฌ์†Œ์Šค๊ฐ€ Resํ˜•ํƒœ๋กœ ์ƒ์„ฑ๋˜์„œ DB์— ๋‚ด์šฉ์ด ๋“ค์–ด๊ฐ€๊ฒŒ ๋œ๋‹ค.
  • "remove"์— ์‚ญ์ œํ•  key๋ฅผ ์ ์–ด์ฃผ๋ฉด ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ๋Š” ๋‹ค ์ง€์›Œ์ค€๋‹ค.
//http://www.bsidesoft.com:9980/seller2/api/gateway์˜ ๋‚ด์šฉ
// "gateway#1"๊ฐ€ db์— ์ €์žฅ๋  ๋•Œ์˜ key
{
  "data": {
    "remove": [
      "old1",
      "old2"
    ],
    "gateway#1": {
      "api": {
        "base": "https://seller2.bsidesoft.com/",
        "islogin": {
          "url": "/api/?member/islogin",
          "method": "POST",
          "requestTask": "sheader",
          "responseTask": "json|data",
          "request": {
            "authtoken": {}
          }
        },
        "login": {
          "url": "/api/?member/signin",
          "method": "POST",
          "requestTask": "sheader|jsonBody",
          "responseTask": "json|authtoken|error|data[us.slab.seller.vo.User]",
          "request": {
            "userid": {
              "name": "userid",
              "rules": "se.userid"
            },
            "pass": {
              "name": "userpw",
              "rules": "se.pass"
            }
          }
        }
      },
      "ruleset": {
        "se": {
          "userid": "string|firstlower|lowernum|minLength[4]|maxLength[30]",
          "useridInput": "string|firstlower|lowernum|maxLength[30]",
          "pass": "string|noblank|minLength[4]|maxLength[30]",
          "passInput": "string|noblank|maxLength[30]",
          "name": "string|minLength[1]|maxLength[255]",
          "email": "string|email|minLength[4]|maxLength[255]",
          "phone": "string|maxLength[255]",
          "authtoken": "string|maxLength[255]"
        }
      },
      "query": {
        "se_add": [
          "REPLACE into seller(userid,name,email,phone,authtoken)values(",
          "@userid:se.userid@, @name:se.name@, @email:se.email@, @phone:se.phone@, @authtoken:se.authtoken@)"
        ],
        "se_get": "select userid,name,email,phone,authtoken,regdate from seller limit 1"
      }
    }
  }
}
if(Ch.net.isOn()){
    App.isLoading(true)
    Log.i("ch", "Ch.res.ids - ${Ch.res.ids}")
    val result = Ch.net.api("gateway", "id" to Ch.res.ids){
        Ch.res.load(it.result as JSONObject)
        go()
    }
    if(result.isFail()){
        Log.i("ch", result.msg )
        go()
    }
}