MCPcopy Create free account
hub / github.com/OpenTreeHole/treehole_next / Create

Method Create

models/hole.go:363–399  ·  view source on GitHub ↗
(c *fiber.Ctx, content string, specialTag string, db ...*gorm.DB)

Source from the content-addressed store, hash-verified

361}
362
363func (hole *Hole) Create(c *fiber.Ctx, content string, specialTag string, db ...*gorm.DB) error {
364 var tx *gorm.DB
365 if len(db) > 0 {
366 tx = db[0]
367 } else {
368 tx = DB
369 }
370
371 hole.UserID, _ = GetUserID(c)
372
373 return tx.Transaction(func(tx *gorm.DB) error {
374 // Create hole
375 hole.Reply = -1
376 result := tx.Omit("Tags").Create(hole) // tags are created in AfterCreate hook
377 if result.Error != nil {
378 return result.Error
379 }
380 hole.Reply = 0
381
382 // Bind and Create floor
383 floor := Floor{
384 HoleID: hole.ID,
385 Content: content,
386 UserID: hole.UserID,
387 SpecialTag: specialTag,
388 }
389
390 // create floor
391 err := floor.Create(c, tx)
392 if err != nil {
393 return err
394 }
395
396 // create Favorite
397 return UserCreateFavourite(tx, c, false, hole.UserID, []int{hole.ID})
398 })
399}
400
401func (hole *Hole) AfterCreate(tx *gorm.DB) (err error) {
402 hole.HoleID = hole.ID

Callers 11

CreateHoleFunction · 0.95
CreateHoleOldFunction · 0.95
initFunction · 0.45
initFunction · 0.45
initFunction · 0.45
initFunction · 0.45
initFunction · 0.45
TestDeleteDivisionFunction · 0.45
initFunction · 0.45
SetTagsMethod · 0.45
initFunction · 0.45

Calls 3

CreateMethod · 0.95
GetUserIDFunction · 0.85
UserCreateFavouriteFunction · 0.85

Tested by 7

initFunction · 0.36
initFunction · 0.36
initFunction · 0.36
initFunction · 0.36
initFunction · 0.36
TestDeleteDivisionFunction · 0.36
initFunction · 0.36