aboutsummaryrefslogtreecommitdiffstats
path: root/golang/api
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-10 18:55:26 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-10 18:55:26 -0700
commit353de263272d41f6d7c1becb481f787966a1aa4c (patch)
tree5cafa5a7dcc8c02d3d4e0bd729e4e43959ff4993 /golang/api
parente6fedd421bf7644e969072eff9f375ecb58b25e2 (diff)
downloadfatcat-353de263272d41f6d7c1becb481f787966a1aa4c.tar.gz
fatcat-353de263272d41f6d7c1becb481f787966a1aa4c.zip
improvements to creator endpoints
Diffstat (limited to 'golang/api')
-rw-r--r--golang/api/handlers/entities.go40
1 files changed, 20 insertions, 20 deletions
diff --git a/golang/api/handlers/entities.go b/golang/api/handlers/entities.go
index 9331a588..beed633a 100644
--- a/golang/api/handlers/entities.go
+++ b/golang/api/handlers/entities.go
@@ -12,30 +12,31 @@ import (
)
type CreatorRev struct {
- tableName struct{} `sql:"creator_rev"`
- Id string
+ Id int64
ExtraJson string
Name string
Orcid string
+ tableName struct{} `sql:"creator_rev"`
}
type CreatorIdent struct {
- tableName struct{} `sql:"creator_ident"`
- Id string
- IsLive bool
- RevId int64
- //Rev *CreatorRev
- RedirectId int64
+ Id string
+ IsLive bool
+ RevId int64
+ Rev *CreatorRev
+ RedirectId string
+ Redirect *CreatorIdent
+ tableName struct{} `sql:"creator_ident"`
}
func (ci *CreatorIdent) State() string {
- if ci.IsLive && (ci.RedirectId == 0) && (ci.RevId == 0) {
+ if ci.IsLive && (ci.RedirectId == "") && (ci.RevId == 0) {
return "deleted"
- } else if ci.IsLive && (ci.RedirectId != 0) {
+ } else if ci.IsLive && (ci.RedirectId != "") {
return "redirect"
- } else if ci.IsLive && (ci.RedirectId == 0) && (ci.RevId != 0) {
+ } else if ci.IsLive && (ci.RedirectId == "") && (ci.RevId != 0) {
return "active"
- } else if !ci.IsLive && (ci.RedirectId == 0) && (ci.RevId != 0) {
+ } else if !ci.IsLive && (ci.RedirectId == "") && (ci.RevId != 0) {
return "wip"
} else {
log.Fatalf("Invalid CreatorIdent state: %v", ci)
@@ -55,12 +56,11 @@ func (d *getCreatorID) Handle(params operations.GetCreatorIDParams) middleware.R
// "get or 404" using params.ID. join creator_ident and creator_rev.
// populate result data
// return that
- db_entity_ident := &CreatorIdent{Id: swag.StringValue(&params.ID)}
-
- err := d.db.Select(db_entity_ident)
- //err := d.db.Model(db_entity_ident).Select()
- // Relation("Rev").
- // Select()
+ db_entity_ident := &CreatorIdent{}
+ err := d.db.Model(db_entity_ident).
+ Column("creator_ident.*", "Rev").
+ Where("creator_ident.id = ?", swag.StringValue(&params.ID)).
+ First()
if err == pg.ErrNoRows {
return operations.NewGetCreatorIDNotFound().WithPayload(&models.Error{Message: swag.String("no such entity")})
} else if err != nil {
@@ -69,8 +69,8 @@ func (d *getCreatorID) Handle(params operations.GetCreatorIDParams) middleware.R
api_entity := &models.CreatorEntity{
Ident: &db_entity_ident.Id,
State: swag.String(db_entity_ident.State()),
- //Name: db_entity_ident.Rev.Name,
- //Orcid: db_entity_ident.Rev.Orcid,
+ Name: swag.String(db_entity_ident.Rev.Name),
+ Orcid: db_entity_ident.Rev.Orcid,
}
return operations.NewGetCreatorIDOK().WithPayload(api_entity)
}