From ae37039556ea59cd1771db027a57353385e0569c Mon Sep 17 00:00:00 2001 From: monastyr Date: Sun, 18 Nov 2018 23:42:18 +0100 Subject: [PATCH] =?UTF-8?q?bez=20po=C5=82acznia=20vue=20z=20backendem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/go_proto_buffer/main.go | 9 +++ backend/go_proto_buffer/person.json | 2 +- backend/go_proto_buffer/person.proto | 8 ++ backend/golang-gin/main.go | 81 +++++++++++++++++++++ backend/golang-gin/views/app.jsx | 0 backend/golang-gin/views/index.html | 21 ++++++ couchdb_cheat_sheet.txt | 0 frontend/app/config/index.js | 19 ++++- frontend/app/package-lock.json | 17 +++-- frontend/app/package.json | 1 + frontend/app/src/App.vue | 20 ++++- frontend/app/src/components/SidenavMenu.vue | 1 - todo.txt | 0 13 files changed, 167 insertions(+), 12 deletions(-) create mode 100644 backend/go_proto_buffer/person.proto create mode 100644 backend/golang-gin/main.go create mode 100644 backend/golang-gin/views/app.jsx create mode 100644 backend/golang-gin/views/index.html create mode 100644 couchdb_cheat_sheet.txt create mode 100644 todo.txt diff --git a/backend/go_proto_buffer/main.go b/backend/go_proto_buffer/main.go index 8f3de03..e83c3da 100644 --- a/backend/go_proto_buffer/main.go +++ b/backend/go_proto_buffer/main.go @@ -5,6 +5,15 @@ package main // go get github.com/golang/protobuf //[!] błąd [!] can't load package: package github.com/golang/protobuf: no Go files in C:\Users\dp\go\src\github.com\golang\protobuf //go get github.com/golang/protobuf/proto + +//https://github.com/golang/protobuf +//go get -u github.com/golang/protobuf/protoc-gen-go dziala +//The compiler plugin, protoc-gen-go, will be installed in $GOBIN, +//defaulting to $GOPATH/bin. It must be in your $PATH for the protocol compiler, protoc, to find it. + +//protoc +// 'protoc' is not recognized as an internal or external command, +// operable program or batch file. import "fmt" func main() { diff --git a/backend/go_proto_buffer/person.json b/backend/go_proto_buffer/person.json index efa94fe..a3d2971 100644 --- a/backend/go_proto_buffer/person.json +++ b/backend/go_proto_buffer/person.json @@ -1,4 +1,4 @@ { - "name": "elliot", + "name": "Elliot", "age": 24 } \ No newline at end of file diff --git a/backend/go_proto_buffer/person.proto b/backend/go_proto_buffer/person.proto new file mode 100644 index 0000000..3b3b036 --- /dev/null +++ b/backend/go_proto_buffer/person.proto @@ -0,0 +1,8 @@ +syntax="proto3" + +package main; + +message Person { + string name =1; + int32 age = 2; +} \ No newline at end of file diff --git a/backend/golang-gin/main.go b/backend/golang-gin/main.go new file mode 100644 index 0000000..29e3429 --- /dev/null +++ b/backend/golang-gin/main.go @@ -0,0 +1,81 @@ +package main + +// go get -u github.com/gin-gonic/gin +// go get -u github.com/gin-gonic/contrib/static +// go get "github.com/gin-gonic/contrib/static" +// go get "github.com/gin-gonic/gin" + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/contrib/static" + "github.com/gin-gonic/gin" +) + +// Let's create our Jokes struct. This will contain information about a Joke + +// Joke contains information about a single Joke +type Joke struct { + ID int `json:"id" binding:"required"` + Likes int `json:"likes"` + Joke string `json:"joke" binding:"required"` +} + +// We'll create a list of jokes +var jokes = []Joke{ + Joke{0, 0, "How does a penguin build it's house? Igloos it together."}, + Joke{1, 0, "Did you hear about the restaurant on the moon? Great food, no atmosphere."}, + Joke{2, 0, "What do you call a fake noodle? An Impasta."}, + Joke{3, 0, "How many apples grow on a tree? All of them."}, + Joke{4, 0, "Want to hear a joke about paper? Nevermind it's tearable."}, + Joke{5, 0, "I just watched a program about beavers. It was the best dam program I've ever seen."}, + Joke{6, 0, "Why did the coffee file a police report? It got mugged."}, +} + +func main() { + // Set the router as the default one shipped with Gin + router := gin.Default() + + // Serve frontend static files + router.Use(static.Serve("/", static.LocalFile("./views", true))) + + // Setup route group for the API + api := router.Group("/api") + { + api.GET("/", func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "message": "pong", + }) + }) + } + + // Our API will consit of just two routes + // /jokes - which will retrieve a list of jokes a user can see + // /jokes/like/:jokeID - which will capture likes sent to a particular joke + api.GET("/jokes", JokeHandler) + api.POST("/jokes/like/:jokeID", LikeJoke) + + // Start and run the server + router.Run(":3000") +} + +// JokeHandler retrieves a list of available jokes +func JokeHandler(c *gin.Context) { + c.Header("Content-Type", "application/json") + c.JSON(http.StatusOK, jokes) +} + +// LikeJoke increments the likes of a particular joke Item +func LikeJoke(c *gin.Context) { + // confirm Joke ID sent is valid + // remember to import the `strconv` package + //jokeid - wartosc z url'a + if jokeid, err := strconv.Atoi(c.Param("jokeID")); err == nil { + // return a pointer to the updated jokes list + c.JSON(http.StatusOK, &jokes[jokeid]) + } else { + // Joke ID is invalid + c.AbortWithStatus(http.StatusNotFound) + } +} diff --git a/backend/golang-gin/views/app.jsx b/backend/golang-gin/views/app.jsx new file mode 100644 index 0000000..e69de29 diff --git a/backend/golang-gin/views/index.html b/backend/golang-gin/views/index.html new file mode 100644 index 0000000..41b7749 --- /dev/null +++ b/backend/golang-gin/views/index.html @@ -0,0 +1,21 @@ + + + + + + + Jokeish App + + + + + + + + + + +
+ + + \ No newline at end of file diff --git a/couchdb_cheat_sheet.txt b/couchdb_cheat_sheet.txt new file mode 100644 index 0000000..e69de29 diff --git a/frontend/app/config/index.js b/frontend/app/config/index.js index 926ab36..52f75d6 100644 --- a/frontend/app/config/index.js +++ b/frontend/app/config/index.js @@ -6,15 +6,28 @@ const path = require('path') module.exports = { dev: { - // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', - proxyTable: {}, + proxyTable: { + '/api': { + target: 'http://localhost:3000', + changeOrigin: true + }, + }, + devServer: { + proxy: { + "/api/*": { + target: "http://localhost:3000", + secure: false, + pathRewrite: { '^/api': '' } + } + } + }, // Various Dev Server settings host: 'localhost', // can be overwritten by process.env.HOST - port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined + port: 3000, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined autoOpenBrowser: false, errorOverlay: true, notifyOnErrors: true, diff --git a/frontend/app/package-lock.json b/frontend/app/package-lock.json index af37874..c6f7819 100644 --- a/frontend/app/package-lock.json +++ b/frontend/app/package-lock.json @@ -876,6 +876,15 @@ "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==", "dev": true }, + "axios": { + "version": "0.18.0", + "resolved": "http://registry.npmjs.org/axios/-/axios-0.18.0.tgz", + "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", + "requires": { + "follow-redirects": "^1.3.0", + "is-buffer": "^1.1.5" + } + }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -5078,7 +5087,6 @@ "version": "1.5.9", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.9.tgz", "integrity": "sha512-Bh65EZI/RU8nx0wbYF9shkFZlqLP+6WT/5FnA3cE/djNSuKNHJEinGGZgu/cQEkeeb2GdFOgenAmn8qaqYke2w==", - "dev": true, "requires": { "debug": "=3.1.0" }, @@ -5087,7 +5095,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, "requires": { "ms": "2.0.0" } @@ -6591,8 +6598,7 @@ "is-buffer": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", - "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", - "dev": true + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==" }, "is-builtin-module": { "version": "1.0.0", @@ -8399,8 +8405,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "multicast-dns": { "version": "6.2.3", diff --git a/frontend/app/package.json b/frontend/app/package.json index 7ce6e48..984b0c6 100644 --- a/frontend/app/package.json +++ b/frontend/app/package.json @@ -14,6 +14,7 @@ "build": "node build/build.js" }, "dependencies": { + "axios": "^0.18.0", "bootstrap-vue": "^2.0.0-rc.11", "vue": "^2.5.2", "vue-router": "^3.0.1", diff --git a/frontend/app/src/App.vue b/frontend/app/src/App.vue index 42fe887..5d74f4f 100644 --- a/frontend/app/src/App.vue +++ b/frontend/app/src/App.vue @@ -5,9 +5,27 @@ diff --git a/frontend/app/src/components/SidenavMenu.vue b/frontend/app/src/components/SidenavMenu.vue index 12163e6..f84dbf8 100644 --- a/frontend/app/src/components/SidenavMenu.vue +++ b/frontend/app/src/components/SidenavMenu.vue @@ -26,7 +26,6 @@