*DB.ReadAll() hinzugefügt
This commit is contained in:
parent
b13eba8008
commit
8ae3019b9c
2
main.go
2
main.go
@ -17,8 +17,8 @@ func writeBriefing(ch chan *types.Briefing, db *db.DB) {
|
||||
|
||||
func main() {
|
||||
var i, j int64
|
||||
|
||||
i, j = 1, 1
|
||||
|
||||
mux := http.NewServeMux()
|
||||
cb := make(chan *types.Briefing)
|
||||
|
||||
|
@ -86,6 +86,31 @@ func (db *DB) WriteBriefing(b *types.Briefing) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DB) ReadAll() (*[]types.Briefing, error) {
|
||||
bs := make([]types.Briefing, 0)
|
||||
|
||||
rows, err := db.Query("SELECT *" + " FROM " + db.Name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("*DB.ReadAll: db.Query(\"SELECT * FROM \"+db.Name): %v\n", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
b := new(types.Briefing)
|
||||
p := new(types.Participant)
|
||||
|
||||
if err := rows.Scan(&p.ID, &b.FirstName, &b.LastName, &b.Date, &b.Time,
|
||||
&b.State, &b.Location, &p.FirstName, &p.LastName, &p.Company); err != nil {
|
||||
return nil, fmt.Errorf("*DB.ReadAll: db.Query(): %v\n", err)
|
||||
}
|
||||
|
||||
b.Participants = append(b.Participants, *p)
|
||||
bs = append(bs, *b)
|
||||
}
|
||||
|
||||
return &bs, nil
|
||||
}
|
||||
|
||||
func (db *DB) ReadByName(name string) (*[]types.Briefing, error) {
|
||||
bs := make([]types.Briefing, 0)
|
||||
|
||||
|
@ -10,14 +10,14 @@ import (
|
||||
|
||||
func DisplayForm(i *int64) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("templates/index.html")).Execute(w, i)
|
||||
template.Must(template.ParseFiles("templates/form.html")).Execute(w, i)
|
||||
}
|
||||
}
|
||||
|
||||
func AddParticipant(i *int64) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
*i++
|
||||
template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i)
|
||||
template.Must(template.ParseFiles("templates/form.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user