Skip to content
Open
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
28 changes: 28 additions & 0 deletions common/infrastructure/mongodb/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,34 @@ func (impl *daoImpl) GetDocs(filter, project bson.M, result interface{}) error {
})
}

func (impl *daoImpl) GetDocsPage(filter, project bson.M, intPage, intPageSize int, result interface{}) error {
return impl.withContext(func(ctx context.Context) error {
// 构建查询选项
opts := options.Find()
if len(project) > 0 {
opts.SetProjection(project)
}
opts.SetSkip(int64((intPage - 1) * intPageSize))
opts.SetLimit(int64(intPageSize))
// 执行查询
cursor, err := impl.col.Find(ctx, filter, opts)
if err != nil {
return err
}
return cursor.All(ctx, result)
})
}
Comment on lines +338 to +354

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other layers in the call stack, the parameter names should be page and pageSize instead of intPage and intPageSize. Remember to update their usage within the function body as well.

Suggested change
func (impl *daoImpl) GetDocsPage(filter, project bson.M, intPage, intPageSize int, result interface{}) error {
return impl.withContext(func(ctx context.Context) error {
// 构建查询选项
opts := options.Find()
if len(project) > 0 {
opts.SetProjection(project)
}
opts.SetSkip(int64((intPage - 1) * intPageSize))
opts.SetLimit(int64(intPageSize))
// 执行查询
cursor, err := impl.col.Find(ctx, filter, opts)
if err != nil {
return err
}
return cursor.All(ctx, result)
})
}
func (impl *daoImpl) GetDocsPage(filter, project bson.M, page, pageSize int, result interface{}) error {
return impl.withContext(func(ctx context.Context) error {
// 构建查询选项
opts := options.Find()
if len(project) > 0 {
opts.SetProjection(project)
}
opts.SetSkip(int64((page - 1) * pageSize))
opts.SetLimit(int64(pageSize))
// 执行查询
cursor, err := impl.col.Find(ctx, filter, opts)
if err != nil {
return err
}
return cursor.All(ctx, result)
})
}


func (impl *daoImpl) GetDocsCount(filter bson.M) (int64, error) {
var count int64
err := impl.withContext(func(ctx context.Context) error {
var err error
count, err = impl.col.CountDocuments(ctx, filter)
return err
})
Comment on lines +358 to +362

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The err variable is shadowed inside the closure. While this is not a bug, it makes the code harder to read and is generally discouraged in Go. You can refactor this to be more idiomatic and avoid shadowing by using a named return for the closure.

	err := impl.withContext(func(ctx context.Context) (err error) {
		count, err = impl.col.CountDocuments(ctx, filter)
		return
	})

return count, err
}

func (impl *daoImpl) GetDocAndDelete(filter, project bson.M, result interface{}) error {
return impl.withContext(func(ctx context.Context) error {
var sr *mongo.SingleResult
Expand Down
41 changes: 41 additions & 0 deletions controllers/corp_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,47 @@ func (ctl *CorporationSigningController) GetAll() {
}
}

// @Title GetPage
// @Description get all the corporations by page
// @Tags CorpSigning
// @Accept json
// @Param link_id path string true "link id"
// @Success 200 {object} models.CorporationSigningSummary
Comment on lines +207 to +208

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Swagger documentation for this endpoint has a couple of issues:

  1. It's missing definitions for the page and page_size query parameters.
  2. The success response object is incorrect. It should be models.CorporationSigningPageSummary which includes total count and data array.
Suggested change
// @Param link_id path string true "link id"
// @Success 200 {object} models.CorporationSigningSummary
// @Param link_id path string true "link id"
// @Param page query int false "page number"
// @Param page_size query int false "page size"
// @Success 200 {object} models.CorporationSigningPageSummary

// @Failure 400 missing_url_path_parameter: missing url path parameter
// @Failure 401 missing_token: token is missing
// @Failure 402 unknown_token: token is unknown
// @Failure 403 expired_token: token is expired
// @Failure 404 unauthorized_token: the permission of token is unmatched
// @Failure 405 unknown_link: unkown link id
// @Failure 406 not_yours_org: the link doesn't belong to your community
// @Failure 500 system_error: system error
// @router /page/:link_id [get]
func (ctl *CorporationSigningController) GetPage() {
action := "community manager lists page corp signings"
linkID := ctl.GetString(":link_id")
page, pageErr := ctl.GetInt("page", 1)
if pageErr != nil {
ctl.sendModelErrorAsResp(models.NewModelError(models.ErrSystemError, pageErr), action)
return
}
pageSize, sizeErr := ctl.GetInt("page_size", 10)
if sizeErr != nil {
ctl.sendModelErrorAsResp(models.NewModelError(models.ErrSystemError, sizeErr), action)
return
}
adminAdded, sizeErr := ctl.GetBool("admin_added", false)
pl, fr := ctl.tokenPayloadBasedOnCorpManager()
if fr != nil {
ctl.sendFailedResultAsResp(fr, action)
return
}
if r, merr := models.ListPageCorpSigning(pl.UserId, linkID, page, pageSize, adminAdded); merr != nil {
ctl.sendModelErrorAsResp(merr, action)
} else {
ctl.sendSuccessResp(action, r)
}
}

// @Title ListDeleted
// @Description get all the corporations which have been deleted
// @Tags CorpSigning
Expand Down
4 changes: 4 additions & 0 deletions models/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func ListCorpSigning(userId, linkID string) ([]CorporationSigningSummary, IModel
return corpSigningAdapterInstance.List(userId, linkID)
}

func ListPageCorpSigning(userId, linkID string, page, pageSize int, adminAdded bool) (CorporationSigningPageSummary, IModelError) {
return corpSigningAdapterInstance.ListPage(userId, linkID, page, pageSize, adminAdded)
}

func GetCorpSigning(userId, csId string, email dp.EmailAddr) (string, CorporationSigning, IModelError) {
return corpSigningAdapterInstance.Get(userId, csId, email)
}
Expand Down
5 changes: 5 additions & 0 deletions models/corp_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func (opt *CorporationSigningCreateOption) ToCorporationSigning() CorporationSig
}
}

type CorporationSigningPageSummary struct {
Total int64 `json:"total"`
Data []CorporationSigningSummary `json:"page_data"`
}

type CorporationSigningSummary struct {
CorporationSigningBasicInfo

Expand Down
1 change: 1 addition & 0 deletions models/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type corpSigningAdapter interface {
Remove(string, string) IModelError
Get(userId, csId string, email dp.EmailAddr) (string, CorporationSigning, IModelError)
List(userId, linkId string) ([]CorporationSigningSummary, IModelError)
ListPage(userId, linkId string, page, pageSize int, adminAdded bool) (CorporationSigningPageSummary, IModelError)
FindCorpSummary(linkId string, email string) (interface{}, IModelError)
FindDiffCLAFile(signingId string) (string, IModelError)
Agree(signingId string) IModelError
Expand Down
Loading