add pdf upload
This commit is contained in:
@@ -74,15 +74,25 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
||||
variantValues := ctx.PostFormArray("variant-value[]")
|
||||
tagIds := ctx.PostFormArray("tags[]")
|
||||
image, err := ctx.FormFile("image")
|
||||
dst := "static/img/zine.jpg"
|
||||
dstImage := "static/img/zine.jpg"
|
||||
|
||||
if err == nil {
|
||||
dst = filepath.Join("static/uploads", image.Filename)
|
||||
if err := ctx.SaveUploadedFile(image, dst); err != nil {
|
||||
dstImage = filepath.Join("static/uploads", image.Filename)
|
||||
if err := ctx.SaveUploadedFile(image, dstImage); err != nil {
|
||||
return models.ShopItem{}, fmt.Errorf("Could not save image")
|
||||
}
|
||||
}
|
||||
|
||||
dstPdf := ""
|
||||
pdf, err := ctx.FormFile("pdf")
|
||||
|
||||
if err == nil {
|
||||
dstPdf = filepath.Join("static/uploads", pdf.Filename)
|
||||
if err := ctx.SaveUploadedFile(pdf, dstPdf); err != nil {
|
||||
return models.ShopItem{}, fmt.Errorf("Could not save PDF")
|
||||
}
|
||||
}
|
||||
|
||||
if name == "" || description == "" {
|
||||
return models.ShopItem{}, fmt.Errorf("Name or description empty")
|
||||
}
|
||||
@@ -124,7 +134,8 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
||||
Description: description,
|
||||
Category: category,
|
||||
IsPublic: true,
|
||||
Image: dst,
|
||||
Image: dstImage,
|
||||
Pdf: dstPdf,
|
||||
Variants: variants,
|
||||
}
|
||||
|
||||
|
||||
@@ -48,4 +48,5 @@ type ShopItem struct {
|
||||
IsPublic bool `json:"isPublic" gorm:"default:true"`
|
||||
Tags []Tag `gorm:"many2many:item_tags;"`
|
||||
Image string
|
||||
Pdf string
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-900">
|
||||
Image
|
||||
@@ -101,6 +100,29 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-900">
|
||||
PDF
|
||||
</label>
|
||||
<div class="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md">
|
||||
<div class="space-y-1 text-center">
|
||||
<svg class="mx-auto h-12 w-12 text-gray-900" stroke="currentColor" fill="none" viewBox="0 0 48 48" aria-hidden="true">
|
||||
<path d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
|
||||
</svg>
|
||||
<div class="flex text-sm text-gray-600">
|
||||
<label for="pdf-upload" class="relative cursor-pointer bg-white rounded-md font-medium text-indigo-600 hover:text-indigo-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-indigo-500">
|
||||
<span class="">Upload a file</span>
|
||||
<input id="pdf-upload" name="pdf" type="file" accept="application/pdf" class="sr-only">
|
||||
</label>
|
||||
<p class="pl-1 text-gray-900">or drag and drop</p>
|
||||
</div>
|
||||
<p class="text-xs text-gray-900">
|
||||
PDF up to 50MB
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="mt-10 text-center text-sm/6 text-red-500">
|
||||
{{ .data.error }}
|
||||
</p>
|
||||
|
||||
@@ -15,13 +15,17 @@
|
||||
<button type="submit" class="w-full bg-gray-900 dark:bg-gray-600 text-white py-2 px-4 rounded-full font-bold hover:bg-gray-800 dark:hover:bg-gray-700">Add to Cart</button>
|
||||
</div>
|
||||
|
||||
<div class="w-1/3 px-2">
|
||||
<a href="/{{ .data.shopItem.Pdf }}"><button type="button" class="w-full bg-blue-900 dark:bg-gray-600 text-white py-2 px-4 rounded-full font-bold hover:bg-gray-800 dark:hover:bg-gray-700">View</button></a>
|
||||
</div>
|
||||
|
||||
{{ if .loggedIn }}
|
||||
<div class="w-1/3 px-2">
|
||||
<a href="{{ .data.shopItem.ID }}/edit"><button class="w-full bg-blue-900 dark:bg-gray-600 text-white py-2 px-4 rounded-full font-bold hover:bg-gray-800 dark:hover:bg-gray-700">Edit</button></a>
|
||||
<a href="{{ .data.shopItem.ID }}/edit"><button type="button" class="w-full bg-blue-900 dark:bg-gray-600 text-white py-2 px-4 rounded-full font-bold hover:bg-gray-800 dark:hover:bg-gray-700">Edit</button></a>
|
||||
</div>
|
||||
|
||||
<div class="w-1/3 px-2">
|
||||
<a href="{{ .data.shopItem.ID }}/delete"><button class="w-full bg-red-900 dark:bg-red-600 text-white py-2 px-4 rounded-full font-bold hover:bg-gray-800 dark:hover:bg-gray-700">Delete</button></a>
|
||||
<a href="{{ .data.shopItem.ID }}/delete"><button type="button" class="w-full bg-red-900 dark:bg-red-600 text-white py-2 px-4 rounded-full font-bold hover:bg-gray-800 dark:hover:bg-gray-700">Delete</button></a>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
{{ .Name }}
|
||||
</a>
|
||||
</h3>
|
||||
<!--<p class="mt-1 text-sm text-gray-500">{{ .Abstract }}</p>-->
|
||||
<p class="mt-1 text-sm text-gray-500">{{ .Abstract }}</p>
|
||||
<p class="mt-1 text-sm text-gray-500">{{ range .Tags }}{{ .Name }} {{ end }}</p>
|
||||
</div>
|
||||
<p class="text-sm font-medium text-gray-900">{{ .BasePrice }}€</p>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user