first commit
This commit is contained in:
commit
c1867d63d0
|
|
@ -0,0 +1,3 @@
|
||||||
|
module gittea.marcokittel.de/Playground/Datenbank/intern
|
||||||
|
|
||||||
|
go 1.24.3
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package intern
|
||||||
|
|
||||||
|
type IVertragsRepository interface {
|
||||||
|
GetAllContracts() []Vertrag
|
||||||
|
GetContractById(id int) Vertrag
|
||||||
|
}
|
||||||
|
|
||||||
|
type Vertrag struct {
|
||||||
|
Id int
|
||||||
|
Data string
|
||||||
|
}
|
||||||
|
|
||||||
|
type vertragsRepository struct {
|
||||||
|
Vertraege []Vertrag
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *vertragsRepository) GetAllContracts() []Vertrag {
|
||||||
|
return v.Vertraege
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *vertragsRepository) GetContractById(id int) Vertrag {
|
||||||
|
return v.Vertraege[id]
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVertragsRepository() IVertragsRepository {
|
||||||
|
con := []Vertrag{
|
||||||
|
Vertrag{Id: 1, Data: "Kunde Kling und Bert GmbH"},
|
||||||
|
Vertrag{Id: 2, Data: "Kunde Wäscherei Puth und Frank"},
|
||||||
|
Vertrag{Id: 3, Data: "Sören Handwerk und Sanitär"},
|
||||||
|
}
|
||||||
|
v := vertragsRepository{Vertraege: con}
|
||||||
|
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
module gittea.marcokittel.de/Playground/Datenbank/kunde
|
||||||
|
|
||||||
|
go 1.24.3
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package kunde
|
||||||
|
|
||||||
|
type IMeldungsRepository interface {
|
||||||
|
AddAmount(menge int)
|
||||||
|
GetAllAmount() []Meldung
|
||||||
|
}
|
||||||
|
|
||||||
|
type Meldung struct {
|
||||||
|
Id int
|
||||||
|
Data int
|
||||||
|
}
|
||||||
|
|
||||||
|
type meldungsRepository struct {
|
||||||
|
Meldungen []Meldung
|
||||||
|
i int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *meldungsRepository) AddAmount(menge int) {
|
||||||
|
m.i++
|
||||||
|
m.Meldungen = append(m.Meldungen, Meldung{Id: m.i, Data: menge})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *meldungsRepository) GetAllAmount() []Meldung {
|
||||||
|
return m.Meldungen
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMeldungsRepository() IMeldungsRepository {
|
||||||
|
m := meldungsRepository{Meldungen: make([]Meldung, 0), i: 0}
|
||||||
|
return &m
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package kunde
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMeldungRepo(t *testing.T) {
|
||||||
|
m := NewMeldungsRepository()
|
||||||
|
m.AddAmount(1)
|
||||||
|
if len(m.GetAllAmount()) != 1 || m.GetAllAmount()[0].Id != 1 {
|
||||||
|
t.Errorf("Error, Element of first Meldung should have id %d, but has %d", 1, m.GetAllAmount()[0].Id)
|
||||||
|
}
|
||||||
|
m.AddAmount(20)
|
||||||
|
if len(m.GetAllAmount()) != 2 || m.GetAllAmount()[1].Id != 2 || m.GetAllAmount()[1].Data != 20 {
|
||||||
|
t.Errorf("Error, Element of second Meldung should have id %d, but has %d, and amount should be 20, but is %d", 1, m.GetAllAmount()[0].Id, m.GetAllAmount()[1].Data)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue