-
Notifications
You must be signed in to change notification settings - Fork 16
feat: V2 API for get hole #184
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,7 @@ func RegisterRoutes(app fiber.Router) { | |
| app.Put("/holes/:id<int>", ModifyHole) | ||
| app.Delete("/holes/:id<int>", HideHole) | ||
| app.Delete("/holes/:id<int>/_force", DeleteHole) | ||
|
|
||
| // V2 | ||
| app.Get("/v2/holes/:id<int>", GetHole) | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,9 +17,11 @@ import ( | |||||
| "treehole_next/utils" | ||||||
| ) | ||||||
|
|
||||||
| type Hole struct { | ||||||
| type Hole = HoleV1 | ||||||
|
|
||||||
| type BaseHole struct { | ||||||
| /// saved fields | ||||||
| ID int `json:"id" gorm:"primaryKey"` | ||||||
| ID int `json:"id" gorm:"primaryKey;"` | ||||||
| CreatedAt time.Time `json:"time_created" gorm:"not null;index:idx_hole_div_cre,priority:2,sort:desc"` | ||||||
| UpdatedAt time.Time `json:"time_updated" gorm:"not null;index:idx_hole_div_upd,priority:2,sort:desc"` | ||||||
| DeletedAt gorm.DeletedAt `json:"time_deleted,omitempty" gorm:"index"` | ||||||
|
|
@@ -54,7 +56,7 @@ type Hole struct { | |||||
| Tags Tags `json:"tags" gorm:"many2many:hole_tags;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` | ||||||
|
|
||||||
| // 楼层列表 | ||||||
| Floors Floors `json:"-" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` | ||||||
| Floors Floors `json:"-" gorm:"foreignKey:HoleID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` | ||||||
|
|
||||||
| // 匿名映射表 | ||||||
| Mapping Users `json:"-" gorm:"many2many:anonyname_mapping;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"` | ||||||
|
|
@@ -66,20 +68,26 @@ type Hole struct { | |||||
|
|
||||||
| // 兼容旧版 id | ||||||
| HoleID int `json:"hole_id" gorm:"-:all"` | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| type HoleV1 struct { | ||||||
| BaseHole | ||||||
|
|
||||||
| // 返回给前端的楼层列表,包括首楼、尾楼和预加载的前 n 个楼层 | ||||||
| HoleFloor struct { | ||||||
| FirstFloor *Floor `json:"first_floor"` // 首楼 | ||||||
| LastFloor *Floor `json:"last_floor"` // 尾楼 | ||||||
| Floors Floors `json:"prefetch"` // 预加载的楼层 | ||||||
| } `json:"floors" gorm:"-:all"` | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| func (hole *Hole) GetID() int { | ||||||
| func (hole *BaseHole) GetID() int { | ||||||
| return hole.ID | ||||||
| } | ||||||
|
|
||||||
| func (hole *Hole) CacheName() string { | ||||||
| func (hole *BaseHole) CacheName() string { | ||||||
| return fmt.Sprintf("hole_%d", hole.ID) | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -97,7 +105,7 @@ func IsHolesExist(tx *gorm.DB, holeID []int) bool { | |||||
|
|
||||||
| const HoleCacheExpire = time.Minute * 10 | ||||||
|
|
||||||
| func loadTags(holes Holes) (err error) { | ||||||
| func (holes Holes)loadTags() error { | ||||||
|
||||||
| func (holes Holes)loadTags() error { | |
| func (holes Holes) loadTags() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
/v2/holes/:idroute is wired to the existingGetHolehandler, which currently fetches and serializesmodels.Hole(aliasingHoleV1). That means the V2 endpoint will return the V1 response shape unless a dedicated V2 handler/model is used.