func (pub *Publication) getProps(sess *dbr.Session, id string) ([]*pubProp, error) { var props []*pubProp _, err := sess.Select( "pubprop.value", "cvterm.name as term", ).From("pubprop"). Join("pub", dbr.Eq("pubprop.pub_id", "pub.pub_id")). Join("cvterm", dbr.Eq("pubprop.type_id", "cvterm.type_id")). Join("cv", dbr.Eq("cvterm.cv_id", "cv.cv_id")). Where( dbr.And( dbr.Eq("pub.uniquename", id), dbr.Eq("pub.is_obsolete", "0"), dbr.Eq("cv.name", "pub_type"), ), ).LoadStructs(&props) return props, err }
func (m *Members) Load(tx *dbr.Tx, position string) error { var condition dbr.Condition if position != "" { condition = dbr.Eq("position", position) } return tx.Select("*"). From("member"). Where(condition). LoadStruct(m) }
func (pub *Publication) Get(w http.ResponseWriter, r *http.Request) { id := router.Params(r).ByName("id") sess := pub.GetDbh().NewSession(nil) var pubRow pubData err := sess.Select( "pub.title", "pub.volume", "pub.series_name", "pub.issue", "pub.pages", "pub.uniquename", "cvterm.name", "pub.pubplace", "pub.pyear", ).From("pub").Join("cvterm", dbr.Eq("pub.type_id", "cvterm.cvterm_id")). Where( dbr.And( dbr.Eq("pub.uniquename", id), dbr.Eq("pub.is_obsolete", "0"), ), ).LoadStruct(&pubRow) if err != nil { render.DatabaseError(w, err) return } props, err := pub.getProps(sess, id) if err != nil { render.DatabaseError(w, err) return } // Now check if authors needs to be included var authors []*publication.Author params := r.URL.Query() if val, ok := params["include"]; ok { if val[0] == "authors" { _, err := sess.Select( "pubauthor.pubauthor_id", "pubauthor.rank", "pubauthor.surname", "pubauthor.givennames", ).From("pubauthor"). Join("pub", dbr.Eq("pubauthor.pub_id", "pub.pub_id")). Where( dbr.And( dbr.Eq("pub.uniquename", id), dbr.Eq("pub.is_obsolete", "0"), ), ).LoadStructs(&authors) if err != nil { render.DatabaseError(w, err) return } } } // publication type struct that will be converted to json pubj := &publication.Publication{ ID: pubRow.PubId, Title: pubRow.Title, Journal: pubRow.Journal, Year: pubRow.Year, Volume: pubRow.Volume.String, Pages: pubRow.Pages.String, PubType: pubRow.PubType, Source: pubRow.Source, Issue: pubRow.Issue.String, } for _, p := range props { v := p.Value switch p.Term { case "doi": pubj.Doi = v case "status": pubj.Status = v case "month": pubj.Month = v case "issn": pubj.Issn = v case "abstract": pubj.Abstract = v } } if len(authors) > 0 { pubj.Authors = authors } render.Resource(pubj, resources.GetAPIServerInfo(r, pub.PathPrefix), w) }
func (pub *Publication) GetAll(w http.ResponseWriter, r *http.Request) { pageProps := resources.GetPaginationProp(r) // Get the total no of publications sess := pub.GetDbh().NewSession(nil) var count int err := sess.Select("count(pub_id)").From("pub").LoadValue(&count) if err != nil { render.DatabaseError(w, err) return } pageProps.Records = count // Now get a list of publications within that page range var pubRows []*pubData err = sess.Select( "pub.title", "pub.volume", "pub.series_name", "pub.issue", "pub.pages", "pub.uniquename", "cvterm.name", "pub.pubplace", "pub.pyear", ).From("pub"). Join("cvterm", dbr.Eq("pub.type_id", "cvterm.cvterm_id")). Where(dbr.Eq("pub.is_obsolete", "0")). Paginate(uint64(pageProps.Current), uint64(pageProps.Entries)). LoadStruct(&pubRows) if err != nil { render.DatabaseError(w, err) return } var pubSlice []*publication.Publication for _, pb := range pubRows { props, err := pub.getProps(sess, pb.PubId) if err != nil { render.DatabaseError(w, err) return } pubj := &publication.Publication{ ID: pb.PubId, Title: pb.Title, Journal: pb.Journal, Year: pb.Year, Volume: pb.Volume.String, Pages: pb.Pages.String, PubType: pb.PubType, Source: pb.Source, Issue: pb.Issue.String, } for _, p := range props { v := p.Value switch p.Term { case "doi": pubj.Doi = v case "status": pubj.Status = v case "month": pubj.Month = v case "issn": pubj.Issn = v case "abstract": pubj.Abstract = v } } pubSlice = append(pubSlice, pubj) } render.ResourceCollection(pubSlice, resources.GetAPIServerInfo(r, pub.PathPrefix), w, pageProps) }