Skip to content

armgit / posta

Public Imported from GitHub
0

Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.

fix: include stylesheet and localizations in version responses, use fresh sample data for preview

Jonas Kanindaf04d8e43f041
diff --git a/internal/handlers/template_version_handler.go b/internal/handlers/template_version_handler.go
index 511d909..2245df3 100644
--- a/internal/handlers/template_version_handler.go
+++ b/internal/handlers/template_version_handler.go
@@ -112,6 +112,7 @@ func (h *TemplateVersionHandler) Create(c *okapi.Context, req *CreateVersionRequ
return c.AbortInternalServerError("failed to create version")
}
+ v, _ = h.versionRepo.FindByID(v.ID)
return created(c, v)
}
diff --git a/internal/models/template_version.go b/internal/models/template_version.go
index 1636534..737d047 100644
--- a/internal/models/template_version.go
+++ b/internal/models/template_version.go
@@ -34,5 +34,6 @@ type TemplateVersion struct {
SampleData string `json:"sample_data"`
CreatedAt time.Time `json:"created_at"`
- StyleSheet *StyleSheet `json:"stylesheet,omitempty" gorm:"foreignKey:StyleSheetID;constraint:OnDelete:SET NULL"`
+ StyleSheet *StyleSheet `json:"stylesheet,omitempty" gorm:"foreignKey:StyleSheetID;constraint:OnDelete:SET NULL"`
+ Localizations []TemplateLocalization `json:"localizations,omitempty" gorm:"foreignKey:VersionID"`
}
diff --git a/internal/storage/repositories/template_version_repo.go b/internal/storage/repositories/template_version_repo.go
index 8603f64..1681bcd 100644
--- a/internal/storage/repositories/template_version_repo.go
+++ b/internal/storage/repositories/template_version_repo.go
@@ -51,7 +51,7 @@ func (r *TemplateVersionRepository) FindByID(id uint) (*models.TemplateVersion,
func (r *TemplateVersionRepository) FindByTemplateID(templateID uint) ([]models.TemplateVersion, error) {
var versions []models.TemplateVersion
- if err := r.db.Preload("StyleSheet").
+ if err := r.db.Preload("StyleSheet").Preload("Localizations").
Where("template_id = ?", templateID).
Order("version DESC").
Find(&versions).Error; err != nil {
diff --git a/web/src/api/types.ts b/web/src/api/types.ts
index aee06c7..f279844 100644
--- a/web/src/api/types.ts
+++ b/web/src/api/types.ts
@@ -166,6 +166,7 @@ export interface TemplateVersion {
version: number
stylesheet_id?: number | null
stylesheet?: StyleSheet | null
+ localizations?: TemplateLocalization[] | null
sample_data: string
created_at: string
}
diff --git a/web/src/views/templates/TemplateDetail.vue b/web/src/views/templates/TemplateDetail.vue
index f122bf8..3ee0770 100644
--- a/web/src/views/templates/TemplateDetail.vue
+++ b/web/src/views/templates/TemplateDetail.vue
@@ -96,7 +96,7 @@ async function loadAll() {
// Auto-select the active version or the first one
if (versions.value.length > 0) {
const active = versions.value.find(v => v.id === template.value?.active_version_id)
- await selectVersion(active || versions.value[0])
+ selectVersion(active || versions.value[0])
}
} catch {
notify.error('Failed to load template')
@@ -105,14 +105,16 @@ async function loadAll() {
}
}
-async function selectVersion(v: TemplateVersion) {
+function selectVersion(v: TemplateVersion) {
selectedVersion.value = v
- try {
- const res = await templatesApi.listLocalizations(templateId, v.id)
- localizations.value = res.data.data || []
- } catch {
- localizations.value = []
- }
+ localizations.value = v.localizations || []
+}
+
+function syncLocalizationsToVersion() {
+ if (!selectedVersion.value) return
+ selectedVersion.value.localizations = [...localizations.value]
+ const idx = versions.value.findIndex(v => v.id === selectedVersion.value!.id)
+ if (idx >= 0) versions.value[idx].localizations = [...localizations.value]
}
async function createVersion() {
@@ -123,7 +125,7 @@ async function createVersion() {
sample_data: template.value?.sample_data || '',
})
versions.value.unshift(res.data.data)
- await selectVersion(res.data.data)
+ selectVersion(res.data.data)
notify.success(`Version ${res.data.data.version} created`)
newVersionStylesheetId.value = null
} catch {
@@ -187,7 +189,7 @@ async function deleteVersion(v: TemplateVersion) {
versions.value = versions.value.filter(x => x.id !== v.id)
if (selectedVersion.value?.id === v.id) {
selectedVersion.value = versions.value[0] || null
- if (selectedVersion.value) await selectVersion(selectedVersion.value)
+ if (selectedVersion.value) selectVersion(selectedVersion.value)
else localizations.value = []
}
notify.success('Version deleted')
@@ -231,6 +233,7 @@ async function saveLoc() {
localizations.value.push(res.data.data)
notify.success('Localization created')
}
+ syncLocalizationsToVersion()
showLocModal.value = false
} catch {
notify.error(editingLoc.value ? 'Failed to update localization' : 'Language already exists for this version')
@@ -250,6 +253,7 @@ async function deleteLoc(l: TemplateLocalization) {
try {
await templatesApi.deleteLocalization(l.id)
localizations.value = localizations.value.filter(x => x.id !== l.id)
+ syncLocalizationsToVersion()
notify.success('Localization deleted')
} catch {
notify.error('Failed to delete localization')
@@ -328,7 +332,9 @@ function openPreview(lang: string) {
previewLang.value = lang
preview.value = null
previewError.value = ''
- if (selectedVersion.value?.sample_data) {
+ if (template.value?.sample_data) {
+ previewData.value = template.value.sample_data
+ } else if (selectedVersion.value?.sample_data) {
previewData.value = selectedVersion.value.sample_data
}
showPreview.value = true