Besucher auf Struct umgeschrieben

This commit is contained in:
Husky
2022-01-04 19:30:34 +01:00
parent d0bc77271e
commit 8c814daf48
5 changed files with 36 additions and 13 deletions

View File

@@ -4,7 +4,6 @@ import (
"encoding/json"
"io"
"io/ioutil"
"log"
"net/http"
"git.cosysda.de/HuskyTeufel/Hochzeit/planner"
@@ -21,8 +20,8 @@ func AddBesucherHandler(c *gin.Context) {
c.JSON(statusCode, err)
return
}
log.Println("Besucher hinzugefügt" + besucherItem.Message)
c.JSON(statusCode, gin.H{"id": planner.Add(besucherItem.Message)})
c.JSON(statusCode, gin.H{"id": planner.Add(besucherItem)})
}
func DeleteBesucherHandler(c *gin.Context) {

View File

@@ -27,8 +27,8 @@ func Get() []Besucher {
}
// Add will add a new Besucher
func Add(message string) string {
t := newBesucher(message)
func Add(newClient Besucher) string {
t := newBesucher(newClient)
mtx.Lock()
list = append(list, t)
mtx.Unlock()
@@ -66,10 +66,11 @@ func isMatchingID(a, b string) bool {
return a == b
}
func newBesucher(message string) Besucher {
func newBesucher(newBesucher Besucher) Besucher {
return Besucher{
ID: xid.New().String(),
Message: message,
Come: false,
Name: newBesucher.Name,
Message: newBesucher.Message,
Come: newBesucher.Come,
}
}

View File

@@ -0,0 +1,9 @@
.example-radio-group {
display: flex;
flex-direction: column;
margin: 15px 0;
}
.example-radio-button {
margin: 5px;
}

View File

@@ -16,11 +16,14 @@
</table>
<input placeholder="Ihre Name..." [(ngModel)]="BesucherName">
<input placeholder="Eventuell eine Nachricht" [(ngModel)]="BesucherMessage">
<input placeholder="Eventuell eine Nachricht" [(ngModel)]="BesucherMessage"><br />
<label id="zusage-radio-button-group-label">Kommen Sie</label>
<mat-radio-group>
<mat-radio-button value="1">Ja</mat-radio-button>
<mat-radio-button value="0">Nein</mat-radio-button>
<mat-radio-group
aria-labelledby="zusage-radio-button-group-label"
class="example-radio-group"
[(ngModel)]="BesucherKommtRadio"
>
<mat-radio-button class="example-radio-button" *ngFor="let entscheidung of kommt" [value]="entscheidung">{{entscheidung}}</mat-radio-button>
</mat-radio-group>
<button class="btn btn-primary" (click)="addBesucher()">Abschicken</button>

View File

@@ -5,6 +5,7 @@ import { filter } from 'rxjs';
import { BesucherService } from '../besucher.service';
import { Besucher } from 'src/besucher';
@Component({
selector: 'app-besucher',
templateUrl: './besucher.component.html',
@@ -17,8 +18,12 @@ export class BesucherComponent implements OnInit {
kommendeBesuchers: Besucher[] = [];
BesucherName: string = "";
BesucherMessage: string = "";
BesucherKommt: boolean = false;
BesucherKommtRadio: string = "";
kommt: string[] = ['Ja','Nein'];
constructor(private besucherService: BesucherService) { }
ngOnInit(): void {
@@ -48,8 +53,9 @@ export class BesucherComponent implements OnInit {
name : this.BesucherName,
message : this.BesucherMessage,
id: '',
come : this.BesucherKommt
come : this.convertBesucherkommtStringToBoolean(this.BesucherKommtRadio)
};
console.log(newBesucher.come);
this.besucherService.addBesucher(newBesucher).subscribe(() => {
this.getAll();
this.BesucherMessage = '';
@@ -57,4 +63,9 @@ export class BesucherComponent implements OnInit {
}
convertBesucherkommtStringToBoolean(input: string) : boolean {
return input == this.kommt[0]
}
}