diff options
| author | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-10 17:10:19 -0700 | 
|---|---|---|
| committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-05-10 17:10:19 -0700 | 
| commit | c6422b49b8b946386ca1068ec6887bbf07a8b166 (patch) | |
| tree | c6c082c0875edfbb0eeb7379813e01024fa74367 /golang/api/handlers | |
| parent | 8827f2a643b5dee773869eccb5d839f636b2295d (diff) | |
| download | fatcat-c6422b49b8b946386ca1068ec6887bbf07a8b166.tar.gz fatcat-c6422b49b8b946386ca1068ec6887bbf07a8b166.zip | |
404 example
Diffstat (limited to 'golang/api/handlers')
| -rw-r--r-- | golang/api/handlers/entities.go | 56 | 
1 files changed, 53 insertions, 3 deletions
| diff --git a/golang/api/handlers/entities.go b/golang/api/handlers/entities.go index 61104553..9331a588 100644 --- a/golang/api/handlers/entities.go +++ b/golang/api/handlers/entities.go @@ -3,12 +3,46 @@ package handlers  import (      "github.com/go-pg/pg" +    "github.com/go-openapi/swag"      "github.com/go-openapi/runtime/middleware" +    log "github.com/sirupsen/logrus" -	//"git.archive.org/bnewbold/fatcat/golang/gen/models" +	"git.archive.org/bnewbold/fatcat/golang/gen/models"  	"git.archive.org/bnewbold/fatcat/golang/gen/restapi/operations"  ) +type CreatorRev struct { +    tableName struct{} `sql:"creator_rev"` +    Id          string +    ExtraJson   string +    Name        string +    Orcid       string +} + +type CreatorIdent struct { +    tableName struct{} `sql:"creator_ident"` +    Id          string +    IsLive      bool +    RevId       int64 +    //Rev         *CreatorRev +    RedirectId  int64 +} + +func (ci *CreatorIdent) State() string { +    if ci.IsLive && (ci.RedirectId == 0) && (ci.RevId == 0) { +        return "deleted" +    } else if ci.IsLive && (ci.RedirectId != 0) { +        return "redirect" +    } else if ci.IsLive && (ci.RedirectId == 0) && (ci.RevId != 0) { +        return "active" +    } else if !ci.IsLive && (ci.RedirectId == 0) && (ci.RevId != 0) { +        return "wip" +    } else { +        log.Fatalf("Invalid CreatorIdent state: %v", ci) +        panic("fail") +    } +} +  func NewGetCreatorIDHandler(db *pg.DB) operations.GetCreatorIDHandler {      return &getCreatorID{db: db}  } @@ -21,9 +55,25 @@ 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 -    return middleware.NotImplemented("operation .GetCreatorID has not yet been implemented. Coming soon!") -} +    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() +    if err == pg.ErrNoRows { +        return operations.NewGetCreatorIDNotFound().WithPayload(&models.Error{Message: swag.String("no such entity")}) +    } else if err != nil { +        log.Fatal(err) +    } +    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, +    } +    return operations.NewGetCreatorIDOK().WithPayload(api_entity) +}  func NewPostCreatorHandler(db *pg.DB) operations.PostCreatorHandler { | 
