Merge pull request '💄 Move DELETE logic to specific function' (#16) from ada/backend/refactor-delete into main

Reviewed-on: #16
This commit is contained in:
Ada 2024-01-23 21:28:50 +00:00
commit 07ca9d04f2
2 changed files with 6 additions and 11 deletions

10
db.go
View file

@ -2,9 +2,10 @@ package main
import (
"context"
"github.com/redis/go-redis/v9"
"log"
"time"
"github.com/redis/go-redis/v9"
)
var ctx = context.Background()
@ -43,9 +44,6 @@ func getContent(key string) string {
return db.HGet(ctx, key, "content").Val()
}
func deleteContent(key string) {
err := db.Del(ctx, key)
if err != nil {
log.Println(err)
}
func DeleteContent(key string) {
db.Del(ctx, key)
}

View file

@ -80,11 +80,8 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
case "DELETE":
if UrlExist(path) {
secret := r.URL.Query().Get("secret")
if secret == db.HGet(ctx, path, "secret").Val() {
err := db.Del(ctx, path)
if err != nil {
log.Println(err)
}
if VerifySecret(path, secret) {
DeleteContent(path)
w.WriteHeader(http.StatusNoContent)
} else {
w.WriteHeader(http.StatusForbidden)