aboutsummaryrefslogtreecommitdiff
path: root/internal/image/service.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/image/service.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/internal/image/service.go b/internal/image/service.go
index f953bfa..4ffd513 100644
--- a/internal/image/service.go
+++ b/internal/image/service.go
@@ -17,7 +17,7 @@ import (
// Servicer image management
type Servicer interface {
NewID() (string, error)
- AddFile(extension, fileType string, fileBytes []byte) (string, string, error)
+ AddFile(extension string, meta *PostMeta, fileBytes []byte) (string, string, error)
GetFile(fileUrl string) (*PostMeta, error)
Render(w http.ResponseWriter, templateName string, data interface{}) error
}
@@ -48,7 +48,7 @@ func (is *Service) NewID() (string, error) {
}
// AddFile writes to disk, writes meta to db
-func (is *Service) AddFile(extension, fileType string, fileBytes []byte) (string, string, error) {
+func (is *Service) AddFile(extension string, postMeta *PostMeta, fileBytes []byte) (string, string, error) {
fileID, err := is.NewID()
if err != nil {
return "", "", errors.Wrap(err, "generated id for fileID failed")
@@ -64,12 +64,8 @@ func (is *Service) AddFile(extension, fileType string, fileBytes []byte) (string
return "", "", errors.Wrap(err, "generating postid for uuid")
}
t := time.Now().UTC()
- postMeta := &PostMeta{
- FilePath: fileName,
- CreatedAt: t.Format(time.RFC3339),
- UserID: "1",
- MimeType: fileType,
- }
+ postMeta.FilePath = fileName
+ postMeta.CreatedAt = t.Format(time.RFC3339)
is.db.AddNewFile(postID, postMeta, 946080000)
if err := is.db.AddNewFile(postID, postMeta, 946080000); err != nil {
log.Fatal(err)
@@ -81,5 +77,7 @@ func (is *Service) AddFile(extension, fileType string, fileBytes []byte) (string
// GetFile fetch file from db interface
func (is *Service) GetFile(fileUrl string) (*PostMeta, error) {
result, err := is.db.GetFile(fileUrl)
+ if err != nil {
+ }
return result, err
}