From cbf6f2ea6d20428a5220f42122c4ad94297b99a6 Mon Sep 17 00:00:00 2001 From: MarkCherepovskyi Date: Thu, 4 Jan 2024 13:12:10 +0200 Subject: [PATCH] update pdf generation --- internal/assets/migrations/002_default_template.sql | 8 ++++++-- internal/data/template.go | 2 +- internal/service/core/pdf/container.go | 1 + internal/service/core/pdf/default_data.go | 12 ++++++++++-- internal/service/core/pdf/pdf.go | 2 +- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/internal/assets/migrations/002_default_template.sql b/internal/assets/migrations/002_default_template.sql index ad1e6c71..ffb6d7d4 100644 --- a/internal/assets/migrations/002_default_template.sql +++ b/internal/assets/migrations/002_default_template.sql @@ -1,5 +1,9 @@ -- +migrate Up +ALTER TABLE template DROP COLUMN is_default_template; -ALTER TABLE template ADD is_default_template INTEGER; +ALTER TABLE template ADD is_default_template BOOLEAN DEFAULT False; -ALTER TABLE template ADD CONSTRAINT ck_testbool_ischk CHECK (is_default_template IN (1,0)); \ No newline at end of file + +-- +migrate Down + +ALTER TABLE template DROP COLUMN is_default_template; diff --git a/internal/data/template.go b/internal/data/template.go index dac6d32a..4e25fed9 100644 --- a/internal/data/template.go +++ b/internal/data/template.go @@ -18,7 +18,7 @@ type Template struct { UserID int64 `db:"user_id" structs:"user_id"` Name string `db:"name" structs:"name"` ShortName string `db:"short_name" structs:"short_name"` - IsDefaultTemplate bool `db:"is_default_template" structs:"is_default_template"` Template []byte `db:"template" structs:"template"` ImgBytes []byte `db:"img_bytes" structs:"img_bytes"` //todo make better + IsDefaultTemplate bool `db:"is_default_template" structs:"is_default_template"` } diff --git a/internal/service/core/pdf/container.go b/internal/service/core/pdf/container.go index 10f5238d..7f7febde 100644 --- a/internal/service/core/pdf/container.go +++ b/internal/service/core/pdf/container.go @@ -53,6 +53,7 @@ func (c *Container) Generate() error { files = append(files, google.FilesBytes{File: file, Name: name, ID: user.ID, Type: "image/svg+xml"}) pdf := PDF{} + certificateTemplate, err := pdf.InitTemplate(c.masterQ, user.CourseTitle, c.owner.ID) if err != nil { return errors.Wrap(err, "failed to get template") diff --git a/internal/service/core/pdf/default_data.go b/internal/service/core/pdf/default_data.go index fc53c22f..4863dd9c 100644 --- a/internal/service/core/pdf/default_data.go +++ b/internal/service/core/pdf/default_data.go @@ -7,12 +7,14 @@ var DefaultTemplateNormal = PDF{ X: 200, Y: 217, FontSize: 28, + XCenter: true, Font: "semibold", }, Course: Field{ X: 61, Y: 259, FontSize: 14, + XCenter: true, Font: "semibold", }, Credits: Field{ @@ -55,6 +57,7 @@ var DefaultTemplateNormal = PDF{ X: 300, Y: 277, FontSize: 14, + XCenter: true, Font: "semibold", }, } @@ -65,11 +68,13 @@ var DefaultTemplateTall = PDF{ Name: Field{ Y: 434, FontSize: 56, + XCenter: true, Font: "semibold", }, Course: Field{ Y: 518, FontSize: 28, + XCenter: true, Font: "semibold", }, Credits: Field{ //todo get from front and save to db @@ -108,18 +113,21 @@ var DefaultTemplateTall = PDF{ Exam: Field{ Y: 600, FontSize: 30, + XCenter: true, Font: "italic", }, Level: Field{ Y: 554, FontSize: 28, + XCenter: true, Font: "semibold", }, } var DefaultData = PDFData{ - Name: "Test Name", - Course: "Blockchain and Distributed Systems", + Name: "Test Name", + Course: "Blockchain and Distributed Systems", + Credits: " 99", Points: "100", SerialNumber: "694d0f5a7afe6fbc99cb", diff --git a/internal/service/core/pdf/pdf.go b/internal/service/core/pdf/pdf.go index c5d25dba..4aac8b17 100644 --- a/internal/service/core/pdf/pdf.go +++ b/internal/service/core/pdf/pdf.go @@ -446,7 +446,7 @@ func (p *PDF) InitTemplate(masterQ data.MasterQ, templateName string, userID int if err != nil { return nil, errors.Wrap(err, "failed to get template data") } - if template == nil || template.Template == nil { + if template == nil || template.Template == nil || template.IsDefaultTemplate { return &DefaultTemplateTall, nil }