diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9f9d555 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceRoot}", + "console": "integratedTerminal" + } + + ] +} \ No newline at end of file diff --git a/README.md b/README.md index a672145..013fe6f 100644 --- a/README.md +++ b/README.md @@ -1 +1,17 @@ -# skill-map \ No newline at end of file +# skill-map + + +## Part 1 - Initital setup and server setup +* [YouTube Tutorial Link](https://youtu.be/pHtohACmyj8?si=JwZHSdzFwHd8uAMB) +* [Source Code Link](https://github.com/Buildfromzero/skill-map/tree/v0.0.1) + +## Part 2 - User creation and project structure + +* [YouTube Tutorial Link](https://www.youtube.com/watch?v=Bu3FZobGnHY) +* [Source Code Link](https://github.com/Buildfromzero/skill-map/tree/v0.0.2) + +## Part 3 - User CRUD operations and refctoring + +* [YouTube Tutorial Link](https://www.youtube.com/watch?v=rvFzZmuiR6A) +* [Source Code link](https://github.com/Buildfromzero/skill-map/tree/v0.0.3) + \ No newline at end of file diff --git a/frontend/src/components/createUser.js b/frontend/src/components/createUser.js index 8862dad..2addc12 100644 --- a/frontend/src/components/createUser.js +++ b/frontend/src/components/createUser.js @@ -7,15 +7,15 @@ export default function CreateUser() { console.log(fullName); console.log(email); - fetch("http://localhost:8080/api/users/", { + fetch("http://localhost:8080/api/users", { method: "POST", body: JSON.stringify({ "fullName":fullName, "email":email, }), - headers: { - "Content-type": "application/json; charset=UTF-8", - }, + // headers: { + // "Content-type": "application/json; charset=UTF-8", + // }, }) .then(response => response.json()) .then(data => { diff --git a/frontend/src/components/userlist.js b/frontend/src/components/userlist.js index 8ed63f4..cf7b55d 100644 --- a/frontend/src/components/userlist.js +++ b/frontend/src/components/userlist.js @@ -7,17 +7,14 @@ export default function UserList() { function reloadUserList(event){ console.log(event); - fetch("http://localhost:8080/api/users/", { + fetch("http://localhost:8080/api/users", { method: "GET", - headers: { - "Content-type": "application/json; charset=UTF-8", - }, }) .then(response => response.json()) .then(data => { console.log(data); setData(data); - alert(JSON.stringify(data)); + // alert(JSON.stringify(data)); }) }; diff --git a/go.mod b/go.mod index 7ebbf0d..196ebff 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/buildfromzero/skill-map go 1.21.0 require ( + github.com/gin-gonic/contrib v0.0.0-20221130124618-7e01895a63f2 github.com/gin-gonic/gin v1.9.1 gorm.io/driver/sqlite v1.5.5 gorm.io/gorm v1.25.7 diff --git a/go.sum b/go.sum index d70c72c..011dcb5 100644 --- a/go.sum +++ b/go.sum @@ -17,6 +17,8 @@ github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uq github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/contrib v0.0.0-20221130124618-7e01895a63f2 h1:dyuNlYlG1faymw39NdJddnzJICy6587tiGSVioWhYoE= +github.com/gin-gonic/contrib v0.0.0-20221130124618-7e01895a63f2/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= diff --git a/main.go b/main.go index 077bdc1..00a0039 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "github.com/buildfromzero/skill-map/handlers" "github.com/buildfromzero/skill-map/managers" "github.com/buildfromzero/skill-map/storage" + "github.com/gin-gonic/contrib/cors" "github.com/gin-gonic/gin" ) @@ -18,6 +19,8 @@ func main() { router := gin.Default() + router.Use(cors.Default()) + userManger := managers.NewUserManager() userHandler := handlers.NewUserHandlerFrom(userManger) userHandler.RegisterUserApis(router)