cors support, admin panel

This commit is contained in:
PawelJa 2019-01-07 23:16:26 +01:00
parent e45dc87655
commit 76914dcfd3
60 changed files with 1729 additions and 557 deletions

View File

@ -2,13 +2,26 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="baac0fea-ba77-4412-8e4a-c4ee1e16e324" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/calendar/controller.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/dbConfig/config.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/booking.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/calendarController.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/calendar/controller.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/dbConfig/config.go" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/router/routes.go" beforeDir="false" afterPath="$PROJECT_DIR$/router/routes.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/controller.go" beforeDir="false" afterPath="$PROJECT_DIR$/test/controller.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/router/router.go" beforeDir="false" afterPath="$PROJECT_DIR$/router.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/router/routes.go" beforeDir="false" afterPath="$PROJECT_DIR$/routes.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/package-lock.json" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/package-lock.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/app.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/app.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/app.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/app.module.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/app.router.module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/app.router.module.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/add-terms/add-terms.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/add-terms/add-terms.component.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/components/add-terms/add-terms.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/components/add-terms/add-terms.component.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/app/services/term.service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/app/services/term.service.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/environments/environment.ts" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/environments/environment.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt-visio-app/src/styles.css" beforeDir="false" afterPath="$PROJECT_DIR$/szt-visio-app/src/styles.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/szt_visio.exe" beforeDir="false" afterPath="$PROJECT_DIR$/szt_visio.exe" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/controller.go" beforeDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@ -50,32 +63,33 @@
<session id="2110107836">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="4" />
<entry key="project.closed" value="9" />
<entry key="project.open.time.1" value="1" />
<entry key="project.open.time.10" value="1" />
<entry key="project.open.time.10" value="4" />
<entry key="project.open.time.13" value="1" />
<entry key="project.open.time.14" value="1" />
<entry key="project.opened" value="4" />
<entry key="project.open.time.9" value="2" />
<entry key="project.opened" value="9" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="go" value="4248" />
<entry key="go" value="8964" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="Go" value="4248" />
<entry key="Go" value="8964" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="go" value="11" />
<entry key="go" value="35" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="Go" value="11" />
<entry key="Go" value="35" />
</counts>
</usages-collector>
<usages-collector id="statistics.go.postfix.template.usages.trigger">
@ -90,26 +104,47 @@
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="24">
<caret line="173" column="81" selection-start-line="173" selection-start-column="81" selection-end-line="173" selection-end-column="81" />
<state relative-caret-position="238">
<caret line="14" column="88" selection-start-line="14" selection-start-column="88" selection-end-line="14" selection-end-column="88" />
<folding>
<element signature="e#14#71#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/dbConfig/config.go">
<entry file="file://$PROJECT_DIR$/dbConnector.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="15" column="23" selection-start-line="15" selection-start-column="23" selection-end-line="15" selection-end-column="23" />
<state relative-caret-position="357">
<caret line="24" column="19" selection-start-line="24" selection-start-column="19" selection-end-line="24" selection-end-column="19" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/controller.go">
<entry file="file://$PROJECT_DIR$/routes.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="14" column="1" selection-start-line="14" selection-start-column="1" selection-end-line="14" selection-end-column="1" />
<state relative-caret-position="221">
<caret line="15" column="20" selection-start-line="15" selection-start-column="20" selection-end-line="15" selection-end-column="20" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/calendarController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2244">
<caret line="139" column="48" selection-start-line="139" selection-start-column="48" selection-end-line="139" selection-end-column="48" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/models.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="473">
<caret line="31" column="1" selection-start-line="31" selection-start-column="1" selection-end-line="31" selection-end-column="1" />
</state>
</provider>
</entry>
@ -123,6 +158,11 @@
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>repo</find>
</findStrings>
</component>
<component name="GOROOT" path="C:\Go" />
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@ -133,12 +173,19 @@
<option value="$PROJECT_DIR$/controller.go" />
<option value="$PROJECT_DIR$/logger.go" />
<option value="$PROJECT_DIR$/router.go" />
<option value="$PROJECT_DIR$/routes.go" />
<option value="$PROJECT_DIR$/router/router.go" />
<option value="$PROJECT_DIR$/router/routes.go" />
<option value="$PROJECT_DIR$/calendar/controller.go" />
<option value="$PROJECT_DIR$/test/controller.go" />
<option value="$PROJECT_DIR$/dbConfig/config.go" />
<option value="$PROJECT_DIR$/dbConnector.go" />
<option value="$PROJECT_DIR$/router/routes.go" />
<option value="$PROJECT_DIR$/alghoritms.go" />
<option value="$PROJECT_DIR$/proba.go" />
<option value="$PROJECT_DIR$/queriesController.go" />
<option value="$PROJECT_DIR$/models.go" />
<option value="$PROJECT_DIR$/booking.go" />
<option value="$PROJECT_DIR$/routes.go" />
<option value="$PROJECT_DIR$/calendarController.go" />
<option value="$PROJECT_DIR$/main.go" />
</list>
</option>
@ -176,21 +223,6 @@
<item name="szt_visio" type="b2602c69:ProjectViewProjectNode" />
<item name="szt_visio" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="szt_visio" type="b2602c69:ProjectViewProjectNode" />
<item name="szt_visio" type="462c0819:PsiDirectoryNode" />
<item name="dbConfig" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="szt_visio" type="b2602c69:ProjectViewProjectNode" />
<item name="szt_visio" type="462c0819:PsiDirectoryNode" />
<item name="router" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="szt_visio" type="b2602c69:ProjectViewProjectNode" />
<item name="szt_visio" type="462c0819:PsiDirectoryNode" />
<item name="test" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="szt_visio" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
@ -216,10 +248,11 @@
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\pawel\go\szt_visio" />
<recent name="C:\Users\pawel\go\szt_visio\calendar" />
<recent name="C:\Users\pawel\go\simpleREST\logger" />
<recent name="C:\Users\pawel\go\simpleREST\router" />
<recent name="C:\Users\pawel\go\simpleREST\test" />
<recent name="C:\Users\pawel\go\simpleREST\Test" />
</key>
</component>
<component name="RunDashboard">
@ -252,7 +285,7 @@
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.26865673" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.2835821" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
@ -286,45 +319,79 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/calendar/controller.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
<caret line="5" selection-start-line="5" selection-end-line="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/router/routes.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255">
<caret line="15" column="19" selection-start-line="15" selection-start-column="19" selection-end-line="15" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/router/router.go">
<entry file="file://$PROJECT_DIR$/dbConfig/config.go" />
<entry file="file://$PROJECT_DIR$/router.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="34">
<caret line="2" selection-start-line="2" selection-end-line="2" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/calendar/controller.go" />
<entry file="file://$PROJECT_DIR$/test/controller.go" />
<entry file="file://$PROJECT_DIR$/proba.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="694">
<caret line="42" column="9" lean-forward="true" selection-start-line="42" selection-start-column="9" selection-end-line="42" selection-end-column="9" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/queriesController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="26" column="68" selection-start-line="26" selection-start-column="68" selection-end-line="26" selection-end-column="68" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/alghoritms.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="17" column="5" selection-start-line="17" selection-start-column="5" selection-end-line="17" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/models.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="473">
<caret line="31" column="1" selection-start-line="31" selection-start-column="1" selection-end-line="31" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/booking.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-666">
<caret line="87" column="29" selection-start-line="87" selection-start-column="29" selection-end-line="87" selection-end-column="29" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/dbConnector.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="24" column="19" selection-start-line="24" selection-start-column="19" selection-end-line="24" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/routes.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="221">
<caret line="15" column="20" selection-start-line="15" selection-start-column="20" selection-end-line="15" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/calendarController.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2244">
<caret line="139" column="48" selection-start-line="139" selection-start-column="48" selection-end-line="139" selection-end-column="48" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="24">
<caret line="173" column="81" selection-start-line="173" selection-start-column="81" selection-end-line="173" selection-end-column="81" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/dbConfig/config.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="15" column="23" selection-start-line="15" selection-start-column="23" selection-end-line="15" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/controller.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="14" column="1" selection-start-line="14" selection-start-column="1" selection-end-line="14" selection-end-column="1" />
<state relative-caret-position="238">
<caret line="14" column="88" selection-start-line="14" selection-start-column="88" selection-end-line="14" selection-end-column="88" />
<folding>
<element signature="e#14#71#0" expanded="true" />
</folding>
</state>
</provider>
</entry>

