diff --git a/backend/go.mod b/backend/go.mod index d0f8e10..f01fbf5 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -6,6 +6,7 @@ require github.com/jackc/pgx/v5 v5.7.2 require ( github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/rs/cors v1.11.1 // indirect golang.org/x/sync v0.10.0 // indirect ) diff --git a/backend/go.sum b/backend/go.sum index 207908e..fb281ca 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -15,6 +15,8 @@ github.com/pashagolub/pgxmock/v4 v4.5.0 h1:l2nGpTiX0Yi62z+I69HOXYXRewkAM19bVYFsp github.com/pashagolub/pgxmock/v4 v4.5.0/go.mod h1:9VoVHXwS3XR/yPtKGzwQvwZX1kzGB9sM8SviDcHDa3A= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA= +github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/backend/http/example.http b/backend/http/example.http index 4bc6366..8236d32 100644 --- a/backend/http/example.http +++ b/backend/http/example.http @@ -55,4 +55,28 @@ DELETE http://localhost:{{PORT}}/users/2 GET http://localhost:{{PORT}}/users ### Delete last user -DELETE http://localhost:{{PORT}}/users/3 \ No newline at end of file +DELETE http://localhost:{{PORT}}/users/3 + + +### Get all notes +GET http://localhost:{{PORT}}/notes + +### Post a note +POST http://localhost:{{PORT}}/notes +Content-Type: "application/json" + +{ + "user_id": 1, + "title": "Test", + "content": "dear diary" +} + + +### Post a box +POST http://localhost:3000/boxes +Content-Type: "application/json" + +{ + "user_id": 1, + "name": "My favorite box" +} \ No newline at end of file diff --git a/backend/middleware/middleware.go b/backend/middleware/middleware.go index 7fc651e..6a7396e 100644 --- a/backend/middleware/middleware.go +++ b/backend/middleware/middleware.go @@ -104,7 +104,7 @@ func NoteValidatorMiddleware(next http.Handler) http.Handler { if contentInter, ok := requestBody["content"]; ok { content := contentInter.(string) - if len(content) < NOTE_CONTENT_MAX_LENGTH { + if len(content) > NOTE_CONTENT_MAX_LENGTH { slog.Error(fmt.Sprintln("content must be at most", NOTE_CONTENT_MAX_LENGTH, "characters long")) http.Error(w, fmt.Sprintln("content must be at most", NOTE_CONTENT_MAX_LENGTH, "characters long"), http.StatusBadRequest) return diff --git a/backend/server.go b/backend/server.go index c2f14e7..fa841b2 100644 --- a/backend/server.go +++ b/backend/server.go @@ -14,6 +14,7 @@ import ( model "github.com/ZBox-Notes/ZBox/backend/models/generated_model" "github.com/gorilla/mux" + "github.com/rs/cors" ) func main() { @@ -47,12 +48,15 @@ func main() { // Add middleware slog.Info("Adding middleware...") + r.Use(middleware.LoggingMiddleware) r.Use(middleware.AuthMiddleware) // Start the server + c := cors.AllowAll() + handler := c.Handler(r) slog.Info("Server started successfully") - http.Handle("/", r) + http.Handle("/", handler) http.ListenAndServe(":3000", nil) } diff --git a/frontend/.env.example b/frontend/.env.example deleted file mode 100644 index 92fa291..0000000 --- a/frontend/.env.example +++ /dev/null @@ -1 +0,0 @@ -REACT_APP_API_BASE_URL=http://127.0.0.1:8000 \ No newline at end of file diff --git a/frontend/.eslintrc.cjs b/frontend/.eslintrc.cjs deleted file mode 100644 index d6c9537..0000000 --- a/frontend/.eslintrc.cjs +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - root: true, - env: { browser: true, es2020: true }, - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:react-hooks/recommended', - ], - ignorePatterns: ['dist', '.eslintrc.cjs'], - parser: '@typescript-eslint/parser', - plugins: ['react-refresh'], - rules: { - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, -} diff --git a/frontend/README.md b/frontend/README.md index 7f229a5..0a446ce 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,13 +1,21 @@ -# React Beginner Course 2024 (Vite, Tailwind CSS, TypeScript) +# React + TypeScript + Vite -This is the project code for my YouTube tutorial: https://www.youtube.com/watch?v=siTUv1L9ymM +This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. -Learn the basics of **React.js** with Tailwind CSS and TypeScript. You will learn: -- How to set up a new React project using Vite -- How to install & use Tailwind CSS in React -- How to think in React -- The difference between declarative and imperative code -- What are components, props, JSX, SPA, unidirectional data flow, callbacks, state, side effects, and more. -- How to build your first app with clean & well-organized code +While this project uses React, Vite supports many popular JS frameworks. [See all the supported frameworks](https://vitejs.dev/guide/#scaffolding-your-first-vite-project). - +## Deploy Your Own + +Deploy your own Vite project with Vercel. + +[](https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/framework-boilerplates/vite-react&template=vite-react) + +_Live Example: https://vite-react-example.vercel.app_ + +### Deploying From Your Terminal + +You can deploy your new Vite project with a single command from your terminal using [Vercel CLI](https://vercel.com/download): + +```shell +$ vercel +``` diff --git a/frontend/components.json b/frontend/components.json new file mode 100644 index 0000000..73afbdb --- /dev/null +++ b/frontend/components.json @@ -0,0 +1,21 @@ +{ + "$schema": "https://ui.shadcn.com/schema.json", + "style": "new-york", + "rsc": false, + "tsx": true, + "tailwind": { + "config": "", + "css": "src/index.css", + "baseColor": "neutral", + "cssVariables": true, + "prefix": "" + }, + "aliases": { + "components": "@/components", + "utils": "@/lib/utils", + "ui": "@/components/ui", + "lib": "@/lib", + "hooks": "@/hooks" + }, + "iconLibrary": "lucide" +} \ No newline at end of file diff --git a/frontend/eslint.config.js b/frontend/eslint.config.js new file mode 100644 index 0000000..092408a --- /dev/null +++ b/frontend/eslint.config.js @@ -0,0 +1,28 @@ +import js from '@eslint/js' +import globals from 'globals' +import reactHooks from 'eslint-plugin-react-hooks' +import reactRefresh from 'eslint-plugin-react-refresh' +import tseslint from 'typescript-eslint' + +export default tseslint.config( + { ignores: ['dist'] }, + { + extends: [js.configs.recommended, ...tseslint.configs.recommended], + files: ['**/*.{ts,tsx}'], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + }, + plugins: { + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + }, + rules: { + ...reactHooks.configs.recommended.rules, + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, + }, +) diff --git a/frontend/index.html b/frontend/index.html index e4b78ea..912eb3f 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,13 +1,20 @@ -
- - - -