|
15 | 15 | // Repo represents all stream endpoint interactions
|
16 | 16 | Repo interface {
|
17 | 17 | ListEndpoints(ctx context.Context) ([]EndpointDB, error)
|
| 18 | + FindEndpoint(ctx context.Context, findEndpoint FindEndpoint) (EndpointDB, error) |
18 | 19 | GetEndpointByID(ctx context.Context, endpointID int) (EndpointDB, error)
|
19 | 20 | GetEndpointByApplicationNamePwd(ctx context.Context, application, name, pwd string) (EndpointDB, error)
|
20 | 21 |
|
@@ -63,6 +64,18 @@ type (
|
63 | 64 | AutoRemove bool `json:"autoRemove,omitempty"`
|
64 | 65 | }
|
65 | 66 |
|
| 67 | + // FindEndpoint used to find an endpoint |
| 68 | + FindEndpoint struct { |
| 69 | + // EndpointID is the unique database id of the stream |
| 70 | + EndpointID int `json:"endpointId,omitempty"` |
| 71 | + // Application defines which RTMP application this is valid for |
| 72 | + Application string `json:"application,omitempty"` |
| 73 | + // Name is the unique name given in an application |
| 74 | + Name string `json:"name,omitempty"` |
| 75 | + // Pwd defines an extra layer of security for authentication |
| 76 | + Pwd string `json:"pwd,omitempty"` |
| 77 | + } |
| 78 | + |
66 | 79 | // NewEditEndpoint encapsulates the creation of a stream endpoint
|
67 | 80 | NewEditEndpoint struct {
|
68 | 81 | // Application defines which RTMP application this is valid for
|
@@ -114,6 +127,37 @@ func (s *Store) ListEndpoints(ctx context.Context) ([]EndpointDB, error) {
|
114 | 127 | return e, nil
|
115 | 128 | }
|
116 | 129 |
|
| 130 | +func (s *Store) FindEndpoint(ctx context.Context, findEndpoint *FindEndpoint) (EndpointDB, error) { |
| 131 | + var e EndpointDB |
| 132 | + |
| 133 | + builder := utils.PSQL().Select("*"). |
| 134 | + From("web_api.stream_endpoints"). |
| 135 | + Where(sq.Or{ |
| 136 | + sq.Eq{"endpoint_id": findEndpoint.EndpointID}, |
| 137 | + sq.And{ |
| 138 | + sq.Eq{"application": findEndpoint.Application}, |
| 139 | + sq.Eq{"name": findEndpoint.Name}, |
| 140 | + sq.Eq{"pwd": findEndpoint.Pwd}, |
| 141 | + }, |
| 142 | + }) |
| 143 | + |
| 144 | + sql, args, err := builder.ToSql() |
| 145 | + if err != nil { |
| 146 | + panic(fmt.Errorf("failed to build sql for FindEndpoint: %w", err)) |
| 147 | + } |
| 148 | + |
| 149 | + err = s.db.GetContext(ctx, &e, sql, args...) |
| 150 | + if err != nil { |
| 151 | + return EndpointDB{}, fmt.Errorf("failed to find endpoint: %w", err) |
| 152 | + } |
| 153 | + |
| 154 | + findEndpoint.EndpointID = e.EndpointID |
| 155 | + findEndpoint.Application = e.Application |
| 156 | + findEndpoint.Name = e.Name |
| 157 | + |
| 158 | + return e, nil |
| 159 | +} |
| 160 | + |
117 | 161 | func (s *Store) GetEndpointByID(ctx context.Context, endpointID int) (EndpointDB, error) {
|
118 | 162 | var e EndpointDB
|
119 | 163 |
|
|
0 commit comments