Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
JingYiJun committed Oct 31, 2023
2 parents 505c3c6 + 79eb79c commit ecb6cbb
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 71 deletions.
34 changes: 34 additions & 0 deletions apis/hole/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,40 @@ func ListHolesByMe(c *fiber.Ctx) error {
return Serialize(c, &holes)
}

// ListGoodHoles
//
// @Summary List good holes
// @Tags Hole
// @Produce json
// @Router /holes/_good [get]
// @Param object query QueryTime false "query"
// @Success 200 {array} Hole
func ListGoodHoles(c *fiber.Ctx) error {
var query QueryTime
err := common.ValidateQuery(c, &query)
if err != nil {
return err
}
_, err = common.GetUserID(c)
if err != nil {
return err
}

// get holes
var holes Holes
querySet, err := holes.MakeQuerySet(query.Offset, query.Size, query.Order, c)
if err != nil {
return err
}
querySet = querySet.Where("good = 1")
err = querySet.Find(&holes).Error
if err != nil {
return err
}

return Serialize(c, &holes)
}

// ListHolesOld
//
// @Summary Old API for Listing Holes
Expand Down
3 changes: 2 additions & 1 deletion apis/hole/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ func RegisterRoutes(app fiber.Router) {
app.Get("/divisions/:id/holes", ListHolesByDivision)
app.Get("/tags/:name/holes", ListHolesByTag)
app.Get("/users/me/holes", ListHolesByMe)
app.Get("/holes/:id", GetHole)
app.Get("/holes/:id<int>", GetHole)
app.Get("/holes", ListHolesOld)
app.Get("/holes/_good", ListGoodHoles)
app.Post("/divisions/:id/holes", utils.MiddlewareHasAnsweredQuestions, CreateHole)
app.Post("/holes", utils.MiddlewareHasAnsweredQuestions, CreateHoleOld)
app.Patch("/holes/:id", PatchHole)
Expand Down
1 change: 1 addition & 0 deletions apis/tag/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func CreateTag(c *fiber.Ctx) error {
}

// bind and create tag
body.Name = strings.TrimSpace(body.Name)
tag.Name = body.Name
result := DB.Where("name = ?", body.Name).FirstOrCreate(&tag)
if result.RowsAffected == 0 {
Expand Down
70 changes: 46 additions & 24 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,48 @@ const docTemplate = `{
}
}
},
"/holes/_good": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Hole"
],
"summary": "List good holes",
"parameters": [
{
"type": "string",
"description": "updated time \u003c offset (default is now)",
"name": "offset",
"in": "query"
},
{
"type": "string",
"name": "order",
"in": "query"
},
{
"maximum": 10,
"type": "integer",
"default": 10,
"name": "size",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Hole"
}
}
}
}
}
},
"/holes/{hole_id}/floors": {
"get": {
"produces": [
Expand Down Expand Up @@ -2740,6 +2782,9 @@ const docTemplate = `{
}
}
},
"good": {
"type": "boolean"
},
"hidden": {
"description": "是否隐藏,隐藏的洞用户不可见,管理员可见",
"type": "boolean"
Expand Down Expand Up @@ -2871,7 +2916,7 @@ const docTemplate = `{
"type": "integer"
},
"duration": {
"$ref": "#/definitions/time.Duration"
"type": "integer"
},
"end_time": {
"description": "end_time of this punishment",
Expand Down Expand Up @@ -3178,29 +3223,6 @@ const docTemplate = `{
"type": "integer"
}
}
},
"time.Duration": {
"type": "integer",
"enum": [
-9223372036854775808,
9223372036854775807,
1,
1000,
1000000,
1000000000,
60000000000,
3600000000000
],
"x-enum-varnames": [
"minDuration",
"maxDuration",
"Nanosecond",
"Microsecond",
"Millisecond",
"Second",
"Minute",
"Hour"
]
}
}
}`
Expand Down
70 changes: 46 additions & 24 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,48 @@
}
}
},
"/holes/_good": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Hole"
],
"summary": "List good holes",
"parameters": [
{
"type": "string",
"description": "updated time \u003c offset (default is now)",
"name": "offset",
"in": "query"
},
{
"type": "string",
"name": "order",
"in": "query"
},
{
"maximum": 10,
"type": "integer",
"default": 10,
"name": "size",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Hole"
}
}
}
}
}
},
"/holes/{hole_id}/floors": {
"get": {
"produces": [
Expand Down Expand Up @@ -2733,6 +2775,9 @@
}
}
},
"good": {
"type": "boolean"
},
"hidden": {
"description": "是否隐藏,隐藏的洞用户不可见,管理员可见",
"type": "boolean"
Expand Down Expand Up @@ -2864,7 +2909,7 @@
"type": "integer"
},
"duration": {
"$ref": "#/definitions/time.Duration"
"type": "integer"
},
"end_time": {
"description": "end_time of this punishment",
Expand Down Expand Up @@ -3171,29 +3216,6 @@
"type": "integer"
}
}
},
"time.Duration": {
"type": "integer",
"enum": [
-9223372036854775808,
9223372036854775807,
1,
1000,
1000000,
1000000000,
60000000000,
3600000000000
],
"x-enum-varnames": [
"minDuration",
"maxDuration",
"Nanosecond",
"Microsecond",
"Millisecond",
"Second",
"Minute",
"Hour"
]
}
}
}
51 changes: 30 additions & 21 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ definitions:
$ref: '#/definitions/models.Floor'
type: array
type: object
good:
type: boolean
hidden:
description: 是否隐藏,隐藏的洞用户不可见,管理员可见
type: boolean
Expand Down Expand Up @@ -459,7 +461,7 @@ definitions:
division_id:
type: integer
duration:
$ref: '#/definitions/time.Duration'
type: integer
end_time:
description: end_time of this punishment
type: string
Expand Down Expand Up @@ -676,26 +678,6 @@ definitions:
description: Admin only
type: integer
type: object
time.Duration:
enum:
- -9223372036854775808
- 9223372036854775807
- 1
- 1000
- 1000000
- 1000000000
- 60000000000
- 3600000000000
type: integer
x-enum-varnames:
- minDuration
- maxDuration
- Nanosecond
- Microsecond
- Millisecond
- Second
- Minute
- Hour
info:
contact:
email: dev@fduhole.com
Expand Down Expand Up @@ -1265,6 +1247,33 @@ paths:
summary: Old API for Creating A Hole
tags:
- Hole
/holes/_good:
get:
parameters:
- description: updated time < offset (default is now)
in: query
name: offset
type: string
- in: query
name: order
type: string
- default: 10
in: query
maximum: 10
name: size
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/models.Hole'
type: array
summary: List good holes
tags:
- Hole
/holes/{hole_id}/floors:
get:
parameters:
Expand Down
2 changes: 2 additions & 0 deletions models/hole.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Hole struct {
// 锁定帖子,如果锁定则非管理员无法发帖,也无法修改已有发帖
Locked bool `json:"locked" gorm:"not null;default:false"`

Good bool `json:"good" gorm:"not null;default:false"`

/// association info, should add foreign key

// 所属 division 的 id
Expand Down
2 changes: 1 addition & 1 deletion models/punishment.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Punishment struct {
// end_time of this punishment
EndTime time.Time `json:"end_time" gorm:"not null"`

Duration *time.Duration `json:"duration"`
Duration *time.Duration `json:"duration" swaggertype:"integer"`

// user punished
UserID int `json:"user_id" gorm:"not null;index"`
Expand Down
1 change: 1 addition & 0 deletions models/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func FindOrCreateTags(tx *gorm.DB, user *User, names []string) (Tags, error) {

newTags := make(Tags, 0)
for _, name := range names {
name = strings.TrimSpace(name)
if !slices.ContainsFunc(existTagName, func(s string) bool {
return strings.EqualFold(s, name)
}) {
Expand Down

0 comments on commit ecb6cbb

Please sign in to comment.