mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat: add postgres support (#215)
* feat: add postgres support and refactor * feat: improve releases find * fix: autobrrctl create user
This commit is contained in:
parent
f6873e932e
commit
3185832708
30 changed files with 1708 additions and 831 deletions
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
type actionService interface {
|
||||
Fetch() ([]domain.Action, error)
|
||||
List(ctx context.Context) ([]domain.Action, error)
|
||||
Store(ctx context.Context, action domain.Action) (*domain.Action, error)
|
||||
Delete(actionID int) error
|
||||
ToggleEnabled(actionID int) error
|
||||
|
@ -39,7 +39,7 @@ func (h actionHandler) Routes(r chi.Router) {
|
|||
}
|
||||
|
||||
func (h actionHandler) getActions(w http.ResponseWriter, r *http.Request) {
|
||||
actions, err := h.service.Fetch()
|
||||
actions, err := h.service.List(r.Context())
|
||||
if err != nil {
|
||||
// encode error
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
type downloadClientService interface {
|
||||
List(ctx context.Context) ([]domain.DownloadClient, error)
|
||||
Store(ctx context.Context, client domain.DownloadClient) (*domain.DownloadClient, error)
|
||||
Update(ctx context.Context, client domain.DownloadClient) (*domain.DownloadClient, error)
|
||||
Delete(ctx context.Context, clientID int) error
|
||||
Test(client domain.DownloadClient) error
|
||||
}
|
||||
|
@ -93,7 +94,7 @@ func (h downloadClientHandler) update(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
client, err := h.service.Store(r.Context(), data)
|
||||
client, err := h.service.Update(r.Context(), data)
|
||||
if err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
|
|
|
@ -12,9 +12,9 @@ import (
|
|||
)
|
||||
|
||||
type indexerService interface {
|
||||
Store(indexer domain.Indexer) (*domain.Indexer, error)
|
||||
Update(indexer domain.Indexer) (*domain.Indexer, error)
|
||||
List() ([]domain.Indexer, error)
|
||||
Store(ctx context.Context, indexer domain.Indexer) (*domain.Indexer, error)
|
||||
Update(ctx context.Context, indexer domain.Indexer) (*domain.Indexer, error)
|
||||
List(ctx context.Context) ([]domain.Indexer, error)
|
||||
GetAll() ([]*domain.IndexerDefinition, error)
|
||||
GetTemplates() ([]domain.IndexerDefinition, error)
|
||||
Delete(ctx context.Context, id int) error
|
||||
|
@ -55,20 +55,23 @@ func (h indexerHandler) getSchema(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (h indexerHandler) store(w http.ResponseWriter, r *http.Request) {
|
||||
var data domain.Indexer
|
||||
var (
|
||||
ctx = r.Context()
|
||||
data domain.Indexer
|
||||
)
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
indexer, err := h.service.Store(data)
|
||||
indexer, err := h.service.Store(ctx, data)
|
||||
if err != nil {
|
||||
//
|
||||
h.encoder.StatusResponse(r.Context(), w, nil, http.StatusBadRequest)
|
||||
h.encoder.StatusResponse(ctx, w, nil, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.StatusResponse(r.Context(), w, indexer, http.StatusCreated)
|
||||
h.encoder.StatusResponse(ctx, w, indexer, http.StatusCreated)
|
||||
}
|
||||
|
||||
func (h indexerHandler) update(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -81,7 +84,7 @@ func (h indexerHandler) update(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
indexer, err := h.service.Update(data)
|
||||
indexer, err := h.service.Update(ctx, data)
|
||||
if err != nil {
|
||||
//
|
||||
}
|
||||
|
@ -118,7 +121,7 @@ func (h indexerHandler) getAll(w http.ResponseWriter, r *http.Request) {
|
|||
func (h indexerHandler) list(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
indexers, err := h.service.List()
|
||||
indexers, err := h.service.List(ctx)
|
||||
if err != nil {
|
||||
//
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ type ircService interface {
|
|||
ListNetworks(ctx context.Context) ([]domain.IrcNetwork, error)
|
||||
GetNetworksWithHealth(ctx context.Context) ([]domain.IrcNetworkWithHealth, error)
|
||||
DeleteNetwork(ctx context.Context, id int64) error
|
||||
GetNetworkByID(id int64) (*domain.IrcNetwork, error)
|
||||
GetNetworkByID(ctx context.Context, id int64) (*domain.IrcNetwork, error)
|
||||
StoreNetwork(ctx context.Context, network *domain.IrcNetwork) error
|
||||
UpdateNetwork(ctx context.Context, network *domain.IrcNetwork) error
|
||||
StoreChannel(networkID int64, channel *domain.IrcChannel) error
|
||||
|
@ -61,7 +61,7 @@ func (h ircHandler) getNetworkByID(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
id, _ := strconv.Atoi(networkID)
|
||||
|
||||
network, err := h.service.GetNetworkByID(int64(id))
|
||||
network, err := h.service.GetNetworkByID(ctx, int64(id))
|
||||
if err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
type releaseService interface {
|
||||
Find(ctx context.Context, query domain.ReleaseQueryParams) (res []domain.Release, nextCursor int64, count int64, err error)
|
||||
Find(ctx context.Context, query domain.ReleaseQueryParams) (res []*domain.Release, nextCursor int64, count int64, err error)
|
||||
GetIndexerOptions(ctx context.Context) ([]string, error)
|
||||
Stats(ctx context.Context) (*domain.ReleaseStats, error)
|
||||
Delete(ctx context.Context) error
|
||||
|
@ -105,9 +105,9 @@ func (h releaseHandler) findReleases(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
ret := struct {
|
||||
Data []domain.Release `json:"data"`
|
||||
NextCursor int64 `json:"next_cursor"`
|
||||
Count int64 `json:"count"`
|
||||
Data []*domain.Release `json:"data"`
|
||||
NextCursor int64 `json:"next_cursor"`
|
||||
Count int64 `json:"count"`
|
||||
}{
|
||||
Data: releases,
|
||||
NextCursor: nextCursor,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue