Skip to content

Commit

Permalink
update pdf generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCherepovskyi committed Jan 4, 2024
1 parent e0dcc21 commit cbf6f2e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions internal/assets/migrations/002_default_template.sql
Original file line number Diff line number Diff line change
@@ -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));

-- +migrate Down

ALTER TABLE template DROP COLUMN is_default_template;
2 changes: 1 addition & 1 deletion internal/data/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
1 change: 1 addition & 0 deletions internal/service/core/pdf/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 10 additions & 2 deletions internal/service/core/pdf/default_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -55,6 +57,7 @@ var DefaultTemplateNormal = PDF{
X: 300,
Y: 277,
FontSize: 14,
XCenter: true,
Font: "semibold",
},
}
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/service/core/pdf/pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit cbf6f2e

Please sign in to comment.