19
alghoritms.go Normal file
View File

@ -0,0 +1,19 @@
package main
import (
"fmt"
"strconv"
"time"
)
func daysIn(m int, year int) {
var data string
dni := time.Date(year, time.Month(m+1),0,0,0,0,0,time.UTC)
for i := 1; i <= dni.Day(); i++ {
data = strconv.Itoa(year) + "-" + strconv.Itoa(int(m)) + "-" + strconv.Itoa(i)
fmt.Println("data: ", data)
addRow(data)
}
}

155
booking.go Normal file
View File

@ -0,0 +1,155 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func newBooking(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
}
log.Println(string(body))
var term Term
err = json.Unmarshal(body, &term)
if err != nil {
panic(err)
}
fmt.Println(term)
{
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
defer tx.Rollback()
stmt, err := tx.Prepare("INSERT INTO contracts (date, status, contractno) VALUES ( $1, $2, $3);")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
for i := 0; i < 1; i++ {
_, err = stmt.Exec(term.Date, term.Status, term.Contractno)
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
}
err = tx.Commit()
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
}
{
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
defer tx.Rollback()
stmt, err := tx.Prepare("UPDATE calendar SET status=$1, contractno=$2 WHERE date=$3;")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
for i := 0; i < 1; i++ {
_, err = stmt.Exec(term.Status, term.Contractno, term.Date)
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
}
err = tx.Commit()
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
}
return
}
func delBooking(w http.ResponseWriter, req *http.Request) {
enableCorsDelete(&w)
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
}
log.Println(string(body))
var term Term
err = json.Unmarshal(body, &term)
if err != nil {
panic(err)
}
fmt.Println(term)
{
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
defer tx.Rollback()
stmt, err := tx.Prepare("DELETE FROM contracts WHERE date=$1;")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
for i := 0; i < 1; i++ {
_, err = stmt.Exec(term.Date)
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
}
err = tx.Commit()
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
}
{
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
defer tx.Rollback()
stmt, err := tx.Prepare("UPDATE calendar SET status=$1, contractno=$2 WHERE date=$3;")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
for i := 0; i < 1; i++ {
_, err = stmt.Exec(term.Status, term.Contractno, term.Date)
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
}
err = tx.Commit()
if err != nil {
http.Error(w, "błąd zapisu danych", 500)
return
}
}
return
}
func enableCorsDelete(w *http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
}

View File

@ -1,23 +0,0 @@
package calendar
import (
"fmt"
"net/http"
)
func AddCalendar(w http.ResponseWriter, r *http.Request) {
keys, ok := r.URL.Query()["key"]
if !ok || len(keys[0]) < 1 {
fmt.Println("Url Param 'key' is missing")
return
}
key := keys[0]
fmt.Fprint(w, "Url Param 'key' is: " + string (key))
}
//func Calendar(w http.ResponseWriter, r *http.Request) {
// fmt.Fprint(w, "Welcome!\n")
//}

149
calendarController.go Normal file
View File

@ -0,0 +1,149 @@
package main
import (
"encoding/json"
"fmt"
"github.com/gorilla/mux"
"io/ioutil"
"log"
"net/http"
)
func newTerm(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
}
log.Println(string(body))
var term term_struct
err = json.Unmarshal(body, &term)
if err != nil {
panic(err)
}
for i := 0; i < len(term.Months); i++ {
daysIn(term.Months[i], term.Year)
}
}
func addRow(data string) {
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
defer tx.Rollback()
stmt, err := tx.Prepare("INSERT INTO calendar (date, status, contractNo) VALUES ( $1, 'available', '');")
if err != nil {
log.Fatal(err)
}
defer stmt.Close() // danger!
for i := 0; i < 1; i++ {
_, err = stmt.Exec(data)
if err != nil {
log.Fatal(err)
}
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
}
}
func getTerms(w http.ResponseWriter, r *http.Request) {
enableCors(&w)
terms := []Term{}
rows, err := db.Query("SELECT * FROM calendar;")
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
term := Term{}
err = rows.Scan(
&term.Id,
&term.Date,
&term.Status,
&term.Contractno,
)
if err != nil {
return
}
terms = append(terms, term)
}
fmt.Println(terms)
out, err := json.Marshal(terms)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
fmt.Fprint(w, string(out))
}
func getTerm(w http.ResponseWriter, r *http.Request) {
enableCors(&w)
vars := mux.Vars(r)
terms := []Term{}
stmt, err := db.Prepare("SELECT * FROM calendar WHERE EXTRACT(MONTH FROM date) = $1 AND EXTRACT(YEAR FROM date) = $2 ORDER BY date ASC;")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
rows, err := stmt.Query(vars["month"], vars["year"])
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
term := Term{}
err = rows.Scan(
&term.Id,
&term.Date,
&term.Status,
&term.Contractno,
)
if err != nil {
return
}
terms = append(terms, term)
}
if err = rows.Err(); err != nil {
log.Fatal(err)
}
out, err := json.Marshal(terms)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
fmt.Fprint(w, string(out))
}
func postTest(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
}
fmt.Println("postTest")
log.Println(string(body));
}
func deleteTest(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-Type")
//body, err := ioutil.ReadAll(req.Body)
//if err != nil {
// panic(err)
//}
fmt.Println("deleteTest");
//log.Println(string(body));
}

