going back to how it was
This commit is contained in:
@ -176,6 +176,43 @@ func (h *ImageHandler) deleteImage(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *ImageHandler) reprocessImage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
stringImageID := chi.URLParam(r, "image-id")
|
||||||
|
imageID, err := uuid.Parse(stringImageID)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := r.Context()
|
||||||
|
|
||||||
|
userID, err := middleware.GetUserID(ctx, h.logger, w)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
isAuthorized := h.imageModel.IsUserAuthorized(ctx, imageID, userID)
|
||||||
|
if !isAuthorized {
|
||||||
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
imageToProcessID, err := h.imageModel.GetImageToProcessID(ctx, imageID)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.imageModel.SetNotStarted(ctx, imageToProcessID)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *ImageHandler) CreateRoutes(r chi.Router) {
|
func (h *ImageHandler) CreateRoutes(r chi.Router) {
|
||||||
h.logger.Info("Mounting image router")
|
h.logger.Info("Mounting image router")
|
||||||
|
|
||||||
|
@ -160,6 +160,28 @@ func (m ImageModel) FinishProcessing(ctx context.Context, imageId uuid.UUID) (mo
|
|||||||
return userImage, err
|
return userImage, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m ImageModel) GetImageToProcessID(ctx context.Context, imageID uuid.UUID) (uuid.UUID, error) {
|
||||||
|
getImageToProcessIDStmt := UserImagesToProcess.
|
||||||
|
SELECT(UserImagesToProcess.ID).
|
||||||
|
WHERE(UserImagesToProcess.ImageID.EQ(UUID(imageID)))
|
||||||
|
|
||||||
|
imageToProcess := model.UserImagesToProcess{}
|
||||||
|
err := getImageToProcessIDStmt.QueryContext(ctx, m.dbPool, &imageToProcess)
|
||||||
|
|
||||||
|
return imageToProcess.ID, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m ImageModel) SetNotStarted(ctx context.Context, processingImageId uuid.UUID) error {
|
||||||
|
startProcessingStmt := UserImagesToProcess.
|
||||||
|
UPDATE(UserImagesToProcess.Status).
|
||||||
|
SET(model.Progress_NotStarted).
|
||||||
|
WHERE(UserImagesToProcess.ID.EQ(UUID(processingImageId)))
|
||||||
|
|
||||||
|
_, err := startProcessingStmt.ExecContext(ctx, m.dbPool)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (m ImageModel) StartProcessing(ctx context.Context, processingImageId uuid.UUID) error {
|
func (m ImageModel) StartProcessing(ctx context.Context, processingImageId uuid.UUID) error {
|
||||||
startProcessingStmt := UserImagesToProcess.
|
startProcessingStmt := UserImagesToProcess.
|
||||||
UPDATE(UserImagesToProcess.Status).
|
UPDATE(UserImagesToProcess.Status).
|
||||||
|
Reference in New Issue
Block a user