From 8f5f8c06244662800d5596a9806b5e4aacd4e0ca Mon Sep 17 00:00:00 2001 From: TangBin Date: Mon, 27 Aug 2018 19:28:53 +0800 Subject: [PATCH 1/5] add notice mod --- pkg/mcclient/modules/mod_notices.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pkg/mcclient/modules/mod_notices.go diff --git a/pkg/mcclient/modules/mod_notices.go b/pkg/mcclient/modules/mod_notices.go new file mode 100644 index 0000000000..1456958612 --- /dev/null +++ b/pkg/mcclient/modules/mod_notices.go @@ -0,0 +1,26 @@ +package modules + +type NoticeManager struct { + ResourceManager +} + +type NoticeReadMarkManager struct { + ResourceManager +} + +var ( + Notice NoticeManager + NoticeReadMark NoticeReadMarkManager +) + +func init() { + Version = VersionManager{NewYunionAgentManager("notice", "notices", + []string{}, + []string{})} + register(&Notice) + + NoticeReadMark = NoticeReadMarkManager{NewYunionAgentManager("readmark", "readmarks", + []string{}, + []string{})} + register(&Notice) +} From 2703745e749f848a500ae31e08bdb9e12876e638 Mon Sep 17 00:00:00 2001 From: TangBin Date: Mon, 27 Aug 2018 19:36:16 +0800 Subject: [PATCH 2/5] add notice mod --- pkg/mcclient/modules/mod_notices.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mcclient/modules/mod_notices.go b/pkg/mcclient/modules/mod_notices.go index 1456958612..f0067ee84f 100644 --- a/pkg/mcclient/modules/mod_notices.go +++ b/pkg/mcclient/modules/mod_notices.go @@ -22,5 +22,5 @@ func init() { NoticeReadMark = NoticeReadMarkManager{NewYunionAgentManager("readmark", "readmarks", []string{}, []string{})} - register(&Notice) + register(&NoticeReadMark) } From b419132cfec91b9a4163f1818584454fe1afc9c9 Mon Sep 17 00:00:00 2001 From: TangBin Date: Mon, 27 Aug 2018 19:44:33 +0800 Subject: [PATCH 3/5] bugfix --- pkg/mcclient/modules/mod_notices.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mcclient/modules/mod_notices.go b/pkg/mcclient/modules/mod_notices.go index f0067ee84f..4df4ae966a 100644 --- a/pkg/mcclient/modules/mod_notices.go +++ b/pkg/mcclient/modules/mod_notices.go @@ -14,7 +14,7 @@ var ( ) func init() { - Version = VersionManager{NewYunionAgentManager("notice", "notices", + Notice = NoticeManager{NewYunionAgentManager("notice", "notices", []string{}, []string{})} register(&Notice) From bbe0c66dd6f76fa1fcf4abd2d925290e69fd2cc4 Mon Sep 17 00:00:00 2001 From: TangBin Date: Tue, 28 Aug 2018 11:49:57 +0800 Subject: [PATCH 4/5] add notice climc command --- cmd/climc/shell/notices.go | 79 +++++++++++++++++++++++++++++ pkg/mcclient/modules/mod_notices.go | 4 +- 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 cmd/climc/shell/notices.go diff --git a/cmd/climc/shell/notices.go b/cmd/climc/shell/notices.go new file mode 100644 index 0000000000..697316fb62 --- /dev/null +++ b/cmd/climc/shell/notices.go @@ -0,0 +1,79 @@ +package shell + +import ( + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/pkg/mcclient/modules" +) + +func init() { + type NoticesListOptions struct { + BaseListOptions + } + + R(&NoticesListOptions{}, "notice-list", "list notices", func(s *mcclient.ClientSession, args *NoticesListOptions) error { + params := FetchPagingParams(args.BaseListOptions) + + result, err := modules.Notice.List(s, params) + if err != nil { + return err + } + printList(result, modules.Notice.GetColumns(s)) + return nil + }) + + type NoticesCreateOptions struct { + TITLE string `help:"The notice title"` + CONTENT string `help:"The notice content"` + } + + R(&NoticesCreateOptions{}, "notice-create", "create a notice", func(s *mcclient.ClientSession, args *NoticesCreateOptions) error { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString(args.TITLE), "title") + params.Add(jsonutils.NewString(args.CONTENT), "content") + + notice, err := modules.Notice.Create(s, params) + if err != nil { + return err + } + printObject(notice) + return nil + }) + + type NoticesUpdateOptions struct { + ID string `help:"ID of notice to update"` + Title string `help:"The notice title"` + Content string `help:"The notice content"` + } + + R(&NoticesUpdateOptions{}, "notice-update", "update notice", func(s *mcclient.ClientSession, args *NoticesUpdateOptions) error { + params := jsonutils.NewDict() + if len(args.Title) > 0 { + params.Add(jsonutils.NewString(args.Title), "title") + } + + if len(args.Content) > 0 { + params.Add(jsonutils.NewString(args.Content), "content") + } + + notice, err := modules.Notice.Update(s, args.ID, params) + if err != nil { + return err + } + printObject(notice) + return nil + }) + + type NoticesDeleteOptions struct { + ID string `help:"ID of notice to update"` + } + + R(&NoticesDeleteOptions{}, "notice-delete", "delete notice", func(s *mcclient.ClientSession, args *NoticesDeleteOptions) error { + notice, err := modules.Notice.Delete(s, args.ID, nil) + if err != nil { + return err + } + printObject(notice) + return nil + }) +} diff --git a/pkg/mcclient/modules/mod_notices.go b/pkg/mcclient/modules/mod_notices.go index 4df4ae966a..8a5b755371 100644 --- a/pkg/mcclient/modules/mod_notices.go +++ b/pkg/mcclient/modules/mod_notices.go @@ -15,12 +15,12 @@ var ( func init() { Notice = NoticeManager{NewYunionAgentManager("notice", "notices", - []string{}, + []string{"id", "title", "content"}, []string{})} register(&Notice) NoticeReadMark = NoticeReadMarkManager{NewYunionAgentManager("readmark", "readmarks", []string{}, - []string{})} + []string{"notice_id", "user_id"})} register(&NoticeReadMark) } From a0da87cee59ac767059b47241a3ad131749cab84 Mon Sep 17 00:00:00 2001 From: TangBin Date: Tue, 28 Aug 2018 19:45:33 +0800 Subject: [PATCH 5/5] allow return update time --- pkg/mcclient/modules/mod_notices.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mcclient/modules/mod_notices.go b/pkg/mcclient/modules/mod_notices.go index 8a5b755371..48c704d450 100644 --- a/pkg/mcclient/modules/mod_notices.go +++ b/pkg/mcclient/modules/mod_notices.go @@ -15,7 +15,7 @@ var ( func init() { Notice = NoticeManager{NewYunionAgentManager("notice", "notices", - []string{"id", "title", "content"}, + []string{"id", "created_at", "updated_at","author_id", "author", "title", "content"}, []string{})} register(&Notice)