View File

@ -1,118 +0,0 @@
package dbConfig
import (
"database/sql"
"encoding/json"
"fmt"
"net/http"
"os"
)
var db *sql.DB
const (
dbhost = "DBHOST"
dbport = "5432"
dbuser = "postgres"
dbpass = "admin"
dbname = "mydb"
)
func initDb() {
//config := dbConfig()
var err error
//psqlInfo := fmt.Sprintf("host=localhost port=%s user=%s password=%s dbname=%s sslmode=disable",
// config[dbport], config[dbuser], config[dbpass], config[dbname])
db, err = sql.Open("postgres", "port=5432 password=admin user=postgres dbname=mydb sslmode=disable")
if err != nil {
panic(err)
}
err = db.Ping()
if err != nil {
panic(err)
}
fmt.Println("Successfullu connected!")
}
func dbConfig() map[string]string {
conf := make(map[string]string)
host, ok := os.LookupEnv(dbhost)
if !ok {
panic("DBHOST environment variable required but not set")
}
port, ok := os.LookupEnv(dbport)
if !ok {
panic("DBPORT environment variable required but not set")
}
user, ok := os.LookupEnv(dbuser)
if !ok {
panic("DBUSER environment variable required but not set")
}
password, ok := os.LookupEnv(dbpass)
if !ok {
panic("DBPASS environment variable required but not set")
}
name, ok := os.LookupEnv(dbname)
if !ok {
panic("DBNAME environment variable required but not set")
}
conf[dbhost] = host
conf[dbport] = port
conf[dbuser] = user
conf[dbpass] = password
conf[dbname] = name
return conf
}
func testFunc(w http.ResponseWriter, r *http.Request) {
fmt.Println("weszlo")
repos := repositories{}
err := queryRepos(&repos)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
out, err := json.Marshal(repos)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
fmt.Fprint(w, repos)
fmt.Fprintf(w, string(out))
}
func queryRepos(repos *repositories) error {
rows, err := db.Query(`SELECT * FROM friends.test;`)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
repo := repositorySummary{}
err = rows.Scan(
&repo.firstname,
&repo.lastname, )
if err != nil {
return err
}
fmt.Println("mam", repo)
repos.Repositories = append(repos.Repositories, repo)
}
err = rows.Err()
if err != nil {
return err
}
return nil
}
type repositorySummary struct {
firstname string
lastname string
}
type repositories struct {
Repositories []repositorySummary
}

33
dbConnector.go Normal file
View File

@ -0,0 +1,33 @@
package main
import (
"database/sql"
"fmt"
)
var db *sql.DB
const (
dbhost = "DBHOST"
dbport = "5432"
dbuser = "postgres"
dbpass = "admin"
dbname = "mydb"
)
func initDb() {
//config := dbConfig()
var err error
//psqlInfo := fmt.Sprintf("host=localhost port=%s user=%s password=%s dbname=%s sslmode=disable",
// config[dbport], config[dbuser], config[dbpass], config[dbname])
db, err = sql.Open("postgres", "port=5432 password=admin user=postgres dbname=mydb sslmode=disable")
if err != nil {
panic(err)
}
err = db.Ping()
if err != nil {
panic(err)
}
fmt.Println("Successfullu connected!")
}

234
main.go
View File

