Mostly just function signatures at the moment Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"git.ewellenr.ca/receipt_indexer/backend/internal/storage"
|
|
)
|
|
|
|
func (app *application) getImage(ctx context.Context, imageID int64) (*storage.Image, error) {
|
|
if !app.config.redisCfg.enabled {
|
|
return app.store.Images.GetByID(ctx, imageID)
|
|
}
|
|
|
|
image, err := app.cacheStorage.ReceiptImage.Get(ctx, imageID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if image == nil {
|
|
image, err = app.store.Images.GetByID(ctx, imageID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := app.cacheStorage.ReceiptImage.Set(ctx, image); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return image, nil
|
|
}
|
|
|
|
func (app *application) addImageHandler(w http.ResponseWriter, r *http.Request) {
|
|
// create a new image, add it to the receipt. this should be a function because it should be one whole transaction
|
|
|
|
// it should be do the database transaction, attempt the upload, and then abort/commit the transaction depending on the results of the upload. While uploading directly to the s3/minio would be good, it doesn't provide the transactionality that is required
|
|
}
|
|
|
|
func (app *application) deleteImageHandler(w http.ResponseWriter, r *http.Request) {
|
|
// delete image and remove from cache
|
|
|
|
// this also needs to be transactional first the database transaction stuff, then attempt the delete, and then abort/commit the transaction depending on the results of the upload.
|
|
}
|