feat(assist-api): ignore request's body for isLive and getByID

This commit is contained in:
Alexander 2025-04-16 10:14:29 +02:00
parent 7836153fca
commit a4a5ce6498
4 changed files with 33 additions and 65 deletions

View file

@ -101,7 +101,6 @@ func (e *handlersImpl) autocomplete(w http.ResponseWriter, r *http.Request) {
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize)
return
}
e.log.Debug(context.Background(), "autocomplete request, projectKey: %s, query: %v, response: %v", projectKey, query, resp)
response := map[string]interface{}{
"data": resp,
}
@ -122,25 +121,12 @@ func (e *handlersImpl) socketsListByProject(w http.ResponseWriter, r *http.Reque
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, bodySize)
return
}
bodyBytes, err := api.ReadBody(e.log, w, r, e.jsonSizeLimit)
if err != nil {
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusRequestEntityTooLarge, err, startTime, r.URL.Path, bodySize)
return
}
e.log.Debug(context.Background(), "bodyBytes: %s", bodyBytes)
bodySize = len(bodyBytes)
req := &service.Request{}
if err := json.Unmarshal(bodyBytes, req); err != nil {
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, bodySize)
return
}
resp, err := e.assist.GetByID(projectKey, sessionID, req)
resp, err := e.assist.GetByID(projectKey, sessionID)
if err != nil {
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize)
return
}
e.log.Debug(context.Background(), "socketsListByProject request, projectKey: %s, sessionID: %s, req: %v, response: %v", projectKey, sessionID, req, resp)
response := map[string]interface{}{
"data": resp,
}
@ -174,7 +160,6 @@ func (e *handlersImpl) socketsLiveByProject(w http.ResponseWriter, r *http.Reque
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize)
return
}
e.log.Debug(context.Background(), "socketsLiveByProject request, filters: %v, projectKey: %s, response: %v", req, projectKey, resp)
response := map[string]interface{}{
"data": resp,
}
@ -195,25 +180,12 @@ func (e *handlersImpl) socketsLiveBySession(w http.ResponseWriter, r *http.Reque
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, bodySize)
return
}
bodyBytes, err := api.ReadBody(e.log, w, r, e.jsonSizeLimit)
if err != nil {
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusRequestEntityTooLarge, err, startTime, r.URL.Path, bodySize)
return
}
e.log.Debug(context.Background(), "bodyBytes: %s", bodyBytes)
bodySize = len(bodyBytes)
req := &service.Request{}
if err := json.Unmarshal(bodyBytes, req); err != nil {
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusBadRequest, err, startTime, r.URL.Path, bodySize)
return
}
resp, err := e.assist.GetByID(projectKey, sessionID, req)
resp, err := e.assist.GetByID(projectKey, sessionID)
if err != nil {
e.responser.ResponseWithError(e.log, r.Context(), w, http.StatusInternalServerError, err, startTime, r.URL.Path, bodySize)
return
}
e.log.Debug(context.Background(), "socketsLiveBySession request, projectKey: %s, sessionID: %s, req: %v, response: %v", projectKey, sessionID, req, resp)
response := map[string]interface{}{
"data": resp,
}

View file

@ -1 +0,0 @@
package api

View file

@ -10,32 +10,6 @@ import (
"openreplay/backend/pkg/sessionmanager"
)
type Query struct {
Key string
Value string
}
type Filter struct {
Value []string `json:"values"`
Operator string `json:"operator"` // is|contains
}
type Pagination struct {
Limit int `json:"limit"`
Page int `json:"page"`
}
type Sort struct {
Key string `json:"key"` // useless
Order string `json:"order"` // [ASC|DESC]
}
type Request struct {
Filters map[string]Filter `json:"filter"`
Pagination Pagination `json:"pagination"`
Sort Sort `json:"sort"`
}
type assistImpl struct {
log logger.Logger
pgconn pool.Pool
@ -45,9 +19,9 @@ type assistImpl struct {
type Assist interface {
Autocomplete(projectKey string, query *Query) (interface{}, error)
IsLive(projectKey, sessionID string, filters *Request) (bool, error)
IsLive(projectKey, sessionID string) (bool, error)
GetAll(projectKey string, filters *Request) (interface{}, error)
GetByID(projectKey, sessionID string, filters *Request) (interface{}, error)
GetByID(projectKey, sessionID string) (interface{}, error)
}
func NewAssist(log logger.Logger, pgconn pool.Pool, projects projects.Projects, sessions sessionmanager.SessionManager) Assist {
@ -77,14 +51,12 @@ func (a *assistImpl) Autocomplete(projectKey string, query *Query) (interface{},
return a.sessions.Autocomplete(strconv.Itoa(int(project.ProjectID)), sessionmanager.FilterType(query.Key), query.Value)
}
func (a *assistImpl) IsLive(projectKey, sessionID string, filters *Request) (bool, error) {
func (a *assistImpl) IsLive(projectKey, sessionID string) (bool, error) {
switch {
case projectKey == "":
return false, fmt.Errorf("project key is required")
case sessionID == "":
return false, fmt.Errorf("session ID is required")
case filters == nil:
return false, fmt.Errorf("filters are required")
}
project, err := a.projects.GetProjectByKey(projectKey)
if err != nil {
@ -132,14 +104,12 @@ func (a *assistImpl) GetAll(projectKey string, request *Request) (interface{}, e
return resp, nil
}
func (a *assistImpl) GetByID(projectKey, sessionID string, filters *Request) (interface{}, error) {
func (a *assistImpl) GetByID(projectKey, sessionID string) (interface{}, error) {
switch {
case projectKey == "":
return nil, fmt.Errorf("project key is required")
case sessionID == "":
return nil, fmt.Errorf("session ID is required")
case filters == nil:
return nil, fmt.Errorf("filters are required")
}
project, err := a.projects.GetProjectByKey(projectKey)
if err != nil {

View file

@ -0,0 +1,27 @@
package service
type Query struct {
Key string
Value string
}
type Filter struct {
Value []string `json:"values"`
Operator string `json:"operator"` // is|contains
}
type Pagination struct {
Limit int `json:"limit"`
Page int `json:"page"`
}
type Sort struct {
Key string `json:"key"` // useless
Order string `json:"order"` // [ASC|DESC]
}
type Request struct {
Filters map[string]Filter `json:"filter"`
Pagination Pagination `json:"pagination"`
Sort Sort `json:"sort"`
}