@ -1,235 +1,31 @@
package main
import (
"database/sql"
"encoding/json"
"fmt"
"io/ioutil"
"github.com/gorilla/mux"
"github.com/gorilla/handlers"
"log"
"net/http"
"os"
"strconv"
"time"
)
import _"github.com/lib/pq"
func main() {
alowedHeaders := handlers.AllowedHeaders([]string{"Content-Type"})
allowedOrigins := handlers.AllowedOrigins([]string{"*"})
allowedMethods := handlers.AllowedMethods([]string{"GET", "POST", "OPTIONS", "DELETE"})
initDb()
defer db.Close()
//router := router.NewRouter()
http.HandleFunc("/test", test)
http.HandleFunc("/test2", createTerms2)
http.HandleFunc("/date", createTerms)
log.Fatal(http.ListenAndServe(":8080", nil))
//router := NewRouter()
router:=mux.NewRouter()
router.HandleFunc("/term/{year}/{month}", getTerm).Methods("GET", "OPTIONS")
router.HandleFunc("/test", postTest).Methods("POST", "OPTIONS")
router.HandleFunc("/test", deleteTest).Methods("DELETE", "OPTIONS")
log.Fatal(http.ListenAndServe(":8080", handlers.CORS(alowedHeaders, allowedOrigins, allowedMethods)(router)))
}
var db *sql.DB
const (
dbhost="DBHOST"
dbport="5432"
dbuser="postgres"
dbpass="admin"
dbname="mydb"
)
func initDb() {
//config := dbConfig()
var err error
//psqlInfo := fmt.Sprintf("host=localhost port=%s user=%s password=%s dbname=%s sslmode=disable",
// config[dbport], config[dbuser], config[dbpass], config[dbname])
db, err = sql.Open("postgres", "port=5432 password=admin user=postgres dbname=mydb sslmode=disable")
if err != nil {
panic(err)
}
err = db.Ping()
if err != nil {
panic(err)
}
fmt.Println("Successfullu connected!")
}
func dbConfig() map[string]string {
conf := make(map[string]string)
host, ok := os.LookupEnv(dbhost)
if !ok {
panic("DBHOST environment variable required but not set")
}
port, ok := os.LookupEnv(dbport)
if !ok {
panic("DBPORT environment variable required but not set")
}
user, ok := os.LookupEnv(dbuser)
if !ok {
panic("DBUSER environment variable required but not set")
}
password, ok := os.LookupEnv(dbpass)
if !ok {
panic("DBPASS environment variable required but not set")
}
name, ok := os.LookupEnv(dbname)
if !ok {
panic("DBNAME environment variable required but not set")
}
conf[dbhost] = host
conf[dbport] = port
conf[dbuser] = user
conf[dbpass] = password
conf[dbname] = name
return conf
}
func testFunc(w http.ResponseWriter, r *http.Request) {
fmt.Println("weszlo")
repos := repositories{}
err := queryRepos(&repos)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
out, err := json.Marshal(repos)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
fmt.Fprint(w, repos)
fmt.Fprintf(w, string(out))
}
func test(rw http.ResponseWriter, req *http.Request) {
//body, err := ioutil.ReadAll(req.Body)
//if err != nil {
// panic(err)
//}
//fmt.Println(string(body))
//var t test_struct
//err = json.Unmarshal(body, &t)
//if err != nil {
// panic(err)
//}
//fmt.Println(t.Test1)
//fmt.Println(t.aaa)
//addRow("2018-02-04")
}
func createTerms2(rw http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body)
var t2 test_struct2
err := decoder.Decode(&t2)
if err != nil {
panic(err)
}
fmt.Println(t2.Test)
fmt.Println(t2.SomeKey)
}
type test_struct2 struct {
Test []int `json:"months"`
SomeKey int `json:"year"`
}
type test_struct struct {
Test1 int
aaa string
}
func createTerms(w http.ResponseWriter, req *http.Request) {
//year, ok :=r.URL.Query()["year"]
//daysIn(11,2018)
//daysIn(12,2018)
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
}
log.Println(string(body))
var term term_struct
err = json.Unmarshal(body, &term)
if err != nil {
panic(err)
}
//fmt.Println(term.Year)
//fmt.Println(term.Months)
for i:=0; i< len(term.Months); i++ {
daysIn(term.Months[i], term.Year)
// //fmt.Println(daysIn(newTerm.months[i], newTerm.year))
}
}
type term_struct struct {
Months []int `json:"months"`
Year int `json:"year"`
}
func daysIn(m int, year int) {
var data string
dni := time.Date(year, time.Month(m+1),0,0,0,0,0,time.UTC)
for i := 1; i <= dni.Day(); i++ {
data = strconv.Itoa(year) + "-" + strconv.Itoa(int(m)) + "-" + strconv.Itoa(i)
fmt.Println("data: ", data)
addRow(data)
}
}
func addRow(data string) {
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
defer tx.Rollback()
stmt, err := tx.Prepare("INSERT INTO calendar (date, status, contractNo) VALUES ( $1, 'available', '');")
if err != nil {
log.Fatal(err)
}
defer stmt.Close() // danger!
for i := 0; i < 1; i++ {
_, err = stmt.Exec(data)
if err != nil {
log.Fatal(err)
}
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
}
}
func queryRepos(repos *repositories) error {
rows, err := db.Query(`SELECT * FROM friends.test;`)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
repo := repositorySummary{}
err = rows.Scan(
&repo.firstname,
&repo.lastname,)
if err != nil {
return err
}
fmt.Println("mam", repo)
repos.Repositories = append(repos.Repositories, repo)
}
err = rows.Err()
if err != nil {
return err
}
return nil
}
type repositorySummary struct {
firstname string
lastname string
}
type repositories struct {
Repositories []repositorySummary
func enableCors(w *http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
}

32
models.go Normal file
View File

@ -0,0 +1,32 @@
package main
type term_struct struct {
Months []int `json:"months"`
Year int `json:"year"`
}
type NewQuery struct {
Startdate string `json:"startdate"`
Enddate string `json:"enddate"`
Location string `json:"location"`
Description string `json:"description"`
Contactperson string `json:"contactperon"`
Contactno string `json:"contactno"`
Email string `json:"email"`
Status int `json:"status"`
Questiondate string `json:"questiondate"`
}
//type Term struct {
// id int `json:"id"`
// date string `json:"date"`
// status string `json:"status"`
// contractno string `json:"contractno"`
//}
type Term struct {
Id int `json:"id"`
Date string `json:"date"`
Status string `json:"status"`
Contractno string `json:"contractno"`
}

87
proba.go Normal file
View File

@ -0,0 +1,87 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type repositorySummary struct {
ID int
Name string
Owner string
TotalStars int
}
type repositories struct {
Repositories []repositorySummary
}
func proba(w http.ResponseWriter, req *http.Request) {
repos := []repositorySummary{}
enableCors(&w)
rows, err := db.Query(`
SELECT
*
FROM repositories2`)
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
repo := repositorySummary{}
err = rows.Scan(
&repo.ID,
&repo.Owner,
&repo.Name,
&repo.TotalStars,
)
if err != nil {
return
}
repos = append(repos, repo)
}
out, err := json.Marshal(repos)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
fmt.Fprintf(w, string(out))
}
func queryRepos(repos []repositorySummary) error {
rows, err := db.Query(`
SELECT
id,
repository_owner,
repository_name,
total_stars
FROM repositories2`)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
repo := repositorySummary{}
err = rows.Scan(
&repo.ID,
&repo.Owner,
&repo.Name,
&repo.TotalStars,
)
if err != nil {
return err
}
repos = append(repos, repo)
}
fmt.Println(repos)
err = rows.Err()
if err != nil {
return err
}
return nil
}

43
queriesController.go Normal file
View File

@ -0,0 +1,43 @@
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
func newQuery(w http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
if err != nil {
panic(err)
}
log.Println(string(body))
var query NewQuery
err = json.Unmarshal(body, &query)
if err != nil {
panic(err)
}
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
defer tx.Rollback()
stmt, err := tx.Prepare("INSERT INTO queries (startdate, enddate, location, description, contactperson, contactno, email, status, questiondate) VALUES" +
"( $1, $2, $3, $4, $5, $6, $7, $8, $9);")
if err != nil {
log.Fatal(err)
}
defer stmt.Close() // danger!
for i := 0; i < 1; i++ {
_, err = stmt.Exec(query.Startdate, query.Enddate, query.Location, query.Description, query.Contactperson, query.Contactno, query.Email, query.Status, query.Questiondate)
if err != nil {
log.Fatal(err)
}
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
}
}

View File

@ -1,9 +1,9 @@
package router
package main
import (
"net/http"
"github.com/gorilla/mux"
"../logger"
"./logger"
)
func NewRouter() *mux.Router {

View File

@ -1,21 +0,0 @@
package router
import (
"net/http"
"../test"
"../calendar"
)
type Route struct {
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}
type Routes []Route
var routes = Routes{
Route{"Index", "GET", "/", test.Index,},
Route{"AddCalendar", "POST", "/calendar", calendar.AddCalendar},
}

28
routes.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"net/http"
)
type Route struct {
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}
type Routes []Route
var routes = Routes{
Route{"addTerm", "POST", "/term", newTerm},
Route{"getTerms", "GET", "/term", getTerms},
Route{"getTerm","GET","/term/{year}/{month}", getTerm},
Route{"test", "GET", "/test", proba},
Route{"newQuery", "POST", "/query", newQuery},
Route{"bookTerm", "POST", "/book", newBooking},
Route{"bookTerm", "DELETE", "/book", delBooking},
Route{"postTest", "POST", "/test", postTest},
Route{"postTest", "DELETE", "/test", deleteTest},
}

View File

