Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

失物招领获取记录修改 #61

Merged
merged 1 commit into from
Aug 10, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
)

type GetRecordsData struct {
LostOrFound int `form:"lost_or_found"`
PageNum int `form:"page_num"`
PageSize int `form:"page_size"`
LostOrFound string `form:"lost_or_found"`
PageNum int `form:"page_num"`
PageSize int `form:"page_size"`
}

func GetRecords(c *gin.Context) {
Expand All @@ -39,22 +39,32 @@ func GetRecords(c *gin.Context) {
return
}

var _type int
switch data.LostOrFound {
case "":
_type = 2
case "失物":
_type = 1
case "寻物":
_type = 0
}

var lostAndFoundRecords []models.LostAndFoundRecord
if data.LostOrFound == 2 {
if _type == 2 {
lostAndFoundRecords, err = lostAndFoundRecordServices.GetAllLostAndFoundRecord(campus, kind, data.PageNum, data.PageSize)
} else {
lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecord(campus, kind, data.LostOrFound, data.PageNum, data.PageSize)
lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecord(campus, kind, _type, data.PageNum, data.PageSize)
}
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}

var totalPageNum *int64
if data.LostOrFound == 2 {
if _type == 2 {
totalPageNum, err = lostAndFoundRecordServices.GetAllLostAndFoundTotalPageNum(campus, kind)
} else {
totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNum(campus, kind, data.LostOrFound)
totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNum(campus, kind, _type)
}
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
Expand All @@ -75,27 +85,37 @@ func GetRecordsByAdmin(c *gin.Context) {
return
}

var _type int
switch data.LostOrFound {
case "":
_type = 2
case "失物":
_type = 1
case "寻物":
_type = 0
}

var lostAndFoundRecords []models.LostAndFoundRecord
var totalPageNum *int64
publisher := getPublisher(c)
if *publisher == "Admin" {
lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecordBySuperAdmin(data.LostOrFound, data.PageNum, data.PageSize)
lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecordBySuperAdmin(_type, data.PageNum, data.PageSize)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}
totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNumBySuperAdmin(data.LostOrFound)
totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNumBySuperAdmin(_type)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}
} else {
lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecordByAdmin(*publisher, data.LostOrFound, data.PageNum, data.PageSize)
lostAndFoundRecords, err = lostAndFoundRecordServices.GetRecordByAdmin(*publisher, _type, data.PageNum, data.PageSize)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
}
totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNumByAdmin(*publisher, data.LostOrFound)
totalPageNum, err = lostAndFoundRecordServices.GetTotalPageNumByAdmin(*publisher, _type)
if err != nil {
_ = c.AbortWithError(200, apiException.ServerError)
return
Expand Down