AP-45 wip post request

This commit is contained in:
Huffle 2025-05-18 08:52:20 +02:00
parent b5aae3be3d
commit a675d51718
3 changed files with 15 additions and 1 deletions

View File

@ -20,4 +20,5 @@
>{{ task.reward.toFixed(2) }} SP</div>
</div>
</div>
<button (click)="createTask()">ADD</button>
</ion-content>

View File

@ -21,4 +21,7 @@ export class TasksPage implements OnInit {
});
}
createTask() {
this.taskService.createTask({ name: 'Created task', reward: 10, assigned: 1 });
}
}

View File

@ -7,10 +7,20 @@ import { Task } from '../models/task';
providedIn: 'root'
})
export class TaskService {
private url = 'http://localhost:8080/api'
private url = 'http://localhost:8080/api';
private headers = {
"access-control-allow-origin": "*",
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
'Access-Control-Allow-Methods': '*',
};
constructor(private http: HttpClient) {}
getTaskList(): Observable<Array<Task>> {
return this.http.get<Task[]>(`${this.url}/tasks`);
}
createTask(task: Partial<Task>) {
this.http.post(`${this.url}/tasks`, task, { headers: this.headers }).subscribe(t => console.log('TEST: ', t));
}
}