Skip to content

feat(homepage): resolves #174 #189

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
42 changes: 42 additions & 0 deletions apis/hole/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,48 @@ import (
. "treehole_next/utils"
)

// ListHomePage
//
// @Summary List Holes In Home Page
// @Tags Hole
// @Produce json
// @Router /holes/_homepage [get]
// @Param object query ShowHomePageModel false "query"
// @Success 200 {array} Hole
// @Failure 404 {object} MessageModel
// @Failure 500 {object} MessageModel
func ListHomePage(c *fiber.Ctx) (err error) {
var query ShowHomePageModel
err = common.ValidateQuery(c, &query)
if err != nil {
return err
}

divisionIDs, err := HomepageDivisionIDs(DB, query.ExcludeDivisionIDs)
if err != nil {
return err
}

if len(divisionIDs) == 0 {
return Serialize(c, &Holes{})
}

// get holes
var holes Holes
querySet, err := holes.MakeQuerySet(query.Offset, query.Size, query.Order, c)
if err != nil {
return err
}

querySet = querySet.Where("hole.division_id in (?)", divisionIDs)
err = querySet.Find(&holes).Error
if err != nil {
return err
}

return Serialize(c, &holes)
}

// ListHolesByDivision
//
// @Summary List Holes In A Division
Expand Down
3 changes: 3 additions & 0 deletions apis/hole/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

func RegisterRoutes(app fiber.Router) {
// // order: match first route
// app.Get("/divisions/1/holes", ListHomePage)
app.Get("/holes/_homepage", ListHomePage)
app.Get("/divisions/:id<int>/holes", ListHolesByDivision)
app.Get("/tags/:name/holes", ListHolesByTag)
app.Get("/users/me/holes", ListHolesByMe)
Expand Down
10 changes: 10 additions & 0 deletions apis/hole/schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import (
"treehole_next/models"
)

type ShowHomePageModel struct {
// default is all
ExcludeDivisionIDs *[]int `json:"exclude_division_ids" query:"exclude_division_ids" validate:"omitempty"`

Size int `json:"size" query:"size" default:"10" validate:"max=10"`
// updated time < offset (default is now)
Offset common.CustomTime `json:"offset" query:"offset" swaggertype:"string"`
Order string `json:"order" query:"order"`
}

type QueryTime struct {
Size int `json:"size" query:"size" default:"10" validate:"max=10"`
// updated time < offset (default is now)
Expand Down
85 changes: 85 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,70 @@ const docTemplate = `{
}
}
},
"/holes/_homepage": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Hole"
],
"summary": "List Holes In Home Page",
"parameters": [
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"description": "default is all",
"name": "exclude_division_ids",
"in": "query"
},
{
"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"
}
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/models.MessageModel"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/models.MessageModel"
}
}
}
}
},
"/holes/{hole_id}/floors": {
"get": {
"produces": [
Expand Down Expand Up @@ -3383,6 +3447,18 @@ const docTemplate = `{
}
}
},
"gorm.DeletedAt": {
"type": "object",
"properties": {
"time": {
"type": "string"
},
"valid": {
"description": "Valid is true if Time is not NULL",
"type": "boolean"
}
}
},
"hole.CreateModel": {
"type": "object",
"required": [
Expand Down Expand Up @@ -3526,6 +3602,9 @@ const docTemplate = `{
"$ref": "#/definitions/models.Hole"
}
},
"show_in_home_page": {
"type": "boolean"
},
"time_created": {
"type": "string"
},
Expand Down Expand Up @@ -3773,6 +3852,9 @@ const docTemplate = `{
"time_created": {
"type": "string"
},
"time_deleted": {
"$ref": "#/definitions/gorm.DeletedAt"
},
"time_updated": {
"type": "string"
},
Expand Down Expand Up @@ -3912,6 +3994,9 @@ const docTemplate = `{
"description": "start from end_time of previous punishment (punishment accumulation of different floors)\nif no previous punishment or previous punishment end time less than time.Now() (synced), set start time time.Now()",
"type": "string"
},
"updated_at": {
"type": "string"
},
"user_id": {
"description": "user punished",
"type": "integer"
Expand Down
85 changes: 85 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,70 @@
}
}
},
"/holes/_homepage": {
"get": {
"produces": [
"application/json"
],
"tags": [
"Hole"
],
"summary": "List Holes In Home Page",
"parameters": [
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"description": "default is all",
"name": "exclude_division_ids",
"in": "query"
},
{
"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"
}
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/models.MessageModel"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/models.MessageModel"
}
}
}
}
},
"/holes/{hole_id}/floors": {
"get": {
"produces": [
Expand Down Expand Up @@ -3376,6 +3440,18 @@
}
}
},
"gorm.DeletedAt": {
"type": "object",
"properties": {
"time": {
"type": "string"
},
"valid": {
"description": "Valid is true if Time is not NULL",
"type": "boolean"
}
}
},
"hole.CreateModel": {
"type": "object",
"required": [
Expand Down Expand Up @@ -3519,6 +3595,9 @@
"$ref": "#/definitions/models.Hole"
}
},
"show_in_home_page": {
"type": "boolean"
},
"time_created": {
"type": "string"
},
Expand Down Expand Up @@ -3766,6 +3845,9 @@
"time_created": {
"type": "string"
},
"time_deleted": {
"$ref": "#/definitions/gorm.DeletedAt"
},
"time_updated": {
"type": "string"
},
Expand Down Expand Up @@ -3905,6 +3987,9 @@
"description": "start from end_time of previous punishment (punishment accumulation of different floors)\nif no previous punishment or previous punishment end time less than time.Now() (synced), set start time time.Now()",
"type": "string"
},
"updated_at": {
"type": "string"
},
"user_id": {
"description": "user punished",
"type": "integer"
Expand Down
Loading