Skip to content

Commit d3362d0

Browse files
authored
Merge pull request #585 from actiontech/company-notice-ce
Company notice ce
2 parents 9cd1221 + 9f43210 commit d3362d0

7 files changed

Lines changed: 132 additions & 19 deletions

File tree

api/dms/service/v1/company_notice.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@ package v1
22

33
import (
44
base "github.com/actiontech/dms/pkg/dms-common/api/base/v1"
5+
"time"
56
)
67

8+
// swagger:parameters GetCompanyNotice
9+
type GetCompanyNoticeReq struct {
10+
// When true, return the latest notice record regardless of the display time window (e.g. expired or not yet started); intended for admin edit forms.
11+
// in: query
12+
IncludeLatestOutsidePeriod bool `query:"include_latest_outside_period" json:"include_latest_outside_period"`
13+
}
14+
715
// A companynotice
816
type CompanyNotice struct {
917
// companynotice info
1018
NoticeStr string `json:"notice_str"`
19+
// companynotice creator name
20+
CreateUserName string `json:"create_user_name"`
1121
// current user has been read
1222
ReadByCurrentUser bool `json:"read_by_current_user"`
23+
// notice show start time
24+
StartTime *time.Time `json:"start_time,omitempty"`
25+
// notice expire time
26+
ExpireTime *time.Time `json:"expire_time,omitempty"`
1327
}
1428

