Skip to content

Commit

Permalink
feat: Allow fetching Origin data
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioabreu committed Apr 24, 2024
1 parent f3f7eaf commit 5761850
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions internal/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,27 @@ func (o *OriginController) UpdateOrigin(ctx *gin.Context) {
Message: "Origin updated successfully",
})
}

func (o *OriginController) GetOrigin(ctx *gin.Context) {
id, err := uuid.Parse(ctx.Param("id"))
if err != nil {
ctx.JSON(http.StatusBadRequest, ErrorResponse{
Error: Error{Message: "BadRequest: invalid UUID format"},
})

return
}

origin, err := o.originHandler.Get(ctx, id)
if err != nil {
ctx.JSON(http.StatusInternalServerError, ErrorResponse{
Error: Error{Message: "InternalServerError: failed to get origin"},
})

return
}

ctx.JSON(http.StatusOK, SuccessResponse{
Data: FromOrigin(origin),
})
}
7 changes: 7 additions & 0 deletions internal/api/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,10 @@ func (o *OriginData) ToOrigin() service.Origin {
Address: o.Address,
}
}

func FromOrigin(origin service.Origin) OriginData {
return OriginData{
ID: origin.ID,
Address: origin.Address,
}
}
5 changes: 5 additions & 0 deletions internal/service/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Origin struct {

type OriginHandler interface {
Update(context.Context, Origin) error
Get(context.Context, uuid.UUID) (Origin, error)
}

type originHandler struct {
Expand All @@ -33,3 +34,7 @@ func NewOriginHandler(store OriginStore) OriginHandler {
func (h *originHandler) Update(ctx context.Context, origin Origin) error {
return h.store.Update(ctx, origin)
}

func (h *originHandler) Get(ctx context.Context, id uuid.UUID) (Origin, error) {
return h.store.Get(ctx, id)
}

0 comments on commit 5761850

Please sign in to comment.