0

Please or Register to create posts and topics.

How to replace the hard coded demoNotification with sql server data

i created a class notification.cs in the backend with repository and controller and could successfully get and post with api/notification, however,

in the notification-endpoint.service tried to replace with api but could not be applied. could you help please?

This is so unclear and it misses a lot of information.

What's happening, what's the error message, what's your api, ...?

in the notifications-endpoint.service  i replace demoNotifications with

export class NotificationEndpoint {
demoNotifications: any[];
constructor (private http: HttpClient){
}
getNotificaitons(){
constdemoNotifications=this.http.get('api/notifications').subscribe((demonotifications:any[])=>demonotifications=this.demoNotifications)
returnthis.demoNotifications
}
when i ran the app, demoNotifications is undefined and the notifications show no data although in the back there have been data uploaded

The endpoint provides access to the api endpoint (your backend rest api). You're mixing things.

Example:

The customer controller class has a method to get all the CustomersData from the DB

There's a GET on the rest api "/api/customers"

// GET: api/values
[HttpGet]
public IActionResult Get()
{
var allCustomers = _unitOfWork.Customers.GetAllCustomersData();
return Ok(Mapper.Map<IEnumerable<CustomerViewModel>>(allCustomers));
}

The endpoint service contains the urls to the backend rest api:

export class CustomerEndpoint extends EndpointFactory {

private readonly _customersUrl: string = "/api/customer";
private readonly _currentCustomerUrl: string = "/api/customer";

get customersUrl() { return this.configurations.baseUrl + this._customersUrl; }

constructor(http: HttpClient, configurations: ConfigurationService, injector: Injector) {

super(http, configurations, injector);
}

getCustomersEndpoint<T>(page?: number, pageSize?: number): Observable<T> {
let endpointUrl = page && pageSize ? `${this.customersUrl}/${page}/${pageSize}` : this.customersUrl;

return this.http.get<T>(endpointUrl, this.getRequestHeaders())
.catch(error => {
return this.handleError(error, () => this.getCustomersEndpoint(page, pageSize));
});
}

The service provides you a method to get the customers. the service uses the endpoint url

@Injectable()
export class CustomerService {

constructor(
private router: Router,
private http: HttpClient,
private authService: AuthService,
private customerEndpoint: CustomerEndpoint) { }

getCustomers(page?: number, pageSize?: number) {

return this.customerEndpoint.getCustomersEndpoint<Customer[]>(page, pageSize);
}

You could have a customers page that when it's accessed it loads the customers data. The ts contains the service, on that service it calls the getCustomers

private loadData() {
this.alertService.startLoadingMessage();
this.loadingIndicator = true;

this.customerService.getCustomers().subscribe(
results => this.onDataLoadSuccessful(results),
error => this.onDataLoadFailed(error)
);
}

When it loads successfully they are assigned to the datasource

private onDataLoadSuccessful(customers: Customer[]) {
this.alertService.stopLoadingMessage();
this.loadingIndicator = false;
this.dataSource.data = customers;

}

Thank you for your support,,

with this implementation notificationEndpoint still expects a data source rather than an obsevable in line

let notification=this.demoNotifications.find(val =>val.id ==notificationId);
where
demoNotifications: Notification[]
the page is modified as
demoNotifications: Notification[]
private readonly _notificationsUrl:string="api/notifications";
getnotificationsUrl() {
return this.configurations.baseUrl+this._notificationsUrl;
}
constructor(http: HttpClient, configurations: ConfigurationService, injector: Injector) {
super(http, configurations, injector);
}
getNotificationsEndpoint<T>(page?:number, pageSize?:number): Observable<T> {
letendpointUrl=page&&pageSize?`{this.notificationUrl}/${page}/${pageSize}`:this.notificationsUrl;
returnthis.http.get<T>(endpointUrl, this.getRequestHeaders())
.catch(error => {
returnthis.handleError(error, () =>this.getNotificationsEndpoint(page,pageSize));
});
}
getNotifications(page?:number, pageSize?:number){
return this.getNotificationsEndpoint<Notification[]>(page,pageSize)
}

Could you zip your code, remove any passwords, user id, ip address for the connectionstring and mail if there's one and send it to alve.eben@gmail.com so I can have a look?

We're still missing informations.

Thanks again for your support, i was trying to fix it with no luck, please see attached project, the url is api/notifications

I couldnot send the zip file to the email, it get an error not allowing zip files

I had an invitatin ot github repo

https://github.com/QadMohKuwait/Quick-App-Pro/invitations