-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Organize code in shorter files. (#691)
* chore: Organize code in shorter files. * feat: Change link to documentation in a log output
- Loading branch information
Showing
7 changed files
with
1,133 additions
and
1,070 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/polygonid/sh-id-platform/internal/core/ports" | ||
"github.com/polygonid/sh-id-platform/internal/log" | ||
) | ||
|
||
// Agent is the controller to fetch credentials from mobile | ||
func (s *Server) Agent(ctx context.Context, request AgentRequestObject) (AgentResponseObject, error) { | ||
if request.Body == nil || *request.Body == "" { | ||
log.Debug(ctx, "agent empty request") | ||
return Agent400JSONResponse{N400JSONResponse{"cannot proceed with an empty request"}}, nil | ||
} | ||
|
||
basicMessage, mediatype, err := s.packageManager.Unpack([]byte(*request.Body)) | ||
if err != nil { | ||
log.Debug(ctx, "agent bad request", "err", err, "body", *request.Body) | ||
return Agent400JSONResponse{N400JSONResponse{"cannot proceed with the given request"}}, nil | ||
} | ||
|
||
req, err := ports.NewAgentRequest(basicMessage) | ||
if err != nil { | ||
log.Error(ctx, "agent parsing request", "err", err) | ||
return Agent400JSONResponse{N400JSONResponse{err.Error()}}, nil | ||
} | ||
|
||
agent, err := s.claimService.Agent(ctx, req, mediatype) | ||
if err != nil { | ||
log.Error(ctx, "agent error", "err", err) | ||
return Agent400JSONResponse{N400JSONResponse{err.Error()}}, nil | ||
} | ||
return Agent200JSONResponse{ | ||
Body: agent.Body, | ||
From: agent.From, | ||
Id: agent.ID, | ||
ThreadID: agent.ThreadID, | ||
To: agent.To, | ||
Typ: string(agent.Typ), | ||
Type: string(agent.Type), | ||
}, nil | ||
} |
Oops, something went wrong.