2018-11-18 09:52:24 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-11-25 12:46:45 +01:00
|
|
|
"encoding/json"
|
2018-11-18 09:52:24 +01:00
|
|
|
"fmt"
|
|
|
|
"html"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2018-11-25 12:46:45 +01:00
|
|
|
"time"
|
2018-11-18 09:52:24 +01:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
2018-11-25 12:46:45 +01:00
|
|
|
// Zrobione ostatnio:
|
|
|
|
// Podstawowe struktury modeli; niezbędne enumy;
|
|
|
|
// Zrobione:
|
|
|
|
// Podstawowy serwer;
|
|
|
|
//
|
|
|
|
// Do zrobienia:
|
|
|
|
// Funkcje modeli; Interfejsy json; łączenie z bazą danych; Rozne metody do tworzenia komend sql;
|
|
|
|
// Komunikacja z aplikacja desktopowa; Walidacja danych!! ;
|
2018-11-18 09:52:24 +01:00
|
|
|
func main() {
|
2018-11-25 12:46:45 +01:00
|
|
|
xx := getXxx()
|
|
|
|
xx.Pesel = "ssss"
|
2018-11-18 09:52:24 +01:00
|
|
|
muxRouter := mux.NewRouter().StrictSlash(true)
|
|
|
|
muxRouter.HandleFunc("/", index)
|
|
|
|
muxRouter.HandleFunc("/getfromdb", getAll)
|
|
|
|
muxRouter.HandleFunc("/getfromdb/{primaryKey}", getIndex)
|
|
|
|
log.Fatal(http.ListenAndServe(":8080", muxRouter))
|
2018-11-25 12:46:45 +01:00
|
|
|
|
2018-11-18 09:52:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func index(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
|
|
|
}
|
|
|
|
func getAll(w http.ResponseWriter, r *http.Request) {
|
2018-11-25 12:46:45 +01:00
|
|
|
patientsList := patients{
|
|
|
|
patient{"kss", "dasda", "asdasd a", time.Now(), patientStates(critical), sex(m), "xxx@yyy.zz"},
|
|
|
|
patient{"00112245789", "Adam", "Marcel", time.Now(), patientStates(stable), sex(k), "xxxx@yyy.zz"},
|
|
|
|
}
|
|
|
|
json.NewEncoder(w).Encode(patientsList)
|
2018-11-18 09:52:24 +01:00
|
|
|
}
|
|
|
|
func getIndex(w http.ResponseWriter, r *http.Request) {
|
|
|
|
args := mux.Vars(r)
|
|
|
|
pk := args["primaryKey"]
|
|
|
|
fmt.Fprintf(w, "Tutaj bedzie wynik dla PK = %s", pk)
|
|
|
|
}
|
2018-11-25 12:46:45 +01:00
|
|
|
func getXxx() patient {
|
|
|
|
pat := patient{"kss", "dasda", "asdasd a", time.Now(), patientStates(critical), sex(m), "xxx@yyy.zz"}
|
|
|
|
|
|
|
|
return pat
|
|
|
|
}
|