本文整理匯總了Golang中pixelrelay/db.Dbh.GetAlbumById方法的典型用法代碼示例。如果您正苦於以下問題:Golang Dbh.GetAlbumById方法的具體用法?Golang Dbh.GetAlbumById怎麽用?Golang Dbh.GetAlbumById使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pixelrelay/db.Dbh
的用法示例。
在下文中一共展示了Dbh.GetAlbumById方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AlbumMove
func AlbumMove(req *http.Request, r render.Render, su models.User, dbh *db.Dbh, p *models.Page) {
// Default status
var status string = "Permission Denied"
var code int = 401
var reader io.Reader = req.Body
b, e := ioutil.ReadAll(reader)
if e != nil {
log.Println(e)
}
var f Data
err := json.Unmarshal(b, &f)
if err != nil {
log.Println(err)
}
log.Println(f)
albumId := f.Md.AlbumId
album := dbh.GetAlbumById(albumId)
log.Println("album: ", albumId)
if album.User == su.Id {
status = "Success"
code = 200
var image models.Image
for _, f := range f.Md.Images {
imageId, err := strconv.ParseInt(f.Id, 10, 10)
if err != nil {
log.Println("invalid image id: ", f.Id)
}
log.Println("Moving: ", f.Name, imageId)
image = dbh.GetImageById(imageId)
if image.User != su.Id {
status = "Permission Denied"
code = 401
continue
}
fromId := image.AlbumId
image.AlbumId = albumId
_ = dbh.UpdateImage(image)
log.Printf("Moved %s from: %d to: %d status: %s code: %d\n", f.Name, fromId, albumId, status, code)
}
}
p.Data = status
encoder.Render("json", code, "", p, r)
}
示例2: AlbumUpdate
func AlbumUpdate(req *http.Request, r render.Render, su models.User, dbh *db.Dbh, p *models.Page) {
p.SetUser(su)
var reader io.Reader = req.Body
b, e := ioutil.ReadAll(reader)
if e != nil {
log.Println(e)
}
var f interface{}
err := json.Unmarshal(b, &f)
if err != nil {
log.Println(err)
}
m := f.(map[string]interface{})
md := m["data"].(map[string]interface{})
// Default status
var status string = "Permission Denied"
var code int = 401
mi := int64(md["Id"].(float64))
mo := int64(md["Owner"].(float64))
name := md["Name"].(string)
album := dbh.GetAlbumById(mi)
if album.Id == mi && album.User == mo && su.Id == mo {
mAlbum := models.Album{
Id: mi,
Description: md["Description"].(string),
Name: md["Name"].(string),
User: mo,
Poster: md["Poster"].(string),
Private: md["Private"].(bool),
Privatekey: md["Privatekey"].(string)}
log.Printf("mAlbum: %+v\n", mAlbum)
uAlbum := dbh.AlbumUpdate(mAlbum)
log.Printf("uAlbum: %+v\n", uAlbum)
status = "Success"
code = 200
}
log.Println("Album Update: ", "Name: ", name, " Album Id: ", album.Id, "=", mi, " Album User: ", album.User, "=", mo, " Session: ", su.Id, "=", mo, " Status: ", status)
p.Data = models.AlbumResult{Status: status}
encoder.Render("json", code, "", p, r)
}