Vlasnik izlazi iz DAL price za ovaj projekat - postaje samostalan proizvod. Preimenovanje je mehanicko (import putanje, imena fajlova/baze/UI naslova), NIJEDNA linija poslovne logike u internal/handler ili internal/service nije dirana - go build, go vet i go test ./... prolaze cisto pod novim imenom. - go.mod: module dal-license-server -> licence-server; 28 import linija u 13 .go fajlova usaglaseno - internal/config/config.go (+test): default DB_NAME licence_db - HTML sabloni (7 stranica) + 7 Playwright e2e spec fajlova: "DAL License Server" -> "Licence Server" u title/nav-brand, testovi usaglaseni u istom prolazu (nista ne moze da se razdvoji) - package.json/package-lock.json/.gitignore/.claude/project.json: ime projekta/binarnog fajla/work_dir - Usput: package.json je u repository.url nosio OTVORENU Gitea lozinku u cistom tekstu - uklonjena (URL sad bez kredencijala). Lozinka je i dalje u staroj git istoriji - preporuka: rotirati je posebno. - CLAUDE.md/README/API/TESTING/docs/SPEC/ARCHITECTURE/SETUP: naslovi, ASCII dijagrami, git clone URL, mysqldump primer, systemd predlozak u SETUP.md zamenjen stvarnim (obrazac terminia.service - journal log + graceful shutdown, ne stari minimalni predlozak) - Debrendiranje: "Univerzalni licencni server za sve DAL proizvode" -> "za vise proizvoda i klijenata"; potpis "Nenad Djukic / DAL d.o.o." -> "Nenad Djukic". NE dirano: nazivi ESIR/ARV/LIGHT_TICKET (tudji proizvodi, ne DAL brend), "DAL" kao stvaran naziv org-a u RBAC modelu (docs/loggerservice/README.md) - to je podatak, ne branding ovog servera. - docs/asp-terminia/, docs/loggerservice/: prozni pomeni imena servera Baza (dal_license_db -> licence_db) i deploy na 151 idu u posebnom koraku, posle preimenovanja Gitea repoa - vidi CLAUDE.md istorijsku belesku na dnu. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
163 lines
4.8 KiB
Go
163 lines
4.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"licence-server/internal/model"
|
|
"licence-server/internal/repository"
|
|
"licence-server/internal/service"
|
|
"encoding/json"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
type AdminHandler struct {
|
|
licenses *service.LicenseService
|
|
activation *service.ActivationService
|
|
audit *repository.AuditRepo
|
|
}
|
|
|
|
func NewAdminHandler(licenses *service.LicenseService, activation *service.ActivationService, audit *repository.AuditRepo) *AdminHandler {
|
|
return &AdminHandler{licenses: licenses, activation: activation, audit: audit}
|
|
}
|
|
|
|
func (h *AdminHandler) ListProducts(w http.ResponseWriter, r *http.Request) {
|
|
products, err := h.licenses.GetProducts()
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "INTERNAL_ERROR", "Greska pri ucitavanju proizvoda")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, products)
|
|
}
|
|
|
|
func (h *AdminHandler) ListLicenses(w http.ResponseWriter, r *http.Request) {
|
|
product := r.URL.Query().Get("product")
|
|
status := r.URL.Query().Get("status")
|
|
search := r.URL.Query().Get("search")
|
|
|
|
licenses, err := h.licenses.List(product, status, search)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "INTERNAL_ERROR", "Greska pri ucitavanju licenci")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, licenses)
|
|
}
|
|
|
|
func (h *AdminHandler) CreateLicense(w http.ResponseWriter, r *http.Request) {
|
|
var req model.CreateLicenseRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_REQUEST", "Neispravan zahtev")
|
|
return
|
|
}
|
|
|
|
license, err := h.licenses.Create(&req, clientIP(r))
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "CREATE_FAILED", err.Error())
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusCreated, license)
|
|
}
|
|
|
|
func (h *AdminHandler) GetLicense(w http.ResponseWriter, r *http.Request) {
|
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_ID", "Neispravan ID")
|
|
return
|
|
}
|
|
|
|
license, err := h.licenses.GetByID(id)
|
|
if err != nil {
|
|
writeError(w, http.StatusNotFound, "NOT_FOUND", "Licenca nije pronadjena")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, license)
|
|
}
|
|
|
|
func (h *AdminHandler) UpdateLicense(w http.ResponseWriter, r *http.Request) {
|
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_ID", "Neispravan ID")
|
|
return
|
|
}
|
|
|
|
var req model.UpdateLicenseRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_REQUEST", "Neispravan zahtev")
|
|
return
|
|
}
|
|
|
|
if err := h.licenses.Update(id, &req, clientIP(r)); err != nil {
|
|
writeError(w, http.StatusInternalServerError, "UPDATE_FAILED", err.Error())
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, map[string]string{"message": "Licenca azurirana"})
|
|
}
|
|
|
|
func (h *AdminHandler) RevokeLicense(w http.ResponseWriter, r *http.Request) {
|
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_ID", "Neispravan ID")
|
|
return
|
|
}
|
|
|
|
var req model.RevokeRequest
|
|
json.NewDecoder(r.Body).Decode(&req)
|
|
|
|
if err := h.licenses.Revoke(id, req.Reason, clientIP(r)); err != nil {
|
|
writeError(w, http.StatusInternalServerError, "REVOKE_FAILED", err.Error())
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, map[string]string{"message": "Licenca opozvana"})
|
|
}
|
|
|
|
func (h *AdminHandler) ReleaseLicense(w http.ResponseWriter, r *http.Request) {
|
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_ID", "Neispravan ID")
|
|
return
|
|
}
|
|
|
|
if err := h.activation.ForceRelease(id, clientIP(r)); err != nil {
|
|
writeError(w, http.StatusInternalServerError, "RELEASE_FAILED", err.Error())
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, map[string]string{"message": "Aktivacija oslobodjena"})
|
|
}
|
|
|
|
func (h *AdminHandler) ListActivations(w http.ResponseWriter, r *http.Request) {
|
|
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
|
if err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_ID", "Neispravan ID")
|
|
return
|
|
}
|
|
|
|
acts, err := h.activation.ListByLicense(id)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "INTERNAL_ERROR", "Greska")
|
|
return
|
|
}
|
|
if acts == nil {
|
|
acts = []model.Activation{}
|
|
}
|
|
writeJSON(w, http.StatusOK, acts)
|
|
}
|
|
|
|
func (h *AdminHandler) AuditLog(w http.ResponseWriter, r *http.Request) {
|
|
entries, err := h.audit.Recent(100)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "INTERNAL_ERROR", "Greska")
|
|
return
|
|
}
|
|
if entries == nil {
|
|
entries = []model.AuditEntry{}
|
|
}
|
|
writeJSON(w, http.StatusOK, entries)
|
|
}
|
|
|
|
func (h *AdminHandler) Stats(w http.ResponseWriter, r *http.Request) {
|
|
stats, err := h.licenses.GetStats()
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "INTERNAL_ERROR", "Greska")
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, stats)
|
|
}
|