diff --git a/enshi/src/App.tsx b/enshi/src/App.tsx
index 3c7c153..8d115e6 100644
--- a/enshi/src/App.tsx
+++ b/enshi/src/App.tsx
@@ -1,53 +1,20 @@
import "./App.css";
import "@radix-ui/themes/styles.css";
import {
- Badge,
- Button,
- Callout,
- Container,
- Flex,
- Separator,
- Text,
Theme,
ThemePanel,
} from "@radix-ui/themes";
import {
- Router,
- Route,
createBrowserRouter,
- createRoutesFromElements,
RouterProvider,
- Routes,
- useRouteError,
} from "react-router-dom";
-import MainPage from "./Pages/MainPage/MainPage";
import { QueryClientProvider } from "@tanstack/react-query";
import queryClient from "./api/QueryClient/QueryClient";
-
-function ErrorBoundary() {
- let error = useRouteError();
- console.error(error);
-
- return
Dang! This route does not exist... Yet ;)
;
-}
+import { routes } from "./routes/routes";
const router = createBrowserRouter(
- createRoutesFromElements(
- <>
- }
- element={}
- >
- Cringer path} />
- Cringer path, but this a}
- >
-
- >
- )
+ routes
);
export default function App() {
diff --git a/enshi/src/Components/NavBar/NavBar.tsx b/enshi/src/Components/NavBar/NavBar.tsx
index 3b90027..9e956a8 100644
--- a/enshi/src/Components/NavBar/NavBar.tsx
+++ b/enshi/src/Components/NavBar/NavBar.tsx
@@ -1,4 +1,4 @@
-import { Button, Text } from "@radix-ui/themes";
+import { Button, Card, ChevronDownIcon, Text } from "@radix-ui/themes";
import * as NavigationMenu from "@radix-ui/react-navigation-menu";
import { Link, useLocation, useNavigate } from "react-router-dom";
@@ -10,10 +10,31 @@ export default function NavBar() {
className="flex justify-center"
>
-
+
-
+
+
+
+
+
+
+
+ asd
+
+
@@ -26,26 +47,20 @@ type TNavItem = {
};
function NavItem(props: TNavItem) {
-
- const navigate = useNavigate()
- const location = useLocation()
-
- console.log(location);
-
+ const navigate = useNavigate();
+ const location = useLocation();
return (
-
+
);
diff --git a/enshi/src/routes/routes.ts b/enshi/src/routes/routes.ts
deleted file mode 100644
index e69de29..0000000
diff --git a/enshi/src/routes/routes.tsx b/enshi/src/routes/routes.tsx
new file mode 100644
index 0000000..153236e
--- /dev/null
+++ b/enshi/src/routes/routes.tsx
@@ -0,0 +1,27 @@
+import { createRoutesFromElements, Route, useRouteError } from "react-router-dom"
+import MainPage from "../Pages/MainPage/MainPage"
+import {Text} from "@radix-ui/themes";
+
+
+function ErrorBoundary() {
+ let error = useRouteError();
+ console.error(error);
+
+ return Dang! This route does not exist... Yet ;)
;
+}
+
+export const routes = createRoutesFromElements(
+ <>
+ }
+ element={}
+ >
+ Cringer path} />
+ Cringer path, but this a}
+ >
+
+ >
+)
\ No newline at end of file
diff --git a/enshi/tailwind.config.js b/enshi/tailwind.config.js
index 980aeb2..76881c2 100644
--- a/enshi/tailwind.config.js
+++ b/enshi/tailwind.config.js
@@ -5,7 +5,16 @@ content: [
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
- extend: {},
+ extend: {
+ animation: {
+ 'appear': 'appear 0.25s'
+ },
+ keyframes: {
+ appear: {
+ '100%': {opacity: '1'}
+ }
+ }
+ },
},
plugins: [],
}
diff --git a/enshi_back/db/go_queries/favorites_queries.sql.go b/enshi_back/db/go_queries/favorites_queries.sql.go
new file mode 100644
index 0000000..260bb15
--- /dev/null
+++ b/enshi_back/db/go_queries/favorites_queries.sql.go
@@ -0,0 +1,44 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.27.0
+// source: favorites_queries.sql
+
+package db_repo
+
+import (
+ "context"
+)
+
+const createFavorite = `-- name: CreateFavorite :one
+INSERT INTO public.favorites
+(user_id, blog_id, favorited_at)
+VALUES($1, $2, CURRENT_TIMESTAMP)
+RETURNING user_id, blog_id, favorited_at
+`
+
+type CreateFavoriteParams struct {
+ UserID int64 `json:"user_id"`
+ BlogID int64 `json:"blog_id"`
+}
+
+func (q *Queries) CreateFavorite(ctx context.Context, arg CreateFavoriteParams) (Favorite, error) {
+ row := q.db.QueryRow(ctx, createFavorite, arg.UserID, arg.BlogID)
+ var i Favorite
+ err := row.Scan(&i.UserID, &i.BlogID, &i.FavoritedAt)
+ return i, err
+}
+
+const deleteFavorite = `-- name: DeleteFavorite :exec
+DELETE FROM public.favorites
+WHERE user_id=$1 AND blog_id=$2
+`
+
+type DeleteFavoriteParams struct {
+ UserID int64 `json:"user_id"`
+ BlogID int64 `json:"blog_id"`
+}
+
+func (q *Queries) DeleteFavorite(ctx context.Context, arg DeleteFavoriteParams) error {
+ _, err := q.db.Exec(ctx, deleteFavorite, arg.UserID, arg.BlogID)
+ return err
+}
diff --git a/enshi_back/db/go_queries/multi_queries.sql.go b/enshi_back/db/go_queries/multi_queries.sql.go
new file mode 100644
index 0000000..d86e2c2
--- /dev/null
+++ b/enshi_back/db/go_queries/multi_queries.sql.go
@@ -0,0 +1,48 @@
+// Code generated by sqlc. DO NOT EDIT.
+// versions:
+// sqlc v1.27.0
+// source: multi_queries.sql
+
+package db_repo
+
+import (
+ "context"
+)
+
+const getFavoriteBlogsInfosByUserId = `-- name: GetFavoriteBlogsInfosByUserId :many
+SELECT blogs.blog_id, blogs.user_id, blogs.title, blogs.description, blogs.category_id, blogs.created_at
+FROM favorites
+JOIN blogs on blogs.blog_id = favorites.blog_id
+WHERE favorites.user_id = $1
+`
+
+type GetFavoriteBlogsInfosByUserIdRow struct {
+ Blog Blog `json:"blog"`
+}
+
+func (q *Queries) GetFavoriteBlogsInfosByUserId(ctx context.Context, userID int64) ([]GetFavoriteBlogsInfosByUserIdRow, error) {
+ rows, err := q.db.Query(ctx, getFavoriteBlogsInfosByUserId, userID)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+ var items []GetFavoriteBlogsInfosByUserIdRow
+ for rows.Next() {
+ var i GetFavoriteBlogsInfosByUserIdRow
+ if err := rows.Scan(
+ &i.Blog.BlogID,
+ &i.Blog.UserID,
+ &i.Blog.Title,
+ &i.Blog.Description,
+ &i.Blog.CategoryID,
+ &i.Blog.CreatedAt,
+ ); err != nil {
+ return nil, err
+ }
+ items = append(items, i)
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return items, nil
+}
diff --git a/enshi_back/db/migrations/migration1.sql b/enshi_back/db/migrations/migration1.sql
index dde819d..0414b09 100644
--- a/enshi_back/db/migrations/migration1.sql
+++ b/enshi_back/db/migrations/migration1.sql
@@ -25,4 +25,6 @@ CREATE TABLE "public"."post_tags" ("post_id" bigint NOT NULL, "tag_id" integer N
-- Create "post_votes" table
CREATE TABLE "public"."post_votes" ("post_id" bigint NOT NULL, "user_id" bigint NOT NULL, "vote" boolean NOT NULL, PRIMARY KEY ("post_id", "user_id"), CONSTRAINT "post_votes_post_id_fkey" FOREIGN KEY ("post_id") REFERENCES "public"."posts" ("post_id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "post_votes_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("user_id") ON UPDATE NO ACTION ON DELETE NO ACTION);
-- Create "profiles" table
-CREATE TABLE "public"."profiles" ("profile_id" bigint NOT NULL, "user_id" bigint NULL, "bio" text NULL, "avatar_url" character varying(255) NULL, "website_url" character varying(100) NULL, PRIMARY KEY ("profile_id"), CONSTRAINT "profiles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("user_id") ON UPDATE NO ACTION ON DELETE CASCADE);
+CREATE TABLE "public"."profiles" ("profile_id" bigint NOT NULL, "user_id" bigint NOT NULL, "bio" text NULL, "avatar_url" character varying(255) NULL, "website_url" character varying(100) NULL, PRIMARY KEY ("profile_id"), CONSTRAINT "profiles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("user_id") ON UPDATE NO ACTION ON DELETE CASCADE);
+-- Create index "profiles_user_id_idx" to table: "profiles"
+CREATE UNIQUE INDEX "profiles_user_id_idx" ON "public"."profiles" ("user_id");
diff --git a/enshi_back/db/queries/favorites_queries.sql b/enshi_back/db/queries/favorites_queries.sql
new file mode 100644
index 0000000..0a7e6b1
--- /dev/null
+++ b/enshi_back/db/queries/favorites_queries.sql
@@ -0,0 +1,9 @@
+-- name: CreateFavorite :one
+INSERT INTO public.favorites
+(user_id, blog_id, favorited_at)
+VALUES($1, $2, CURRENT_TIMESTAMP)
+RETURNING *;
+
+-- name: DeleteFavorite :exec
+DELETE FROM public.favorites
+WHERE user_id=$1 AND blog_id=$2;
\ No newline at end of file
diff --git a/enshi_back/db/queries/multi_queries.sql b/enshi_back/db/queries/multi_queries.sql
new file mode 100644
index 0000000..c898157
--- /dev/null
+++ b/enshi_back/db/queries/multi_queries.sql
@@ -0,0 +1,6 @@
+-- name: GetFavoriteBlogsInfosByUserId :many
+SELECT sqlc.embed(blogs)
+FROM favorites
+JOIN blogs on blogs.blog_id = favorites.blog_id
+WHERE favorites.user_id = $1;
+
diff --git a/enshi_back/main.go b/enshi_back/main.go
index f6d08e8..441611a 100644
--- a/enshi_back/main.go
+++ b/enshi_back/main.go
@@ -30,7 +30,7 @@ func main() {
}
// Transaction
- tx, _ := utils.Dbx_connection.Begin(context.Background())
+ tx, _ := utils.Dbx.Begin(context.Background())
defer tx.Rollback(context.Background())
repo := db_repo.New(tx)
diff --git a/enshi_back/utils/passwordHashing.go b/enshi_back/utils/passwordHashing.go
index 2e4705d..df7ebbc 100644
--- a/enshi_back/utils/passwordHashing.go
+++ b/enshi_back/utils/passwordHashing.go
@@ -20,9 +20,9 @@ type Argon2Hash struct {
}
type HashSalt struct {
- hash []byte
+ Hash []byte
salt []byte
- stringToStore string
+ StringToStore string
}
// Initializer for algorithm
@@ -75,7 +75,7 @@ func (a *Argon2Hash) HashGen(password, salt []byte) (*HashSalt, error) {
stringToStore := fmt.Sprintf("$m=%d,t=%d$%s$%s", a.memory, a.time, saltDecoded, hashDecoded)
// This is unnecessary structure i created following the guide 0_0
- return &HashSalt{hash: hash, salt: salt, stringToStore: stringToStore}, nil
+ return &HashSalt{Hash: hash, salt: salt, StringToStore: stringToStore}, nil
}
@@ -91,7 +91,7 @@ func (a *Argon2Hash) Compare(hash, salt, password []byte) error {
}
// Comparing hashes
- if !bytes.Equal(hash, hashSalt.hash) {
+ if !bytes.Equal(hash, hashSalt.Hash) {
return fmt.Errorf("invalid password (hashes does not match)")
}
@@ -153,6 +153,6 @@ func Test() {
}
// fmt.Println(testDbString)
- fmt.Printf("%s", cringe.stringToStore)
+ fmt.Printf("%s", cringe.StringToStore)
fmt.Print("\n\n\n\n")
}
diff --git a/enshi_back/utils/routesSetup.go b/enshi_back/utils/routesSetup.go
index eca6a32..b1c9305 100644
--- a/enshi_back/utils/routesSetup.go
+++ b/enshi_back/utils/routesSetup.go
@@ -206,7 +206,7 @@ func registerUser(c *gin.Context) {
rowsToClose, errr := Dbx.Query(context.Background(), "INSERT INTO users "+
"(user_id, username, user_name, user_password) "+
- "VALUES($1, $2, $3, $4);", newUuid, body.Username, body.Name, hashedPassword.stringToStore)
+ "VALUES($1, $2, $3, $4);", newUuid, body.Username, body.Name, hashedPassword.StringToStore)
if errr != nil {
c.IndentedJSON(http.StatusInternalServerError, gin.H{"error": errr.Error()})