MySQL-Datenbank hinzugefügt und Abfrage korrigiert
This commit is contained in:
parent
e9e0cbf382
commit
e89429c3c3
5 changed files with 49 additions and 12 deletions
22
main.go
22
main.go
|
@ -1,14 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"log/syslog"
|
||||
"net/http"
|
||||
"os"
|
||||
"sprechstundentool/controllers"
|
||||
"sprechstundentool/repositories"
|
||||
"sprechstundentool/sqldb"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db := sqldb.ConnectDB()
|
||||
logwriter, e := syslog.New(syslog.LOG_ERR, "sprechstunden")
|
||||
if e == nil {
|
||||
log.SetOutput(logwriter)
|
||||
}
|
||||
|
||||
var db *sql.DB
|
||||
switch os.Getenv("ohtDbType") {
|
||||
case "mysql":
|
||||
db = sqldb.ConnectMysql(os.Getenv("ohtDbMysqlConnection"))
|
||||
default:
|
||||
if os.Getenv("ohtDbFile") != "" && !strings.Contains(os.Getenv("ohtDbFile"), "/") {
|
||||
db = sqldb.ConnectSQLite(os.Getenv("ohtDbFile"))
|
||||
} else {
|
||||
db = sqldb.ConnectSQLite("sprechstunden.db")
|
||||
}
|
||||
}
|
||||
|
||||
// Create repos
|
||||
roomRepo := repositories.NewRoomRepo(db)
|
||||
|
|
|
@ -119,16 +119,15 @@ func (r *OfficeHourRepo) Delete(officeHour models.OfficeHour) error {
|
|||
|
||||
func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
|
||||
var officeHour models.OfficeHour
|
||||
var week, day, hour, minute, tutorid int
|
||||
var roomName, courseName string
|
||||
err := row.Scan(&officeHour.Id, &tutorid, &day, &hour, &minute, &roomName, &courseName, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration)
|
||||
var week, day, hour, minute, tutorId, courseId, roomId int
|
||||
err := row.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration)
|
||||
if err != nil {
|
||||
return models.OfficeHour{}, fmt.Errorf("Error getting single officeHours row from database: %s", err.Error())
|
||||
}
|
||||
officeHour.Date = models.Date{week, day, hour, minute}
|
||||
officeHour.Room, _ = r.roomRepo.FindByName(roomName)
|
||||
officeHour.Tutor, _ = r.tutorRepo.FindById(tutorid)
|
||||
officeHour.Course, _ = r.courseRepo.FindByName(courseName)
|
||||
officeHour.Room, _ = r.roomRepo.FindById(roomId)
|
||||
officeHour.Tutor, _ = r.tutorRepo.FindById(tutorId)
|
||||
officeHour.Course, _ = r.courseRepo.FindById(courseId)
|
||||
return officeHour, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"crypto/rand"
|
||||
"database/sql"
|
||||
"html/template"
|
||||
"log"
|
||||
"math/big"
|
||||
"net/smtp"
|
||||
"sprechstundentool/models"
|
||||
|
|
|
@ -2,16 +2,31 @@ package sqldb
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
// ConnectDB opens a connection to the database
|
||||
func ConnectDB() *sql.DB {
|
||||
db, err := sql.Open("sqlite3", "sprechstunden.db")
|
||||
func ConnectSQLite(file string) *sql.DB {
|
||||
db, err := sql.Open("sqlite3", file)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return db
|
||||
}
|
||||
|
||||
func ConnectMysql(connection string) *sql.DB {
|
||||
db, err := sql.Open("mysql", connection)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = db.Ping()
|
||||
// handle error
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
From: Mathebau Sprechstunden <sprechstunden@mathebau.de>
|
||||
To: {{.OfficeHour.Tutor.Email}}
|
||||
Subject: Sprechstunde {{if eq .Action 1}}anlegen{{end}}{{if eq .Action 2}}löschen{{end}}
|
||||
|
||||
|
@ -7,8 +8,9 @@ mit deiner Emailadresse soll eine Sprechstunde mit folgenden Daten {{if eq .Acti
|
|||
|
||||
{{.OfficeHour.Course.Name}}
|
||||
{{DayName .OfficeHour.Date.Day}}
|
||||
{{printf "%02d".OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} Uhr bis {{printf "%02d" .OfficeHour.EndDate.Hour}}:{{printf "%02d" .OfficeHour.EndDate.Minute}} Uhr
|
||||
{{printf "%02d" .OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} Uhr bis {{printf "%02d" .OfficeHour.EndDate.Hour}}:{{printf "%02d" .OfficeHour.EndDate.Minute}} Uhr
|
||||
{{.OfficeHour.Tutor.Name}}
|
||||
{{.OfficeHour.Room.Name}}
|
||||
|
||||
Falls dies richtig ist, so bestätige die Sprechstunde durch Abrufen der folgenden URL:
|
||||
https://sprechstunden.mathebau.de/confirmRequest?code={{.Secret}}
|
||||
|
|
Loading…
Reference in a new issue