@ -1690,6 +1690,11 @@
"multicast-dns-service-types": "^1.1.0"
}
},
"bootstrap": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-4.1.3.tgz",
"integrity": "sha512-rDFIzgXcof0jDyjNosjv4Sno77X4KuPeFxG2XZZv1/Kc8DRVGVADdoQyyOVDwPqL36DDmtCQbrpMCqvpPLJQ0w=="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -7407,6 +7412,16 @@
"integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=",
"dev": true
},
"primeicons": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/primeicons/-/primeicons-1.0.0.tgz",
"integrity": "sha512-p/hzIjUVccW4eJPhuORHI3AUkDpqfvCQVrjxbFEejnTEdWY4C8fomVfjiaA9jCu83fSQnBHuRIGB96iAR8R6uA=="
},
"primeng": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/primeng/-/primeng-7.0.3.tgz",
"integrity": "sha512-WbC8ScwpFO6iSxiTm/FGRr0T1Q6PvmbIjSFChoA9YIGXVGFK1hCG3K0xhEMdStCdS237m8SKoFoq/jcuJCZIjA=="
},
"process": {
"version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",

View File

@ -22,8 +22,11 @@
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0",
"bootstrap": "^4.1.3",
"core-js": "^2.5.4",
"hammerjs": "^2.0.8",
"primeicons": "^1.0.0",
"primeng": "^7.0.3",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"
},

View File

@ -1 +1,2 @@
<app-nav-bar></app-nav-bar>
<router-outlet></router-outlet>

View File

@ -1,26 +1,48 @@
import { BrowserModule } from '@angular/platform-browser';
import {CUSTOM_ELEMENTS_SCHEMA, NgModule} from '@angular/core';
import {CUSTOM_ELEMENTS_SCHEMA, LOCALE_ID, NgModule} from '@angular/core';
import { AppComponent } from './app.component';
import { AddTermsComponent } from './components/add-terms/add-terms.component';
import {RouterModule} from '@angular/router';
import {appRoutes} from './app.router.module';
import {MaterialModule} from './material.module';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {HttpClientModule} from '@angular/common/http';
import {TestComponent} from './components/test/test.component';
import {NavBarComponent} from './components/nav-bar/nav-bar.component';
import {TermListComponent} from './components/term-list/term-list.component';
import {CreateQueryComponent} from './components/dialogs/create-query/create-query.component';
import { AdminMenuComponent } from './components/admin-menu/admin-menu.component';
import { TermListAdminComponent } from './components/term-list-admin/term-list-admin.component';
import { EditTermAdminComponent } from './components/edit-term-admin/edit-term-admin.component';
@NgModule({
declarations: [
AppComponent,
AddTermsComponent
NavBarComponent,
TermListComponent,
AddTermsComponent,
CreateQueryComponent,
TestComponent,
AdminMenuComponent,
TermListAdminComponent,
EditTermAdminComponent
],
imports: [
BrowserModule,
MaterialModule,
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
HttpClientModule,
RouterModule.forRoot(
appRoutes,
// { enableTracking: true }
)
],
providers: [],
entryComponents: [CreateQueryComponent],
providers: [ ],
bootstrap: [AppComponent],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})

View File

@ -1,9 +1,29 @@
import {AddTermsComponent} from './components/add-terms/add-terms.component';
import {Routes} from '@angular/router';
import {TestComponent} from './components/test/test.component';
import {TermListComponent} from './components/term-list/term-list.component';
import {AdminMenuComponent} from './components/admin-menu/admin-menu.component';
import {TermListAdminComponent} from './components/term-list-admin/term-list-admin.component';
export const appRoutes: Routes = [
{
path: 'add-term',
path: 'list-term',
component: TermListComponent
},
{
path: 'test',
component: TestComponent
},
{
path: 'admin',
component: AdminMenuComponent
},
{
path: 'admin/add-term',
component: AddTermsComponent
},
{
path: 'admin/term-list-admin',
component: TermListAdminComponent
}
]

View File

@ -1,25 +1,22 @@
<!--<form [formGroup]="form">-->
<!--<mat-form-field>-->
<!--<mat-select placeholder="Rok" [formControl]="year" required>-->
<!--<mat-option>&#45;&#45;</mat-option>-->
<!--<mat-option *ngFor="let year of yearItems" [value]="year">-->
<!--{{year}}-->
<!--</mat-option>-->
<!--</mat-select>-->
<!--<mat-error *ngIf="year.hasError('required')">Wybierz rok</mat-error>-->
<!--</mat-form-field>-->
<!--</form>-->
<form [formGroup]="form" (ngSubmit)="submit()">
<div class="container">
<div class="row">
<mat-form-field>
<mat-select placeholder="Rok" formControlName="year">
<mat-option *ngFor="let year of yearItems" [value]="year">
{{year}}
</mat-option>
</mat-select>
<mat-error *ngIf="form.get('year').invalid">Pole wymagane !</mat-error>
</mat-form-field>
</div>
<form class="example-form">
<mat-form-field class="example-full-width">
<input matInput placeholder="Email" [formControl]="emailFormControl"
[errorStateMatcher]="matcher">
<mat-hint>Errors appear instantly!</mat-hint>
<mat-error *ngIf="emailFormControl.hasError('email') && !emailFormControl.hasError('required')">
Please enter a valid email address
</mat-error>
<mat-error *ngIf="emailFormControl.hasError('required')">
Email is <strong>required</strong>
</mat-error>
</mat-form-field>
<div class="row" *ngFor="let month of form.controls.orders.controls; let i = index" formArrayName="orders">
<mat-checkbox [formControlName]="i" color="primary">{{months[i].value}}</mat-checkbox>
</div>
<div class="row">
<button mat-raised-button color="primary" type="submit">Primary</button>
</div>
</div>
</form>

View File

@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup, FormGroupDirective, NgForm, Validators} from '@angular/forms';
import {FormArray, FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators} from '@angular/forms';
import {ErrorStateMatcher} from '@angular/material';
@Component({
@ -11,49 +11,73 @@ import {ErrorStateMatcher} from '@angular/material';
export class AddTermsComponent implements OnInit {
form: FormGroup;
emailFormControl: FormControl;
matcher = new MyErrorStateMatcher();
yearItems = [ 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030 ];
months = [
{ key: 1, value: 'Styczeń'},
{ key: 2, value: 'Luty'},
{ key: 3, value: 'Marzec'},
{ key: 4, value: 'Kwieceń'},
{ key: 5, value: 'Maj'},
{ key: 6, value: 'Czerwiec'},
{ key: 7, value: 'Lipiec'},
{ key: 8, value: 'Sierpień'},
{ key: 9, value: 'Wrzesień'},
{ key: 10, value: 'Październik'},
{ key: 11, value: 'Listopad'},
{ key: 12, value: 'Grudzień'}
]
constructor() { }
constructor(private formBuilder: FormBuilder) {
const controls = this.months.map(c => new FormControl(false));
this.form = this.formBuilder.group({
year: new FormControl(null, Validators.required),
orders: new FormArray(controls)
});
}
ngOnInit() {
this.createForm();
// this.createForm();
}
this.emailFormControl = new FormControl('', [
Validators.required,
Validators.email,
]);
submit() {
const selectedOrderIds = this.form.value.orders
.map((v, i) => v ? this.months[i].key : null)
.filter(v => v !== null);
console.log(selectedOrderIds);
console.log(this.form.controls.year.value);
}
createForm() {
// this.form = new FormGroup({
// year: new FormControl(null, Validators.required),
// months: new FormControl(false, Validators.requiredTrue),
// 1: new FormControl(false),
// 2: new FormControl(false),
// 3: new FormControl(false),
// 4: new FormControl(false),
// 5: new FormControl(false),
// 6: new FormControl(false),
// 7: new FormControl(false),
// 8: new FormControl(false),
// 9: new FormControl(false),
// 10: new FormControl(false),
// 11: new FormControl(false),
// 12: new FormControl(false)
// });
}
this.form = new FormGroup({
year: new FormControl(null, Validators.required),
months: new FormControl(false, Validators.requiredTrue),
month1: new FormControl(false),
month2: new FormControl(false),
month3: new FormControl(false),
month4: new FormControl(false),
month5: new FormControl(false),
month6: new FormControl(false),
month7: new FormControl(false),
month8: new FormControl(false),
month9: new FormControl(false),
month10: new FormControl(false),
month11: new FormControl(false),
month12: new FormControl(false)
});
do() {
console.log(this.form);
}
}
export class MyErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = form && form.submitted;
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
}
}
// export class MyErrorStateMatcher implements ErrorStateMatcher {
// isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
// const isSubmitted = form && form.submitted;
// return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
// }
// }

