Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion api/dms/service/v1/company_notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@ package v1

import (
base "github.com/actiontech/dms/pkg/dms-common/api/base/v1"
"time"
)

// swagger:parameters GetCompanyNotice
type GetCompanyNoticeReq struct {
// 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.
// in: query
IncludeLatestOutsidePeriod bool `query:"include_latest_outside_period" json:"include_latest_outside_period"`
}

// A companynotice
type CompanyNotice struct {
// companynotice info
NoticeStr string `json:"notice_str"`
// companynotice creator name
CreateUserName string `json:"create_user_name"`
// current user has been read
ReadByCurrentUser bool `json:"read_by_current_user"`
// notice show start time
StartTime *time.Time `json:"start_time,omitempty"`
// notice expire time
ExpireTime *time.Time `json:"expire_time,omitempty"`
}

// swagger:model GetCompanyNoticeReply
Expand All @@ -28,5 +42,9 @@ type UpdateCompanyNoticeReq struct {
// A companynotice
type UpdateCompanyNotice struct {
// companynotice info
NoticeStr *string `json:"notice_str" valid:"omitempty"`
NoticeStr *string `json:"notice_str" validate:"required"`
// notice show start time
StartTime *time.Time `json:"start_time" validate:"required"`
// notice show end time
EndTime *time.Time `json:"end_time" validate:"required"`
}
38 changes: 38 additions & 0 deletions api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
"CompanyNotice"
],
"operationId": "GetCompanyNotice",
"parameters": [
{
"type": "boolean",
"x-go-name": "IncludeLatestOutsidePeriod",
"description": "when true, return the latest notice regardless of display window (for admin edit)",
"name": "include_latest_outside_period",
"in": "query"
}
],
"responses": {
"200": {
"description": "GetCompanyNoticeReply",
Expand Down Expand Up @@ -8069,6 +8078,17 @@
"description": "A companynotice",
"type": "object",
"properties": {
"create_user_name": {
"description": "companynotice creator name",
"type": "string",
"x-go-name": "CreateUserName"
},
"expire_time": {
"description": "notice expire time",
"type": "string",
"format": "date-time",
"x-go-name": "ExpireTime"
},
"notice_str": {
"description": "companynotice info",
"type": "string",
Expand All @@ -8078,6 +8098,12 @@
"description": "current user has been read",
"type": "boolean",
"x-go-name": "ReadByCurrentUser"
},
"start_time": {
"description": "notice show start time",
"type": "string",
"format": "date-time",
"x-go-name": "StartTime"
}
},
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
Expand Down Expand Up @@ -14300,10 +14326,22 @@
"description": "A companynotice",
"type": "object",
"properties": {
"end_time": {
"description": "notice show end time",
"type": "string",
"format": "date-time",
"x-go-name": "EndTime"
},
"notice_str": {
"description": "companynotice info",
"type": "string",
"x-go-name": "NoticeStr"
},
"start_time": {
"description": "notice show start time",
"type": "string",
"format": "date-time",
"x-go-name": "StartTime"
}
},
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
Expand Down
30 changes: 30 additions & 0 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,15 @@ definitions:
CompanyNotice:
description: A companynotice
properties:
create_user_name:
description: companynotice creator name
type: string
x-go-name: CreateUserName
expire_time:
description: notice expire time
format: date-time
type: string
x-go-name: ExpireTime
notice_str:
description: companynotice info
type: string
Expand All @@ -909,6 +918,11 @@ definitions:
description: current user has been read
type: boolean
x-go-name: ReadByCurrentUser
start_time:
description: notice show start time
format: date-time
type: string
x-go-name: StartTime
type: object
x-go-package: github.com/actiontech/dms/api/dms/service/v1
ComponentNameWithVersion:
Expand Down Expand Up @@ -5924,10 +5938,20 @@ definitions:
UpdateCompanyNotice:
description: A companynotice
properties:
end_time:
description: notice show end time
format: date-time
type: string
x-go-name: EndTime
notice_str:
description: companynotice info
type: string
x-go-name: NoticeStr
start_time:
description: notice show start time
format: date-time
type: string
x-go-name: StartTime
type: object
x-go-package: github.com/actiontech/dms/api/dms/service/v1
UpdateCompanyNoticeReq:
Expand Down Expand Up @@ -6937,6 +6961,12 @@ paths:
get:
description: get company notice info
operationId: GetCompanyNotice
parameters:
- description: when true, return the latest notice regardless of display window (for admin edit)
in: query
name: include_latest_outside_period
type: boolean
x-go-name: IncludeLatestOutsidePeriod
responses:
"200":
description: GetCompanyNoticeReply
Expand Down
34 changes: 27 additions & 7 deletions internal/apiserver/service/dms_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3470,20 +3470,36 @@ func (ctl *DMSController) WebHookSendMessage(c echo.Context) error {
return NewOkResp(c)
}

// swagger:route GET /v1/dms/company_notice CompanyNotice GetCompanyNotice
// swagger:operation GET /v1/dms/company_notice CompanyNotice GetCompanyNotice
//
// get company notice info
//
// responses:
// 200: body:GetCompanyNoticeReply
// default: body:GenericResp
// ---
// parameters:
// - name: include_latest_outside_period
// description: when true, return the latest notice regardless of display window (for admin edit)
// in: query
// required: false
// type: boolean
// responses:
// '200':
// description: GetCompanyNoticeReply
// schema:
// "$ref": "#/definitions/GetCompanyNoticeReply"
// default:
// description: GenericResp
// schema:
// "$ref": "#/definitions/GenericResp"
func (ctl *DMSController) GetCompanyNotice(c echo.Context) error {
// get current user id
var req aV1.GetCompanyNoticeReq
if err := bindAndValidateReq(c, &req); err != nil {
return NewErrResp(c, err, apiError.BadRequestErr)
}
currentUserUid, err := jwt.GetUserUidStrFromContext(c)
if err != nil {
return NewErrResp(c, err, apiError.DMSServiceErr)
}
reply, err := ctl.DMS.GetCompanyNotice(c.Request().Context(), currentUserUid)
reply, err := ctl.DMS.GetCompanyNotice(c.Request().Context(), currentUserUid, req.IncludeLatestOutsidePeriod)
if err != nil {
return NewErrResp(c, err, apiError.APIServerErr)
}
Expand Down Expand Up @@ -3517,7 +3533,11 @@ func (ctl *DMSController) UpdateCompanyNotice(c echo.Context) error {
if nil != err {
return NewErrResp(c, err, apiError.BadRequestErr)
}
err = ctl.DMS.UpdateCompanyNotice(c.Request().Context(), req)
currentUserUid, err := jwt.GetUserUidStrFromContext(c)
if err != nil {
return NewErrResp(c, err, apiError.DMSServiceErr)
}
err = ctl.DMS.UpdateCompanyNotice(c.Request().Context(), currentUserUid, req)
if err != nil {
return NewErrResp(c, err, apiError.APIServerErr)
}
Expand Down
10 changes: 7 additions & 3 deletions internal/dms/biz/company_notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package biz

import (
"context"
"time"

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

Expand All @@ -11,9 +12,12 @@ import (
type CompanyNotice struct {
Base

UID string
NoticeStr string
ReadUserIds []string
UID string
CreateUserUID string
NoticeStr string
ReadUserIds []string
StartTime *time.Time
EndTime *time.Time
}

func initCompanyNotice() (*CompanyNotice, error) {
Expand Down
7 changes: 4 additions & 3 deletions internal/dms/biz/company_notice_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ package biz
import (
"context"
"errors"
"time"
)

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

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

return errNotSupportCompanyNotice
}

func (d *CompanyNoticeUsecase) GetCompanyNotice(ctx context.Context, userId string) (notice *CompanyNotice, exist bool, err error) {
return nil, false, errNotSupportCompanyNotice
func (d *CompanyNoticeUsecase) GetCompanyNotice(ctx context.Context, userId string, includeLatestOutsidePeriod bool) (notice *CompanyNotice, err error) {
return nil, errNotSupportCompanyNotice
}
12 changes: 7 additions & 5 deletions internal/dms/service/company_notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import (
dmsV1 "github.com/actiontech/dms/api/dms/service/v1"
)

func (d *DMSService) GetCompanyNotice(ctx context.Context, currentUserUid string) (reply *dmsV1.GetCompanyNoticeReply, err error) {
companyNotice, read, err := d.CompanyNoticeUsecase.GetCompanyNotice(ctx, currentUserUid)
func (d *DMSService) GetCompanyNotice(ctx context.Context, currentUserUid string, includeLatestOutsidePeriod bool) (reply *dmsV1.GetCompanyNoticeReply, err error) {
companyNotice, err := d.CompanyNoticeUsecase.GetCompanyNotice(ctx, currentUserUid, includeLatestOutsidePeriod)
if err != nil {
return nil, err
}
data := dmsV1.CompanyNotice{
ReadByCurrentUser: read,
ReadByCurrentUser: false,
}
if companyNotice != nil {
data.NoticeStr = companyNotice.NoticeStr
data.StartTime = companyNotice.StartTime
data.ExpireTime = companyNotice.EndTime
}
return &dmsV1.GetCompanyNoticeReply{
Data: data,
}, nil
}

func (d *DMSService) UpdateCompanyNotice(ctx context.Context, req *dmsV1.UpdateCompanyNoticeReq) (err error) {
return d.CompanyNoticeUsecase.UpdateCompanyNotice(ctx, req.UpdateCompanyNotice.NoticeStr)
func (d *DMSService) UpdateCompanyNotice(ctx context.Context, currentUserUID string, req *dmsV1.UpdateCompanyNoticeReq) (err error) {
return d.CompanyNoticeUsecase.UpdateCompanyNotice(ctx, currentUserUID, req.UpdateCompanyNotice.NoticeStr, req.UpdateCompanyNotice.StartTime, req.UpdateCompanyNotice.EndTime)
}