-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
200 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/app/components/restaurants/restaurant-card/restaurant-card.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<mat-card | ||
*ngIf="restaurant" | ||
class="max-w-72 rounded overflow-hidden shadow-lg"> | ||
<img | ||
class="mb-4" | ||
mat-card-image | ||
[src]="coverPhoto" | ||
alt="{{ restaurant.name }}" /> | ||
<mat-card-content> | ||
<div class="font-bold text-xl mb-2">{{ restaurant.name }}</div> | ||
<p class="text-gray-700 text-base">{{ restaurant.description }}</p> | ||
<p class="text-gray-700 text-sm mt-2"> | ||
{{ restaurant.location.streetAddress }}, | ||
{{ restaurant.location.city }}, {{ restaurant.location.province }}, | ||
{{ restaurant.location.country }} | ||
</p> | ||
</mat-card-content> | ||
<mat-card-content> | ||
<span | ||
class="inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2" | ||
*ngFor="let cuisine of restaurant.cuisines" | ||
>{{ cuisine.name }}</span | ||
> | ||
</mat-card-content> | ||
|
||
<mat-card-actions> | ||
<button | ||
mat-stroked-button | ||
color="accent" | ||
disableRipple="true" | ||
>View Details</button | ||
> | ||
</mat-card-actions> | ||
</mat-card> |
Empty file.
21 changes: 21 additions & 0 deletions
21
src/app/components/restaurants/restaurant-card/restaurant-card.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RestaurantCardComponent } from './restaurant-card.component'; | ||
|
||
describe('RestaurantCardComponent', () => { | ||
let component: RestaurantCardComponent; | ||
let fixture: ComponentFixture<RestaurantCardComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [RestaurantCardComponent], | ||
}); | ||
fixture = TestBed.createComponent(RestaurantCardComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/app/components/restaurants/restaurant-card/restaurant-card.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { Restaurant } from 'src/app/models/restaurant'; | ||
|
||
@Component({ | ||
selector: 'restaurant-card', | ||
templateUrl: './restaurant-card.component.html', | ||
styleUrls: ['./restaurant-card.component.scss'], | ||
}) | ||
export class RestaurantCardComponent { | ||
@Input() restaurant: Restaurant; | ||
private DEFAULT_COVER_PHOTO_URL = 'assets/images/RestaurantCover.jpg'; | ||
|
||
get coverPhoto(): string { | ||
return this.restaurant?.coverPhotoUri ?? this.DEFAULT_COVER_PHOTO_URL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ProfileUser } from './user'; | ||
|
||
export type Restaurants = Restaurant[]; | ||
|
||
export class Restaurant { | ||
_id: string; | ||
ownerId: string; | ||
name: string; | ||
description?: string; | ||
location: RestaurantLocation; | ||
coverPhotoUri: string; | ||
photoUris?: string[]; | ||
staffMembers: ProfileUser[]; | ||
layout: { | ||
length: string; | ||
width: string; | ||
}; | ||
cuisines: Cuisine[]; | ||
|
||
constructor(data: any) { | ||
this._id = data?._id ?? null; | ||
this.ownerId = data?.ownerId ?? null; | ||
this.name = data?.name ?? null; | ||
this.description = data?.description ?? null; | ||
this.location = data?.location ?? null; | ||
this.coverPhotoUri = data?.coverPhotoUri ?? null; | ||
this.photoUris = data?.photoUris ?? null; | ||
this.staffMembers = data?.staffMembers ?? null; | ||
this.layout = data?.layout ?? null; | ||
this.cuisines = data?.cuisines ?? null; | ||
} | ||
} | ||
|
||
export interface Cuisine { | ||
_id: string; | ||
name: string; | ||
imageUrl: string; | ||
} | ||
|
||
export interface RestaurantLocation { | ||
streetAddress: string; | ||
city: string; | ||
province: string; | ||
country: string; | ||
postal: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
src/app/pages/manage-restaurants/manage-restaurants.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
<div class="min-h-screen container-80 p-4"> | ||
<!-- Header --> | ||
<section class="flex justify-between flex-wrap gap-5"> | ||
<h2 class="font-bold text-3xl">Manage Restuarants</h2> | ||
<h2 class="font-bold text-3xl">Manage Restaurants</h2> | ||
<button | ||
mat-button | ||
mat-flat-button | ||
[disableRipple]="true" | ||
color="accent"> | ||
<mat-icon>add</mat-icon>Add Restaurant</button | ||
> | ||
</section> | ||
|
||
<!-- Owned Restaurants --> | ||
<section class="flex flex-wrap gap-5 mt-8 justify-center lg:justify-start"> | ||
<restaurant-card | ||
*ngFor="let restaurant of restaurants" | ||
[restaurant]="restaurant"></restaurant-card> | ||
</section> | ||
</div> |
36 changes: 34 additions & 2 deletions
36
src/app/pages/manage-restaurants/manage-restaurants.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,40 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit, inject } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { Restaurants } from 'src/app/models/restaurant'; | ||
import { RestaurantsService } from 'src/app/services/restaurants.service'; | ||
|
||
@Component({ | ||
selector: 'manage-restaurants', | ||
templateUrl: './manage-restaurants.component.html', | ||
styleUrls: ['./manage-restaurants.component.scss'], | ||
}) | ||
export class ManageRestaurantsComponent {} | ||
export class ManageRestaurantsComponent implements OnInit { | ||
// Services | ||
restaurantsService = inject(RestaurantsService); | ||
|
||
// Props | ||
restaurants: Restaurants; | ||
|
||
ngOnInit(): void { | ||
// For now | ||
// this.getOwnedRestaurants(); | ||
this.getAllRestaurants(); | ||
} | ||
|
||
getOwnedRestaurants() { | ||
this.restaurantsService | ||
.getOwnedRestaurants() | ||
.subscribe((restaurants) => { | ||
this.restaurants = restaurants ?? []; | ||
}); | ||
} | ||
|
||
// Just to test for now | ||
getAllRestaurants() { | ||
this.restaurantsService.getRestaurants().subscribe((res) => { | ||
this.restaurants = res?.restaurants ?? []; | ||
|
||
console.log(this.restaurants); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { filter, map } from 'rxjs'; | ||
import { environment } from 'src/environments/environment.development'; | ||
import { UserService } from './user.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class RestaurantsService { | ||
private API_URL = environment.apiUrl; | ||
|
||
constructor( | ||
private http: HttpClient, | ||
private userService: UserService, | ||
) {} | ||
|
||
getRestaurants() { | ||
const url = `${this.API_URL}/api/restaurants`; | ||
|
||
return this.http.get<any>(url); | ||
} | ||
|
||
getOwnedRestaurants() { | ||
return this.getRestaurants().pipe( | ||
map((data) => data?.restaurants), | ||
map((restaurants) => { | ||
return restaurants.filter( | ||
(restaurant) => | ||
restaurant.ownerId === | ||
this.userService.currentUser()?.uid, | ||
); | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters