fix: user can only react one post
All checks were successful
/ Build (push) Successful in 2m28s

This commit is contained in:
log101 2024-05-31 17:45:28 +03:00
parent 93e9cc2617
commit 84547b811a
4 changed files with 14 additions and 5 deletions

1
go.mod
View File

@ -6,6 +6,7 @@ require (
github.com/gin-contrib/cors v1.7.2
github.com/gin-gonic/gin v1.10.0
github.com/go-sql-driver/mysql v1.8.1
github.com/joho/godotenv v1.5.1
)
require (

2
go.sum
View File

@ -35,6 +35,8 @@ github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=

View File

@ -11,6 +11,7 @@ import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/go-sql-driver/mysql"
"github.com/joho/godotenv"
"log101-blog-services/middleware"
)
@ -67,6 +68,11 @@ func countEmojis(postId string) ([]EmojiCount, error) {
}
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
mysqlHost := os.Getenv("DBHOST")
cfg := mysql.Config{
User: os.Getenv("DBUSER"),
@ -75,8 +81,7 @@ func main() {
Addr: mysqlHost + ":3306",
DBName: "emojis",
}
// Get a database handle.
var err error
db, err = sql.Open("mysql", cfg.FormatDSN())
if err != nil {
log.Fatal(err)

View File

@ -5,8 +5,9 @@ USE emojis;
CREATE TABLE IF NOT EXISTS emoji_clicks (
id INT PRIMARY KEY AUTO_INCREMENT,
user_anon_data VARCHAR(50) UNIQUE,
post_id TEXT NOT NULL,
user_anon_data VARCHAR(50),
post_id VARCHAR(50) NOT NULL,
emoji TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE(`post_id`, `user_anon_data`)
);