Skip to content

Commit

Permalink
chore: Organize code in shorter files. (#691)
Browse files Browse the repository at this point in the history
* chore: Organize code in shorter files.

* feat: Change link to documentation in a log output
  • Loading branch information
x1m3 authored Jul 18, 2024
1 parent 7fa4174 commit 34d9602
Show file tree
Hide file tree
Showing 7 changed files with 1,133 additions and 1,070 deletions.
43 changes: 43 additions & 0 deletions internal/api/agent.go
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
}
Loading

0 comments on commit 34d9602

Please sign in to comment.