View File

@ -0,0 +1,5 @@
<a routerLink="add-term">Dodaj terminy</a>
<a routerLink="term-list-admin">Terminy</a>
<router-outlet></router-outlet>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AdminMenuComponent } from './admin-menu.component';
describe('AdminMenuComponent', () => {
let component: AdminMenuComponent;
let fixture: ComponentFixture<AdminMenuComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AdminMenuComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AdminMenuComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-admin-menu',
templateUrl: './admin-menu.component.html',
styleUrls: ['./admin-menu.component.css']
})
export class AdminMenuComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

View File

@ -0,0 +1,3 @@
.example-full-width {
width: 100%;
}

View File

@ -0,0 +1,82 @@
<div mat-dialog-content>
<p>Zarezerwuj termin</p>
<form [formGroup]="form">
<div class="container">
<div class="row">
<div class="col">
<mat-form-field class="example-full-width">
<input matInput [matDatepicker]="picker1" placeholder="Od" formControlName="startdate">
<mat-datepicker-toggle matSuffix [for]="picker1"></mat-datepicker-toggle>
<mat-datepicker #picker1></mat-datepicker>
</mat-form-field>
</div>
<div class="col">
<mat-form-field class="example-full-width">
<input matInput [matDatepicker]="picker2" placeholder="Do" formControlName="enddate">
<mat-datepicker-toggle matSuffix [for]="picker2"></mat-datepicker-toggle>
<mat-datepicker #picker2></mat-datepicker>
</mat-form-field>
</div>
<div class="col">
<mat-form-field class="example-full-width">
<input matInput placeholder="Miejsce" formControlName="location">
<mat-error *ngIf="form.get('location').hasError('required')">Pole jest wymagane</mat-error>
</mat-form-field>
</div>
</div>
<div class="row">
<div class="col">
<mat-form-field class="example-full-width">
<input matInput placeholder="Imię i nazwisko" formControlName="contactperson">
<mat-error *ngIf="form.get('location').hasError('required')">Pole jest wymagane</mat-error>
</mat-form-field>
</div>
<div class="col">
<mat-form-field class="example-full-width">
<input matInput placeholder="Nr telefonu" formControlName="contactno">
<mat-error *ngIf="form.get('location').hasError('required')">Pole jest wymagane</mat-error>
</mat-form-field>
</div>
<div class="col">
<mat-form-field class="example-full-width">
<input matInput placeholder="Adres email" formControlName="email">
<mat-error *ngIf="form.get('email').hasError('email') && !form.get('email').hasError('required')">
Zły format adresu email
</mat-error>
<mat-error *ngIf="form.get('email').hasError('required')">Pole jest wymagane
</mat-error>
</mat-form-field>
</div>
</div>
<div class="row">
<div class="col">
<mat-form-field class="example-full-width">
<textarea matInput placeholder="Opis zapytania" formControlName="description"></textarea>
<mat-error *ngIf="form.get('description').hasError('required')">Pole jest wymagane</mat-error>
</mat-form-field>
</div>
</div>
</div>
</form>
</div>
<div mat-dialog-actions>
<div class="container">
<div class="row justify-content-between">
<div class="col-3">
<button mat-button mat-raised-button color="warn" (click)="onNoClick()">Zamknij</button>
</div>
<div class="col-3" style="align: right">
<button mat-button mat-raised-button color="primary" (click)="onTest()" [disabled]="form.invalid">Wyślij
zapytanie
</button>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateQueryComponent } from './create-query.component';
describe('CreateQueryComponent', () => {
let component: CreateQueryComponent;
let fixture: ComponentFixture<CreateQueryComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateQueryComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CreateQueryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,47 @@
import { Component, OnInit, Inject } from '@angular/core';
import {ErrorStateMatcher, MAT_DIALOG_DATA, MatDialogRef} from '@angular/material';
import {FormControl, FormGroup, FormGroupDirective, NgForm, Validators} from '@angular/forms';
import {CreateQuery} from '../../../models/CreateQuery';
export interface DialogData {
animal: string;
name: string;
}
@Component({
selector: 'app-create-query',
templateUrl: './create-query.component.html',
styleUrls: ['./create-query.component.css']
})
export class CreateQueryComponent {
test: string;
form: FormGroup;
newQuery = new CreateQuery();
constructor(
public dialogRef: MatDialogRef<CreateQueryComponent>,
@Inject(MAT_DIALOG_DATA) public data: DialogData) {
this.form = new FormGroup({
startdate: new FormControl('', [Validators.required]),
enddate: new FormControl('', [Validators.required]),
location: new FormControl(null, [Validators.required]),
description: new FormControl('', [Validators.required]),
contactperson: new FormControl(null, [Validators.required]),
contactno: new FormControl(null, [Validators.required]),
email: new FormControl(null, [Validators.required, Validators.email])
});
}
onNoClick(): void {
// console.log(this.test);
this.dialogRef.close();
}
onTest() {
console.log(this.form.value);
}
}

View File

@ -0,0 +1,3 @@
<p>
edit-term-admin works!
</p>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditTermAdminComponent } from './edit-term-admin.component';
describe('EditTermAdminComponent', () => {
let component: EditTermAdminComponent;
let fixture: ComponentFixture<EditTermAdminComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditTermAdminComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditTermAdminComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-edit-term-admin',
templateUrl: './edit-term-admin.component.html',
styleUrls: ['./edit-term-admin.component.css']
})
export class EditTermAdminComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

View File

@ -0,0 +1,56 @@
import {Month} from '../../models/Month';
export class DataSources {
public static yearsList = [ '2018', '2019', '2020', '2021', '2022', '2023'];
public static monthsList: Month[] = [
{
key: '01',
value: 'styczeń'
},
{
key: '2',
value: 'luty'
},
{
key: '3',
value: 'marzec'
},
{
key: '4',
value: 'kwiecień'
},
{
key: '5',
value: 'maj'
},
{
key: '6',
value: 'czerwiec'
},
{
key: '7',
value: 'lipiec'
},
{
key: '8',
value: 'sierpień'
},
{
key: '9',
value: 'wrzesień'
},
{
key: '10',
value: 'październik'
},
{
key: '11',
value: 'listopad'
},
{
key: '12',
value: 'grudzień'
}
];
}

View File

@ -0,0 +1,7 @@
<nav class="navbar navbar-dark bg-dark">
<a routerLink="/list-term">Terminarz</a>
<a routerLink="/test">Add term2</a>
<form class="form-inline">
<button class="btn btn-sm btn-outline-info my-2 my-sm-9" type="button" routerLink="admin">Admin panel</button>
</form>
</nav>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NavBarComponent } from './nav-bar.component';
describe('NavBarComponent', () => {
let component: NavBarComponent;
let fixture: ComponentFixture<NavBarComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NavBarComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NavBarComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-nav-bar',
templateUrl: './nav-bar.component.html',
styleUrls: ['./nav-bar.component.css']
})
export class NavBarComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

