From 353de263272d41f6d7c1becb481f787966a1aa4c Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 10 May 2018 18:55:26 -0700 Subject: improvements to creator endpoints --- golang/api/handlers/entities.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'golang') 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(¶ms.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(¶ms.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) } -- cgit v1.2.3