1529
// swagger:model GetCompanyNoticeReply
@@ -28,5 +42,9 @@ type UpdateCompanyNoticeReq struct {
2842
// A companynotice
2943
type UpdateCompanyNotice struct {
3044
// companynotice info
31-
NoticeStr *string `json:"notice_str" valid:"omitempty"`
45+
NoticeStr *string `json:"notice_str" validate:"required"`
46+
// notice show start time
47+
StartTime *time.Time `json:"start_time" validate:"required"`
48+
// notice show end time
49+
EndTime *time.Time `json:"end_time" validate:"required"`
3250
}

api/swagger.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
"CompanyNotice"
4848
],
4949
"operationId": "GetCompanyNotice",
50+
"parameters": [
51+
{
52+
"type": "boolean",
53+
"x-go-name": "IncludeLatestOutsidePeriod",
54+
"description": "when true, return the latest notice regardless of display window (for admin edit)",
55+
"name": "include_latest_outside_period",
56+
"in": "query"
57+
}
58+
],
5059
"responses": {
5160
"200": {
5261
"description": "GetCompanyNoticeReply",
@@ -8069,6 +8078,17 @@
80698078
"description": "A companynotice",
80708079
"type": "object",
80718080
"properties": {
8081+
"create_user_name": {
8082+
"description": "companynotice creator name",
8083+
"type": "string",
8084+
"x-go-name": "CreateUserName"
8085+
},
8086+
"expire_time": {
8087+
"description": "notice expire time",
8088+
"type": "string",
8089+
"format": "date-time",
8090+
"x-go-name": "ExpireTime"
8091+
},
80728092
"notice_str": {
80738093
"description": "companynotice info",
80748094
"type": "string",
@@ -8078,6 +8098,12 @@
80788098
"description": "current user has been read",
80798099
"type": "boolean",
80808100
"x-go-name": "ReadByCurrentUser"
8101+
},
8102+
"start_time": {
8103+
"description": "notice show start time",
8104+
"type": "string",
8105+
"format": "date-time",
8106+
"x-go-name": "StartTime"
80818107
}
80828108
},
80838109
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
@@ -14300,10 +14326,22 @@
1430014326
"description": "A companynotice",
1430114327
"type": "object",
1430214328
"properties": {
14329+
"end_time": {
14330+
"description": "notice show end time",
14331+
"type": "string",
14332+
"format": "date-time",
14333+
"x-go-name": "EndTime"
14334+
},
1430314335
"notice_str": {
1430414336
"description": "companynotice info",
1430514337
"type": "string",
1430614338
"x-go-name": "NoticeStr"
14339+
},
14340+
"start_time": {
14341+
"description": "notice show start time",
14342+
"type": "string",
14343+
"format": "date-time",
14344+
"x-go-name": "StartTime"
1430714345
}
1430814346
},
1430914347
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"

api/swagger.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,15 @@ definitions:
901901
CompanyNotice:
902902
description: A companynotice
903903
properties:
904+
create_user_name:
905+
description: companynotice creator name
906+
type: string
907+
x-go-name: CreateUserName
908+
expire_time:
909+
description: notice expire time
910+
format: date-time
911+
type: string
912+
x-go-name: ExpireTime
904913
notice_str:
905914
description: companynotice info
906915
type: string
@@ -909,6 +918,11 @@ definitions:
909918
description: current user has been read
910919
type: boolean
911920
x-go-name: ReadByCurrentUser
921+
start_time:
922+
description: notice show start time
923+
format: date-time
924+
type: string
925+
x-go-name: StartTime
912926
type: object
913927
x-go-package: github.com/actiontech/dms/api/dms/service/v1
914928
ComponentNameWithVersion:
@@ -5924,10 +5938,20 @@ definitions:
59245938
UpdateCompanyNotice:
59255939
description: A companynotice
59265940
properties:
5941+
end_time:
5942+
description: notice show end time
5943+
format: date-time
5944+
type: string
5945+
x-go-name: EndTime
59275946
notice_str:
59285947
description: companynotice info
59295948
type: string
59305949
x-go-name: NoticeStr
5950+
start_time:
5951+
description: notice show start time
5952+
format: date-time
5953+
type: string
5954+
x-go-name: StartTime
59315955
type: object
59325956
x-go-package: github.com/actiontech/dms/api/dms/service/v1
59335957
UpdateCompanyNoticeReq:
@@ -6937,6 +6961,12 @@ paths:
69376961
get:
69386962
description: get company notice info
69396963
operationId: GetCompanyNotice
6964+
parameters:
6965+
- description: when true, return the latest notice regardless of display window (for admin edit)
6966+
in: query
6967+
name: include_latest_outside_period
6968+
type: boolean
6969+
x-go-name: IncludeLatestOutsidePeriod
69406970
responses:
69416971
"200":
69426972
description: GetCompanyNoticeReply

internal/apiserver/service/dms_controller.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,20 +3470,36 @@ func (ctl *DMSController) WebHookSendMessage(c echo.Context) error {
34703470
return NewOkResp(c)
34713471
}
34723472

3473-
// swagger:route GET /v1/dms/company_notice CompanyNotice GetCompanyNotice
3473+
// swagger:operation GET /v1/dms/company_notice CompanyNotice GetCompanyNotice
34743474
//
34753475
// get company notice info
34763476
//
3477-
// responses:
3478-
// 200: body:GetCompanyNoticeReply
3479-
// default: body:GenericResp
3477+
// ---
3478+
// parameters:
3479+
// - name: include_latest_outside_period
3480+
// description: when true, return the latest notice regardless of display window (for admin edit)
3481+
// in: query
3482+
// required: false
3483+
// type: boolean
3484+
// responses:
3485+
// '200':
3486+
// description: GetCompanyNoticeReply
3487+
// schema:
3488+
// "$ref": "#/definitions/GetCompanyNoticeReply"
3489+
// default:
3490+
// description: GenericResp
3491+
// schema:
3492+
// "$ref": "#/definitions/GenericResp"
34803493
func (ctl *DMSController) GetCompanyNotice(c echo.Context) error {
3481-
// get current user id
3494+
var req aV1.GetCompanyNoticeReq
3495+
if err := bindAndValidateReq(c, &req); err != nil {
3496+
return NewErrResp(c, err, apiError.BadRequestErr)
3497+
}
34823498
currentUserUid, err := jwt.GetUserUidStrFromContext(c)
34833499
if err != nil {
34843500
return NewErrResp(c, err, apiError.DMSServiceErr)
34853501
}
3486-
reply, err := ctl.DMS.GetCompanyNotice(c.Request().Context(), currentUserUid)
3502+
reply, err := ctl.DMS.GetCompanyNotice(c.Request().Context(), currentUserUid, req.IncludeLatestOutsidePeriod)
34873503
if err != nil {
34883504
return NewErrResp(c, err, apiError.APIServerErr)
34893505
}
@@ -3517,7 +3533,11 @@ func (ctl *DMSController) UpdateCompanyNotice(c echo.Context) error {
35173533
if nil != err {
35183534
return NewErrResp(c, err, apiError.BadRequestErr)
35193535
}
3520-
err = ctl.DMS.UpdateCompanyNotice(c.Request().Context(), req)
3536+
currentUserUid, err := jwt.GetUserUidStrFromContext(c)
3537+
if err != nil {
3538+
return NewErrResp(c, err, apiError.DMSServiceErr)
3539+
}
3540+
err = ctl.DMS.UpdateCompanyNotice(c.Request().Context(), currentUserUid, req)
35213541
if err != nil {
35223542
return NewErrResp(c, err, apiError.APIServerErr)
35233543
}

internal/dms/biz/company_notice.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package biz
22

33
import (
44
"context"
5+
"time"
56

67
pkgRand "github.com/actiontech/dms/pkg/rand"
78

@@ -11,9 +12,12 @@ import (
1112
type CompanyNotice struct {
1213
Base
1314

14-
UID string
15-
NoticeStr string
16-
ReadUserIds []string
15+
UID string
16+
CreateUserUID string
17+
NoticeStr string
18+
ReadUserIds []string
19+
StartTime *time.Time
20+
EndTime *time.Time
1721
}
1822

1923
func initCompanyNotice() (*CompanyNotice, error) {

internal/dms/biz/company_notice_ce.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ package biz
55
import (
66
"context"
77
"errors"
8+
"time"
89
)
910

1011
var errNotSupportCompanyNotice = errors.New("company notice related functions are enterprise version functions")
1112

12-
func (d *CompanyNoticeUsecase) UpdateCompanyNotice(ctx context.Context, noticeStr *string) error {
13+
func (d *CompanyNoticeUsecase) UpdateCompanyNotice(ctx context.Context, currentUserUID string, noticeStr *string, startTime, endTime *time.Time) error {
1314

1415
return errNotSupportCompanyNotice
1516
}
1617

17-
func (d *CompanyNoticeUsecase) GetCompanyNotice(ctx context.Context, userId string) (notice *CompanyNotice, exist bool, err error) {
18-
return nil, false, errNotSupportCompanyNotice
18+
func (d *CompanyNoticeUsecase) GetCompanyNotice(ctx context.Context, userId string, includeLatestOutsidePeriod bool) (notice *CompanyNotice, err error) {
19+
return nil, errNotSupportCompanyNotice
1920
}

internal/dms/service/company_notice.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ import (
66
dmsV1 "github.com/actiontech/dms/api/dms/service/v1"
77
)
88

9-
func (d *DMSService) GetCompanyNotice(ctx context.Context, currentUserUid string) (reply *dmsV1.GetCompanyNoticeReply, err error) {
10-
companyNotice, read, err := d.CompanyNoticeUsecase.GetCompanyNotice(ctx, currentUserUid)
9+
func (d *DMSService) GetCompanyNotice(ctx context.Context, currentUserUid string, includeLatestOutsidePeriod bool) (reply *dmsV1.GetCompanyNoticeReply, err error) {
10+
companyNotice, err := d.CompanyNoticeUsecase.GetCompanyNotice(ctx, currentUserUid, includeLatestOutsidePeriod)
1111
if err != nil {
1212
return nil, err
1313
}
1414
data := dmsV1.CompanyNotice{
15-
ReadByCurrentUser: read,
15+
ReadByCurrentUser: false,
1616
}
1717
if companyNotice != nil {
1818
data.NoticeStr = companyNotice.NoticeStr
19+
data.StartTime = companyNotice.StartTime
20+
data.ExpireTime = companyNotice.EndTime
1921
}
2022
return &dmsV1.GetCompanyNoticeReply{
2123
Data: data,
2224
}, nil
2325
}
2426

25-
func (d *DMSService) UpdateCompanyNotice(ctx context.Context, req *dmsV1.UpdateCompanyNoticeReq) (err error) {
26-
return d.CompanyNoticeUsecase.UpdateCompanyNotice(ctx, req.UpdateCompanyNotice.NoticeStr)
27+
func (d *DMSService) UpdateCompanyNotice(ctx context.Context, currentUserUID string, req *dmsV1.UpdateCompanyNoticeReq) (err error) {
28+
return d.CompanyNoticeUsecase.UpdateCompanyNotice(ctx, currentUserUID, req.UpdateCompanyNotice.NoticeStr, req.UpdateCompanyNotice.StartTime, req.UpdateCompanyNotice.EndTime)
2729
}

0 commit comments

Comments
 (0)