Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

공지사항 게시판을 만들어 보자..

...

GET {{protocol}}://{{hostname}}:{{port}}/node/nodeType/noticeBoard

GET {{protocol}}://{{hostname}}:{{port}}/node/nodeType/read.json?id=noticeBoard

GET {{protocol}}://{{hostname}}:{{port}}/node/nodeType/list.json?id_matching=noticeBoard

GET {{protocol}}://{{hostname}}:{{port}}/node/propertyType/list.json?tid_matching=noticeBoard

...

Info

POST {{protocol}}://{{hostname}}:{{port}}/adm/notice/updateStatustest

Api Schema

Code Block
{
  "typeId": "api",
  "category": "notice",
  "apiId": "test",
  "apiName": "서비스 작성 이벤트 실행",
  "apiType": "admin",
  "method": "POST",
  "parameters": [
  ],
  "config": [
    {
      "configId": "root",
      "tid": "noticeBoard",
      "type": "event",
      "allowParams": false,
      "orderNo": 1,
      "event": "testEvent"
    }
  ]
}

Config

  • type : event

  • event : testEvent → 별도 이벤트 작성

NodeType Schema 에 Event 추가

Code Block
[
  {
    "typeId": "nodeType",
    "parentId": "root",
    "tid": "noticeBoard",
    "typeName": "게시판",
    "repositoryType": "node",
    "tableName": "",
    "propertyTypes": [
    ],
    "events": [
      {
        "event": "testEvent",
        "name": "테스트 이벤트",
        "noneExecute": true,
        "eventActions": [
          {
            "action": "testAction",
            "actionName": "테스트 이벤트 작성",
            "actionType": "service",
            "actionBody": "noticeBoardService.test",
            "order": 1
          }
        ]
      }
    ]
  }
]

Events

  • event : 기본 event 명 (create,update,delete 등)을 제외한 유니크한 아이디로 작성

EventActions

  • actionType : service

  • actionBody : noticeboardService.test → @Service annotation name.method

Service Java 작성

Code Block
package net.ion.ice.services.commerce;

import net.ion.ice.core.api.ApiException;
import net.ion.ice.core.context.ExecuteContext;
import net.ion.ice.core.query.QueryResult;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;
import java.util.Map;

@Service("noticeBoardService")
public class NoticeBoardService {

    public void test(ExecuteContext context) {
        Map<String, Object> params = context.getData();


        // 코딩


        //Error 처리
        if (false) {
            throw new ApiException("404", "Not Found Data");
        }

        //Response Result 세팅
        QueryResult result = new QueryResult();
        result.setResult("201");
        result.setResultMessage("서비스 성공");

        Map<String, Object> map = new LinkedHashMap<>();
        map.put("a", "1");
        map.put("b", "2");
        map.put("c", "3");

        result.setItem(map);
        result.put("apple", "사과");

        context.setResult(result);

    }
}

  • Event 에서 사용할 Service

    • @Service annotation 필수

    • event에서 직접 호출할 method 는 반드시 ExecuteContext 를 인자로 갖는다.

    • public void test(ExecuteContext context)

Api Result

Code Block
{
    "result": "201",
    "resultMessage": "서비스 성공",
    "item": {
        "a": "1",
        "b": "2",
        "c": "3"
    },
    "apple": "사과"
}
Code Block
{
    "result": "404",
    "resultMessage": "Not Found Data"
}