(c *gin.Context)
| 25 | } |
| 26 | |
| 27 | func proofExists(c *gin.Context) { |
| 28 | req := ProofExistsRequest{} |
| 29 | if err := c.BindQuery(&req); err != nil { |
| 30 | errorResp(c, http.StatusBadRequest, xerrors.Errorf("Param error")) |
| 31 | return |
| 32 | } |
| 33 | if !proofExistsCheckRequest(&req) { |
| 34 | errorResp(c, http.StatusBadRequest, xerrors.Errorf("Param missing")) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | personaPubkey, err := crypto.StringToPubkey(req.PersonaPubkeyHex) |
| 39 | if err != nil { |
| 40 | errorResp(c, http.StatusBadRequest, xerrors.Errorf("Public key unmarshal error")) |
| 41 | return |
| 42 | } |
| 43 | found := model.Proof{} |
| 44 | tx := model.ReadOnlyDB.Where( |
| 45 | "persona = ? AND platform = ? AND (identity = ? OR alt_id = ?)", |
| 46 | model.MarshalPersona(personaPubkey), |
| 47 | req.Platform, |
| 48 | strings.ToLower(req.Identity), |
| 49 | strings.ToLower(req.Identity), |
| 50 | ).Find(&found) |
| 51 | |
| 52 | if tx.Error != nil { |
| 53 | errorResp(c, http.StatusInternalServerError, xerrors.Errorf("Error in DB: %w", err)) |
| 54 | return |
| 55 | } |
| 56 | if found.ID == int64(0) { // Not found |
| 57 | errorResp(c, http.StatusNotFound, xerrors.Errorf("Record not found for %s: %s", req.Platform, req.Identity)) |
| 58 | return |
| 59 | } |
| 60 | if found.IsOutdated() { |
| 61 | go triggerRevalidate(found.ID) |
| 62 | } |
| 63 | |
| 64 | c.JSON(http.StatusOK, ProofExistsResponse{ |
| 65 | CreatedAt: strconv.FormatInt(found.CreatedAt.Unix(), 10), |
| 66 | LastCheckedAt: strconv.FormatInt(found.LastCheckedAt.Unix(), 10), |
| 67 | IsValid: found.IsValid, |
| 68 | InvalidReason: found.InvalidReason, |
| 69 | }) |
| 70 | } |
| 71 | |
| 72 | func proofExistsCheckRequest(req *ProofExistsRequest) bool { |
| 73 | return req.Identity != "" && req.Platform != "" && req.PersonaPubkeyHex != "" |
nothing calls this directly
no test coverage detected