Skip to content

Commit

Permalink
few method changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yahya077 committed Jul 24, 2024
1 parent eaa286d commit f5de3b2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions elevator/elevator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package elevator

import (
"encoding/json"
"errors"
"fmt"
"github.com/WEG-Technology/room"
"github.com/WEG-Technology/room/segment"
Expand Down Expand Up @@ -38,6 +39,7 @@ type IElevatorEngine interface {
PutBodyParser(roomKey, requestKey string, bodyParser room.IBodyParser) IElevatorEngine
PutQuery(roomKey, requestKey string, authStrategy room.IQuery) IElevatorEngine
GetElapsedTime() float64
Request(roomKey, requestKey string) (*room.Request, error)
}

type ElevatorEngine struct {
Expand Down Expand Up @@ -196,6 +198,17 @@ func (e *ElevatorEngine) PutQuery(roomKey, requestKey string, query room.IQuery)
panic(fmt.Sprintf("engine for %s not configured", roomKey))
}

func (e *ElevatorEngine) Request(roomKey, requestKey string) (*room.Request, error) {
if roomContainerEntry, ok := e.RoomContainers[roomKey]; ok {
if requestEntry, ok := roomContainerEntry.Requests[requestKey]; ok {
return requestEntry, nil
}
return nil, errors.New("request not found")
}

return nil, errors.New("request not found")
}

func NewElevator(integrationYmlPath string) Elevator {
ymlFile, err := readYml(integrationYmlPath)

Expand Down
4 changes: 2 additions & 2 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *Request) request() *http.Request {
return req
}

func (r *Request) initBaseUrl(baseUrl string) *Request {
func (r *Request) SetBaseUrl(baseUrl string) *Request {
if strings.HasPrefix(r.path, "/") {
r.path = r.path[1:]
}
Expand All @@ -107,7 +107,7 @@ func (r *Request) initBaseUrl(baseUrl string) *Request {
return r
}

func (r *Request) mergeHeader(header IHeader) *Request {
func (r *Request) MergeHeader(header IHeader) *Request {
if header != nil {
if r.Header == nil {
r.Header = header
Expand Down
4 changes: 2 additions & 2 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ func (r Response) RequestBody() map[string]any {

func (r Response) RequestDTO(v any) any {
if r.Data != nil {
_ = NewDTOFactory(r.Header.Get(headerKeyContentType)).marshall(r.Request.Data, v)
_ = NewDTOFactory(r.Header.Get(headerKeyContentType)).marshall(r.Request.Data, &v)
}

return v
}

func (r Response) RequestDTOorFail(v any) any {
return NewDTOFactory(r.Header.Get(headerKeyContentType)).marshall(r.Request.Data, v)
return NewDTOFactory(r.Header.Get(headerKeyContentType)).marshall(r.Request.Data, &v)
}

// IDTOFactory declares the interface for creating DTOs.
Expand Down

0 comments on commit f5de3b2

Please sign in to comment.