9aaafa2358
dashboard.go i izvestaji.go više ne sadrže direktan SQL — svih 12 upita prebačeno u novi IzvestajRepository (internal/db/sqlite/izvestaj.go). Repo vraća sirove redove (model.*Red tipovi), a handleri zadržavaju prezentaciju (formatiranje datuma, boje tačaka, rang, sklapanje niza 12 meseci). Žičenje kroz Handler.IzvestajRepo (+ reinicijalizuj). Dobici: testabilnost (dodati integracioni testovi izvestaj_test.go) i put ka Postgres-u bez prepravke handlera. dashboard.prihod provera ostaje u handleru. Van obima: middleware/flash.go i backup VACUUM INTO (ne pripadaju repo sloju).
176 lines
8.1 KiB
Go
176 lines
8.1 KiB
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"ntech/internal/model"
|
|
)
|
|
|
|
// ArtikalRepository definiše operacije nad artiklima
|
|
type ArtikalRepository interface {
|
|
Lista(ctx context.Context, filter ArtikalFilter) ([]model.ArtikalSaKategorijom, error)
|
|
DohvatiID(ctx context.Context, id int64) (*model.Artikal, error)
|
|
Kreiraj(ctx context.Context, a *model.Artikal) (int64, error)
|
|
Izmeni(ctx context.Context, a *model.Artikal) error
|
|
PremestiKategoriju(ctx context.Context, id int64, kategorijaID *int64) error
|
|
Obrisi(ctx context.Context, id int64) error
|
|
}
|
|
|
|
// KategorijaRepository definiše operacije nad kategorijama
|
|
type KategorijaRepository interface {
|
|
Lista(ctx context.Context) ([]model.Kategorija, error)
|
|
Kreiraj(ctx context.Context, k *model.Kategorija) (int64, error)
|
|
}
|
|
|
|
// ArtikalFilter definiše parametre za filtriranje liste artikala
|
|
type ArtikalFilter struct {
|
|
Pretraga string
|
|
KategorijaID *int64
|
|
SamoKriticni bool
|
|
}
|
|
|
|
// NabavkaRepository definiše operacije nad nabavkama
|
|
type NabavkaRepository interface {
|
|
Lista(ctx context.Context) ([]model.NabavkaSaDetaljem, error)
|
|
DohvatiID(ctx context.Context, id int64) (*model.Nabavka, error)
|
|
DohvatiStavke(ctx context.Context, nabavkaID int64) ([]model.StavkaSaArtiklom, error)
|
|
Kreiraj(ctx context.Context, n *model.Nabavka, stavke []model.StavkaNabavke) (int64, error)
|
|
Obrisi(ctx context.Context, id int64) error
|
|
}
|
|
|
|
// DobavljacRepository definiše operacije nad dobavljačima
|
|
type DobavljacRepository interface {
|
|
Lista(ctx context.Context, pretraga string) ([]model.Dobavljac, error)
|
|
DohvatiID(ctx context.Context, id int64) (*model.Dobavljac, error)
|
|
Kreiraj(ctx context.Context, d *model.Dobavljac) (int64, error)
|
|
Izmeni(ctx context.Context, d *model.Dobavljac) error
|
|
Obrisi(ctx context.Context, id int64) error
|
|
}
|
|
|
|
// KlijentRepository definiše operacije nad klijentima
|
|
type KlijentRepository interface {
|
|
Lista(ctx context.Context, pretraga string) ([]model.Klijent, error)
|
|
DohvatiID(ctx context.Context, id int64) (*model.Klijent, error)
|
|
Kreiraj(ctx context.Context, k *model.Klijent) (int64, error)
|
|
Izmeni(ctx context.Context, k *model.Klijent) error
|
|
Obrisi(ctx context.Context, id int64) error
|
|
}
|
|
|
|
// ServisRepository definiše operacije nad servisnim nalozima
|
|
type ServisRepository interface {
|
|
Lista(ctx context.Context, pretraga, status string) ([]model.ServisniNalogSaKlijentom, error)
|
|
DohvatiID(ctx context.Context, id int64) (*model.ServisniNalog, error)
|
|
Kreiraj(ctx context.Context, n *model.ServisniNalog) (int64, error)
|
|
Izmeni(ctx context.Context, n *model.ServisniNalog) error
|
|
Obrisi(ctx context.Context, id int64) error
|
|
SledeciBroj(ctx context.Context) (string, error)
|
|
}
|
|
|
|
// ProdajaRepository definiše operacije nad prodajnim nalozima
|
|
type ProdajaRepository interface {
|
|
Lista(ctx context.Context, pretraga string) ([]model.ProdajniNalogSaDetaljem, error)
|
|
DohvatiID(ctx context.Context, id int64) (*model.ProdajniNalog, error)
|
|
DohvatiStavke(ctx context.Context, nalogID int64) ([]model.StavkaProdajeSaArtiklom, error)
|
|
Kreiraj(ctx context.Context, n *model.ProdajniNalog, stavke []model.StavkaProdaje, korisnikID *int64) (int64, error)
|
|
Storno(ctx context.Context, id int64, razlog string, korisnikID *int64) error
|
|
Obrisi(ctx context.Context, id int64) error
|
|
SledeciBroj(ctx context.Context) (string, error)
|
|
}
|
|
|
|
// ServisniDeloviRepository definiše operacije nad ugrađenim delovima u servisu
|
|
type ServisniDeloviRepository interface {
|
|
DohvatiZaNalog(ctx context.Context, nalogID int64) ([]model.ServisniDeoSaArtiklom, error)
|
|
Dodaj(ctx context.Context, nalogID, artikalID int64, kolicina int, cenaKomada float64, korisnikID *int64) (int64, error)
|
|
Obrisi(ctx context.Context, id int64, korisnikID *int64) error
|
|
}
|
|
|
|
// MagacinskePromeneRepository definiše operacije nad revizijskim tragom magacina
|
|
type MagacinskePromeneRepository interface {
|
|
Lista(ctx context.Context, artikalID *int64, limit int) ([]model.MagacinskaPromenaSaDetaljem, error)
|
|
}
|
|
|
|
// KorisniciRepository definiše operacije nad korisnicima
|
|
type KorisniciRepository interface {
|
|
Kreiraj(ctx context.Context, korisnickoIme, lozinkaHash, uloga string) (*model.Korisnik, error)
|
|
DohvatiPoImenu(ctx context.Context, korisnickoIme string) (*model.Korisnik, error)
|
|
DohvatiPoID(ctx context.Context, id int64) (*model.Korisnik, error)
|
|
Lista(ctx context.Context) ([]model.Korisnik, error)
|
|
AzurirajUlogu(ctx context.Context, id int64, uloga string) error
|
|
AzurirajAktivan(ctx context.Context, id int64, aktivan bool) error
|
|
PromeniLozinku(ctx context.Context, id int64, hash string) error
|
|
SacuvajTotpTajnu(ctx context.Context, id int64, tajna string) error
|
|
SacuvajLokalnuTemu(ctx context.Context, id int64, lokalnaTema string, koristi bool) error
|
|
SacuvajLokalnuPozadinu(ctx context.Context, id int64, pozadina, opacity, blur, blurPozadine, glassOpacity string) error
|
|
PostojiIjedan(ctx context.Context) (bool, error)
|
|
Obrisi(ctx context.Context, id int64) error
|
|
}
|
|
|
|
// SesijeRepository definiše operacije nad sesijama
|
|
type SesijeRepository interface {
|
|
Kreiraj(ctx context.Context, korisnikID int64, token string, istice time.Time, totpPotvrdjeno bool) error
|
|
DohvatiPoTokenu(ctx context.Context, token string) (*model.Sesija, error)
|
|
PotvrdiTotp(ctx context.Context, token string, novoIstice time.Time) error
|
|
Obrisi(ctx context.Context, token string) error
|
|
ObrisiIstekle(ctx context.Context) error
|
|
}
|
|
|
|
// PodsetnikFilter definiše parametre za filtriranje liste podsetnika
|
|
type PodsetnikFilter struct {
|
|
SamoAktivni bool // true = samo nezavršeni; false = svi
|
|
KorisnikID *int64 // ako nije nil — samo podsetnici tog korisnika
|
|
}
|
|
|
|
// PokusajiPrijaveRepository definiše operacije nad evidencijom pokušaja prijave
|
|
type PokusajiPrijaveRepository interface {
|
|
Zabeleži(ctx context.Context, ip, korisnickoIme string, uspeh bool) error
|
|
BrojNeuspeha(ctx context.Context, ip string, od time.Time) (int, error)
|
|
VremePoslednjeg(ctx context.Context, ip string, od time.Time) (time.Time, bool, error)
|
|
ObrisiStare(ctx context.Context, pre time.Time) error
|
|
}
|
|
|
|
// LoginIstorijsaRepository definiše operacije nad evidencijom prijava
|
|
type LoginIstorijsaRepository interface {
|
|
Zabeleži(ctx context.Context, korisnikID *int64, ip, userAgent, razlog string, uspeh bool) error
|
|
ListaZaKorisnika(ctx context.Context, korisnikID int64, limit int) ([]*model.LoginPokusaj, error)
|
|
}
|
|
|
|
// DozvoleRepository definiše operacije nad dozvolama po ulogama
|
|
type DozvoleRepository interface {
|
|
ImaDozvolu(ctx context.Context, uloga, akcija string) bool
|
|
SveDozvole(ctx context.Context, uloga string) map[string]bool
|
|
Sacuvaj(ctx context.Context, uloga, akcija string, dozvoljeno bool) error
|
|
Reset(ctx context.Context) error
|
|
}
|
|
|
|
// IzvestajRepository definiše read-only upite za dashboard i stranicu izveštaja.
|
|
// Vraća sirove podatke; prezentaciju (datumi, boje, rang) radi handler.
|
|
type IzvestajRepository interface {
|
|
// dashboard — brojači
|
|
BrojArtikala(ctx context.Context) (int, error)
|
|
BrojAktivnihServisa(ctx context.Context) (int, error)
|
|
PrihodTekuciMesec(ctx context.Context) (float64, error)
|
|
BrojKriticnihZaliha(ctx context.Context) (int, error)
|
|
// dashboard — liste
|
|
PoslednjiServisi(ctx context.Context, limit int) ([]model.ServisRedDashboard, error)
|
|
KriticneZalihe(ctx context.Context, limit int) ([]model.ZalihaRed, error)
|
|
PoslednjeProdaje(ctx context.Context, limit int) ([]model.ProdajaRedDashboard, error)
|
|
// izveštaji
|
|
MesecniPrihodProdaja(ctx context.Context) ([]model.MesecniIznos, error)
|
|
MesecniPrihodServis(ctx context.Context) ([]model.MesecniIznos, error)
|
|
StariOtvoreniNalozi(ctx context.Context) ([]model.StariNalogRed, error)
|
|
TopArtikli(ctx context.Context, limit int) ([]model.TopArtikalRed, error)
|
|
TopKlijenti(ctx context.Context, limit int) ([]model.TopKlijentRed, error)
|
|
}
|
|
|
|
// PodsetnikRepository definiše operacije nad podsetnicima
|
|
type PodsetnikRepository interface {
|
|
Lista(ctx context.Context, filter PodsetnikFilter) ([]model.Podsetnik, error)
|
|
DohvatiID(ctx context.Context, id int64) (*model.Podsetnik, error)
|
|
Kreiraj(ctx context.Context, p *model.Podsetnik) (int64, error)
|
|
Izmeni(ctx context.Context, p *model.Podsetnik) error
|
|
OznaciZavrsenim(ctx context.Context, id int64, zavrseno bool) error
|
|
Obrisi(ctx context.Context, id int64) error
|
|
BrojAktivnih(ctx context.Context, filter PodsetnikFilter) (int, error)
|
|
}
|