Skip to content

Commit

Permalink
working on license record page
Browse files Browse the repository at this point in the history
  • Loading branch information
vsimakhin committed Jan 28, 2025
1 parent ff6664b commit f701330
Show file tree
Hide file tree
Showing 21 changed files with 410 additions and 211 deletions.
27 changes: 8 additions & 19 deletions app/handlers_licensing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/vsimakhin/web-logbook/internal/models"
)

// HandlerApiGetLicensingRecords returns a list of license records
func (app *application) HandlerApiGetLicensingRecords(w http.ResponseWriter, r *http.Request) {
licenses, err := app.db.GetLicenses()
if err != nil {
Expand All @@ -22,34 +23,22 @@ func (app *application) HandlerApiGetLicensingRecords(w http.ResponseWriter, r *
app.writeJSON(w, http.StatusOK, licenses)
}

//////////////////////////////////////////////
/////////////////////////////////////////////

// HandlerLicensingRecordByID is handler for a license record
func (app *application) HandlerLicensingRecordByID(w http.ResponseWriter, r *http.Request) {
// HandlerApiGetLicensingRecord is handler for a license record
func (app *application) HandlerApiGetLicensingRecord(w http.ResponseWriter, r *http.Request) {
uuid := chi.URLParam(r, "uuid")

license, err := app.db.GetLicenseRecordByID(uuid)
if err != nil {
app.errorLog.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
app.handleError(w, err)
return
}

categories, err := app.db.GetLicensesCategory()
if err != nil {
app.errorLog.Println(err)
}

data := make(map[string]interface{})
data["license"] = license
data["categories"] = categories

if err := app.renderTemplate(w, r, "license-record", &templateData{Data: data}); err != nil {
app.errorLog.Println(err)
}
app.writeJSON(w, http.StatusOK, license)
}

//////////////////////////////////////////////
/////////////////////////////////////////////

// HandlerLicensingDownload is a handler for downloading the license files
func (app *application) HandlerLicensingDownload(w http.ResponseWriter, r *http.Request) {
uuid := chi.URLParam(r, "uuid")
Expand Down
4 changes: 2 additions & 2 deletions app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,13 @@ func (app *application) routes() *chi.Mux {
// licensing
r.Route("/licensing", func(r chi.Router) {
r.Get("/list", app.HandlerApiGetLicensingRecords)
r.With(middleware.Compress(5)).Get("/{uuid}", app.HandlerApiGetLicensingRecord)
})

// attachments
r.Route("/attachment", func(r chi.Router) {
r.Get("/list/{uuid}", app.HandlerApiGetAttachments)
r.Get("/{uuid}", app.HandlerApiGetAttachment)
r.With(middleware.Compress(5)).Get("/{uuid}", app.HandlerApiGetAttachment)
r.Delete("/{uuid}", app.HandlerApiDeleteAttachment)
r.Post("/upload", app.HandlerApiUploadAttachment)
})
Expand Down Expand Up @@ -247,7 +248,6 @@ func (app *application) routes() *chi.Mux {
r.Get(APIMapData, app.HandlerMapData)

// documents
r.Get(APILicensingUUID, app.HandlerLicensingRecordByID)
r.Get(APILicensingNew, app.HandlerLicensingRecordNew)
r.Get(APILicensingDownloadUUID, app.HandlerLicensingDownload)

Expand Down
Loading

0 comments on commit f701330

Please sign in to comment.