Skip to content
Closed
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
18 changes: 17 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,26 @@ 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"`
// 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 +40,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"`
}
37 changes: 35 additions & 2 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 @@ -8017,6 +8026,12 @@
"description": "A companynotice",
"type": "object",
"properties": {
"expire_time": {
"description": "notice expire time",
"type": "string",
"format": "date-time",
"x-go-name": "ExpireTime"
},
"notice_str": {
"description": "companynotice info",
"type": "string",
Expand All @@ -8026,6 +8041,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 @@ -9257,7 +9278,7 @@
"x-go-name": "Users"
}
},
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
},
"GetMemberGroupReply": {
"type": "object",
Expand Down Expand Up @@ -14222,7 +14243,7 @@
"x-go-name": "Uid"
}
},
"x-go-package": "github.com/actiontech/dms/api/dms/service/v1"
"x-go-package": "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
},
"UpdateBusinessTagReq": {
"type": "object",
Expand All @@ -14237,10 +14258,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: 28 additions & 2 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,11 @@ definitions:
CompanyNotice:
description: A companynotice
properties:
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 +914,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 @@ -1860,7 +1870,7 @@ definitions:
type: array
x-go-name: Users
type: object
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
x-go-package: github.com/actiontech/dms/api/dms/service/v1
GetMemberGroupReply:
properties:
code:
Expand Down Expand Up @@ -5906,7 +5916,7 @@ definitions:
type: string
x-go-name: Uid
type: object
x-go-package: github.com/actiontech/dms/api/dms/service/v1
x-go-package: github.com/actiontech/dms/pkg/dms-common/api/dms/v1
UpdateBusinessTagReq:
properties:
business_tag:
Expand All @@ -5916,10 +5926,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 @@ -6929,6 +6949,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
28 changes: 22 additions & 6 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
3 changes: 3 additions & 0 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 @@ -14,6 +15,8 @@ type CompanyNotice struct {
UID 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, 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
}
10 changes: 6 additions & 4 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)
return d.CompanyNoticeUsecase.UpdateCompanyNotice(ctx, req.UpdateCompanyNotice.NoticeStr, req.UpdateCompanyNotice.StartTime, req.UpdateCompanyNotice.EndTime)
}
4 changes: 4 additions & 0 deletions internal/dms/storage/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,8 @@ func convertBizCompanyNotice(b *biz.CompanyNotice) (*model.CompanyNotice, error)
},
NoticeStr: b.NoticeStr,
ReadUserIds: b.ReadUserIds,
StartTime: b.StartTime,
EndTime: b.EndTime,
}, nil
}

Expand All @@ -999,6 +1001,8 @@ func convertModelCompanyNotice(m *model.CompanyNotice) (*biz.CompanyNotice, erro
UID: m.UID,
NoticeStr: m.NoticeStr,
ReadUserIds: m.ReadUserIds,
StartTime: m.StartTime,
EndTime: m.EndTime,
}

return p, nil
Expand Down
2 changes: 2 additions & 0 deletions internal/dms/storage/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ type CompanyNotice struct {
Model
NoticeStr string `gorm:"type:mediumtext;comment:'企业公告'" json:"notice_str"`
ReadUserIds ReadUsers `gorm:"type:longtext" json:"read_user_ids"`
StartTime *time.Time `json:"start_time" gorm:"column:start_time;comment:'公告开始时间'"`
EndTime *time.Time `json:"end_time" gorm:"column:end_time;comment:'公告结束时间'"`
}

type ReadUsers []string
Expand Down