View File

@ -0,0 +1,65 @@
<div style="margin: 0 auto; width: 80%">
<form [formGroup]="form">
<mat-form-field>
<mat-select placeholder="Rok" formControlName="year">
<mat-option *ngFor="let year of yearsList" [value]="year">
{{year}}
</mat-option>
</mat-select>
<mat-error *ngIf="form.get('year').invalid">Pole wymagane !</mat-error>
</mat-form-field>
<mat-form-field>
<mat-select placeholder="Miesiąc" formControlName="month">
<mat-option *ngFor="let month of monthsList" [value]="month.key">
{{month.value}}
</mat-option>
</mat-select>
<mat-error *ngIf="form.get('month').invalid">Pole wymagane !</mat-error>
</mat-form-field>
<button mat-raised-button color="primary" (click)="search()" [disabled]="form.invalid">Szukaj</button>
</form>
</div>
<br>
<div style="margin: 0 auto; width: 80%">
<table mat-table [dataSource]="allTerms$ | async" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="weekDay">
<th mat-header-cell *matHeaderCellDef>Dzień tygodnia</th>
<td mat-cell *matCellDef="let element"> {{element.date | date: 'EEEE'}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef>Data</th>
<td mat-cell *matCellDef="let element"> {{element.date | date:'dd - MM - yyyy' }}</td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="availability">
<th mat-header-cell *matHeaderCellDef>Dostępność</th>
<td mat-cell *matCellDef="let element"> {{element.status}} </td>
</ng-container>
<ng-container matColumnDef="contractno">
<th mat-header-cell *matHeaderCellDef>Nr Umowy</th>
<td mat-cell *matCellDef="let element"> {{element.contractno}} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef>Akcja</th>
<td mat-cell *matCellDef="let element">
<button (click)="delete(element)">Usuń</button>
</td>
<td mat-cell *matCellDef="let element">
<button (click)="edit()">Edytuj</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
<button (click)="delete()">Delete</button>
<button (click)="post()">Post</button>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TermListAdminComponent } from './term-list-admin.component';
describe('TermListAdminComponent', () => {
let component: TermListAdminComponent;
let fixture: ComponentFixture<TermListAdminComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TermListAdminComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TermListAdminComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,94 @@
import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {Month} from '../../models/Month';
import {Observable} from 'rxjs';
import {Terms} from '../../models/Term';
import {TermService} from '../../services/term.service';
import {MatDialog} from '@angular/material';
import {DataSources} from '../environments/DataSources';
import {CreateQueryComponent} from '../dialogs/create-query/create-query.component';
import {PeriodicElement} from '../term-list/term-list.component';
import {TerminAdminServiceService} from '../../services/termin-admin-service.service';
const ELEMENT_DATA: PeriodicElement[] = [
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
];
@Component({
selector: 'app-term-list-admin',
templateUrl: './term-list-admin.component.html',
styleUrls: ['./term-list-admin.component.css']
})
export class TermListAdminComponent implements OnInit {
form: FormGroup;
yearsList = [];
monthsList: Month[];
displayedColumns: string[] = ['weekDay', 'date', 'availability', 'contractno', 'actions'];
dataSource = ELEMENT_DATA;
allTerms$: Observable<Array<Terms>>;
animal: string;
name: string;
constructor(private termService: TermService, private dialog: MatDialog, private terminAdminService: TerminAdminServiceService) {
this.yearsList = DataSources.yearsList;
this.monthsList = DataSources.monthsList;
}
ngOnInit() {
this.form = new FormGroup({
year: new FormControl(null, Validators.required),
month: new FormControl(null, Validators.required)
});
this.allTerms$ = this.termService.terms$;
}
search() {
console.log(this.form.value);
this.termService.getTerms(this.form.controls.year.value, this.form.controls.month.value);
}
edit() {
console.log('asdasdasd');
}
delete(event: Terms) {
// var date = new Date(event.date);
// event.date = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDay();
// event.status = 'dostępny';
// event.contractno = '';
// console.log('data ', event.date);
// this.terminAdminService.deleteTerm(event);
this.terminAdminService.deleteTest();
}
post() {
this.terminAdminService.postTest();
}
openDialog(): void {
const dialogRef = this.dialog.open(CreateQueryComponent, {
width: '65%',
data: {name: this.name, animal: this.animal}
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
}

View File

@ -0,0 +1,4 @@
table {
width: 90%;
align: 0 auto;
}

View File

@ -0,0 +1,50 @@
<div style="margin: 0 auto; width: 80%">
<form [formGroup]="form">
<mat-form-field>
<mat-select placeholder="Rok" formControlName="year">
<mat-option *ngFor="let year of yearsList" [value]="year">
{{year}}
</mat-option>
</mat-select>
<mat-error *ngIf="form.get('year').invalid">Pole wymagane !</mat-error>
</mat-form-field>
<mat-form-field>
<mat-select placeholder="Miesiąc" formControlName="month">
<mat-option *ngFor="let month of monthsList" [value]="month.key">
{{month.value}}
</mat-option>
</mat-select>
<mat-error *ngIf="form.get('month').invalid">Pole wymagane !</mat-error>
</mat-form-field>
<button mat-raised-button color="primary" (click)="search()" [disabled]="form.invalid">Szukaj</button>
</form>
<button mat-raised-button color="primary" (click)="openDialog()">Zarezerwuj termin</button>
</div>
<br>
<div style="margin: 0 auto; width: 80%">
<table mat-table [dataSource]="allTerms$ | async" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="weekDay">
<th mat-header-cell *matHeaderCellDef>Dzień tygodnia</th>
<td mat-cell *matCellDef="let element"> {{element.date | date: 'EEEE'}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef>Data</th>
<td mat-cell *matCellDef="let element"> {{element.date | date:'dd - MM - yyyy' }}</td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="availability">
<th mat-header-cell *matHeaderCellDef>Dostępność</th>
<td mat-cell *matCellDef="let element"> {{element.status}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TermListComponent } from './term-list.component';
describe('TermListComponent', () => {
let component: TermListComponent;
let fixture: ComponentFixture<TermListComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TermListComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TermListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,85 @@
import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {Month} from '../../models/Month';
import {DataSources} from '../environments/DataSources';
import {TermService} from '../../services/term.service';
import {Terms} from '../../models/Term';
import {Observable} from 'rxjs';
import {MatDialog} from '@angular/material';
import {CreateQueryComponent} from '../dialogs/create-query/create-query.component';
export interface PeriodicElement {
name: string;
position: number;
weight: number;
symbol: string;
}
const ELEMENT_DATA: PeriodicElement[] = [
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
];
@Component({
selector: 'app-term-list',
templateUrl: './term-list.component.html',
styleUrls: ['./term-list.component.css']
})
export class TermListComponent implements OnInit {
form: FormGroup;
yearsList = [];
monthsList: Month[];
displayedColumns: string[] = ['weekDay', 'date', 'availability'];
dataSource = ELEMENT_DATA;
allTerms$: Observable<Array<Terms>>;
animal: string;
name: string;
constructor(private termService: TermService, private dialog: MatDialog) {
this.yearsList = DataSources.yearsList;
this.monthsList = DataSources.monthsList;
}
ngOnInit() {
this.form = new FormGroup({
year: new FormControl(null, Validators.required),
month: new FormControl(null, Validators.required)
});
this.allTerms$ = this.termService.terms$;
}
search() {
console.log(this.form.value);
this.termService.getTerms(this.form.controls.year.value, this.form.controls.month.value);
}
openDialog(): void {
const dialogRef = this.dialog.open(CreateQueryComponent, {
width: '65%',
data: {name: this.name, animal: this.animal}
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
}
//
// export interface DialogData {
// animal: string;
// name: string;
// }

View File

@ -0,0 +1,3 @@
<p>
test works!
</p>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TestComponent } from './test.component';
describe('TestComponent', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TestComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,17 @@
import { Component, OnInit } from '@angular/core';
import {TermService} from '../../services/term.service';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
constructor(private termService: TermService) { }
ngOnInit() {
// this.termService.getTerms();
}
}

View File

@ -0,0 +1,23 @@
export class CreateQuery {
startdate: string;
enddate: string;
location: string;
description: string;
contactperson: string;
contactno: string;
email: string;
status: number;
questiondate: string
constructor() {
this.startdate = '';
this.enddate = '';
this.location = '';
this.description = '';
this.contactperson = '';
this.contactno = '';
this.email = '';
this.status = 1;
this.questiondate = '';
}
}

View File

@ -0,0 +1,4 @@
export interface Month {
key: string;
value: string;
}

View File

@ -0,0 +1,6 @@
export interface Terms {
id: number;
date: Date;
status: string;
contractno: string;
}

View File

@ -1,9 +1,33 @@
import { Injectable } from '@angular/core';
import {Injectable} from '@angular/core';
import {HttpClient, HttpParams} from '@angular/common/http';
import {environment} from '../../environments/environment';
import {Terms} from '../models/Term';
import {BehaviorSubject} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class TermService {
constructor() { }
constructor(private httpClient: HttpClient) {
}
endpoint = 'term';
// terms: Array<Terms>;
private termsObs = new BehaviorSubject<Array<Terms>>([]);
terms$ = this.termsObs.asObservable();
getTerms(year: string, month: string) {
return this.httpClient.get<Array<Terms>>(environment.API_BACK + this.endpoint + `/${year}/${month}`)
// this.httpClient.get('http://localhost:8080/term/' + year + '/' + month)
.subscribe(x => {
console.log(x);
this.termsObs.next(x);
},
err => {
console.log(err);
});
}
}

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { TerminAdminServiceService } from './termin-admin-service.service';
describe('TerminAdminServiceService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: TerminAdminServiceService = TestBed.get(TerminAdminServiceService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,73 @@
import { Injectable } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {environment} from '../../environments/environment';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
providedIn: 'root'
})
export class TerminAdminServiceService {
endpoint = 'book'
constructor(private httpClient: HttpClient) { }
async deleteTerm(term: any) {
const headers = new HttpHeaders();
headers.set('Content-Type', 'application/json; charset=utf-8');
headers.set('Access-Control-Allow-Origin', '*');
headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
return this.httpClient.delete(environment.API_BACK + this.endpoint, term)
.subscribe(
x => {
console.log('usunięto');
},
err => {
console.log('błąd usuwania');
}
);
// await this.httpClient.delete(environment.API_BACK + this.endpoint, term);
}
postTest() {
console.log('testuje');
const headers = new HttpHeaders();
headers.set('Content-Type', 'application/json');
this.httpClient.post<any>('http://localhost:8080/test', {'asdasd': 15561}, httpOptions)
.subscribe(
x => {
console.log('usunięto');
},
err => {
console.log('błąd usuwania');
});
// this.httpClient.delete('http://localhost:8080/test', {headers: headers})
// .subscribe(
// x => {
// console.log('usunięto');
// },
// err => {
// console.log('błąd usuwania');
// });
}
deleteTest() {
const headers = new HttpHeaders();
headers.set('Content-Type', 'application/json');
this.httpClient.delete<any>('http://localhost:8080/test', httpOptions)
.subscribe(
x => {
console.log('usunięto');
},
err => {
console.log('błąd usuwania');
});
}
}

View File

@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false
production: false,
API_BACK: 'http://localhost:8080/'
};
/*

View File

@ -1,2 +1,3 @@
/* You can add global styles to this file, and also import other style files */
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
@import "~bootstrap/dist/css/bootstrap.css";

Binary file not shown.

View File

@ -1,42 +0,0 @@
package test
import (
"fmt"
"net/http"
)
type repositorySummary struct {
firstname string
lastname string
}
type repositories struct {
Repositories []repositorySummary
}
func Index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome!")
}
//
//func queryRepos(repos *repositories) error {
// rows, err := dbCdb.Query(`SELECT * FROM friends.test`)
// if err != nil {
// return err
// }
// defer rows.Close()
// for rows.Next() {
// repo := repositorySummary{}
// err = rows.Scan(
// &repo.firstname,
// &repo.lastname,)
// if err != nil {
// return err
// }
// repos.Repositories = append(repos.Repositories, repo)
// }
// err = rows.Err()
// if err != nil {
// return err
// }
// return nil
//}