-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: image deletion endpoint * feat: prevent renaming to the same file name * feat: add function to delete file * refactor: using function to delete file * refactor: using function to delete file and improving flow * refactor: code format * feat: add function to validate rename input * refactor: using function that validate input rename * feat: add function to rename file * refactor: using the function to rename file * refactor: using function to rename file and add filter to new name file * refactor: format
- Loading branch information
1 parent
24f5dd6
commit af83c26
Showing
10 changed files
with
101 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func DeleteFile(deletedFileName string, fileType string) error { | ||
filePath := fmt.Sprintf("%v/uploads/%v/%v", ExPath, fileType, deletedFileName) | ||
|
||
err := os.Remove(filePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func RenameFile(oldName, newName, fileType string) error { | ||
prefix := filepath.Join(ExPath, "uploads", fileType) | ||
|
||
err := os.Rename( | ||
filepath.Join(prefix, oldName), | ||
filepath.Join(prefix, newName), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package validations | ||
|
||
import "errors" | ||
|
||
func ValidateRenameInput(oldName, newName string) error { | ||
if oldName == "" || newName == "" { | ||
return errors.New("'oldName' and 'newName' are required") | ||
} | ||
|
||
if oldName == newName { | ||
return errors.New("New name must be different from the old name") | ||
} | ||
|
||
return nil | ||
} |