commit caeef8c14a7b4f5c17f45469001c54c4927c4677
parent c7434dea4e315788662555a94e4b169303b6f993
Author: Shivakumar <[email protected]>
Date: Mon, 3 Aug 2026 04:27:48 +0530
feat(api): add GetInstitution endpoint
Signed-off-by: Shivakumar <[email protected]>
Diffstat:
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/api/handlers/institution.go b/api/handlers/institution.go
@@ -22,6 +22,7 @@ import (
"certichain/api/dto"
"certichain/internal/registry"
+ "certichain/internal/storage"
)
// writeJSON writes v as a JSON response with the given status code.
@@ -49,7 +50,7 @@ func RegisterInstitution(reg *registry.Registry) http.HandlerFunc {
pubKey, err := hex.DecodeString(req.PublicKey)
if err != nil {
- writeError(w, http.StatusBadRequest, "invalid_body", "Invalid hex Encoding")
+ writeError(w, http.StatusBadRequest, "invalid_body", "Invalid Hex Encoding")
return
}
@@ -69,3 +70,28 @@ func RegisterInstitution(reg *registry.Registry) http.HandlerFunc {
writeJSON(w, http.StatusCreated, dto.RegisterInstitutionResponse{DID: did})
}
}
+
+// GetInstitution returns a handler for Get /v1/institutions/{did}.
+func GetInstitution(reg *registry.Registry) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ did := r.PathValue("did")
+
+ _, err := reg.Get(did)
+ switch {
+ case err == nil:
+ writeJSON(w, http.StatusOK, &dto.GetInstitutionResponse{
+ DID: did,
+ Registered: true,
+ })
+ case errors.Is(err, storage.ErrNotFound):
+ writeJSON(w, http.StatusOK, &dto.GetInstitutionResponse{
+ DID: "",
+ Registered: false,
+ })
+ case errors.Is(err, registry.ErrInvalidDID):
+ writeError(w, http.StatusBadRequest, "invalid_did", "malformed DID")
+ default:
+ writeError(w, http.StatusInternalServerError, "server_error", "Internal Server Error")
+ }
+ }
+}
diff --git a/api/router.go b/api/router.go
@@ -26,6 +26,7 @@ func NewRouter(deps Deps) http.Handler {
mux.HandleFunc("GET /healthz", handlers.Health())
mux.HandleFunc("POST /v1/institutions", handlers.RegisterInstitution(deps.Registry))
+ mux.HandleFunc("GET /v1/institutions/{did}", handlers.GetInstitution(deps.Registry))
return mux
}