diff --git a/client/src/app/app-routing.module.ts b/client/src/app/app-routing.module.ts index c0d5aee6accce093ad52baea26114c3967440b19..bb9568bf3c30fcc14fb8192eb2dae239f7a09a9f 100644 --- a/client/src/app/app-routing.module.ts +++ b/client/src/app/app-routing.module.ts @@ -7,6 +7,7 @@ import { UserRegistrationFormComponent } from './users/user-registration-form/us import { UserLoginFormComponent } from './users/user-login-form/user-login-form.component'; import { UserProfileComponent } from './users/user-profile/user-profile.component'; import { UserGuestProfileComponent } from './users/user-guest-profile/user-guest-profile.component'; +import { AdminCategoryComponent} from './categories/admin-category/admin-category.component'; const routes: Routes = [ { path: 'annonse/ny', component: PostFormComponent }, @@ -17,7 +18,9 @@ const routes: Routes = [ { path: 'user/:id', component: UserGuestProfileComponent }, { path: 'profile', component: UserProfileComponent }, { path: 'register', component: UserRegistrationFormComponent }, - { path: 'login', component: UserLoginFormComponent } + { path: 'login', component: UserLoginFormComponent }, + + { path: 'admin/category', component: AdminCategoryComponent } ]; @NgModule({ diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 9b89086876c53bd68002c6c0fab318564f4e388b..24d3015303fc751dc4dc4704ebc0645abee80615 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts @@ -9,6 +9,7 @@ import { PostModule } from './posts/post.module'; import { UserModule } from './users/user.module'; import { AuthModule } from './authentication/auth.module'; import { SharedModule } from './shared/shared.module'; +import { AdminCategoryComponent } from './categories/admin-category/admin-category.component'; export function tokenGetter() { return localStorage.getItem("token"); @@ -16,7 +17,8 @@ export function tokenGetter() { @NgModule({ declarations: [ - AppComponent + AppComponent, + AdminCategoryComponent ], imports: [ BrowserModule, diff --git a/client/src/app/categories/admin-category/admin-category.component.html b/client/src/app/categories/admin-category/admin-category.component.html new file mode 100644 index 0000000000000000000000000000000000000000..bdbf67b78318dff4188c6b8894ee27e6b1df1b15 --- /dev/null +++ b/client/src/app/categories/admin-category/admin-category.component.html @@ -0,0 +1 @@ +<p>admin-category works!</p> diff --git a/client/src/app/categories/admin-category/admin-category.component.scss b/client/src/app/categories/admin-category/admin-category.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/client/src/app/categories/admin-category/admin-category.component.spec.ts b/client/src/app/categories/admin-category/admin-category.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..7797ede96970af79e86b55bc3119de12797750d0 --- /dev/null +++ b/client/src/app/categories/admin-category/admin-category.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AdminCategoryComponent } from './admin-category.component'; + +describe('AdminCategoryComponent', () => { + let component: AdminCategoryComponent; + let fixture: ComponentFixture<AdminCategoryComponent>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ AdminCategoryComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(AdminCategoryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/client/src/app/categories/admin-category/admin-category.component.ts b/client/src/app/categories/admin-category/admin-category.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..526d7de0cf11fcf8a18694d8d03d27d33588d754 --- /dev/null +++ b/client/src/app/categories/admin-category/admin-category.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-admin-category', + templateUrl: './admin-category.component.html', + styleUrls: ['./admin-category.component.scss'] +}) +export class AdminCategoryComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/client/src/app/posts/post.service.ts b/client/src/app/posts/post.service.ts index 63ea70293f18426b7d0e13beb466bd2ec29b4b4f..5a90bf8ddaddf6acc5ae34274a3abf9f0b373189 100644 --- a/client/src/app/posts/post.service.ts +++ b/client/src/app/posts/post.service.ts @@ -104,7 +104,30 @@ export class PostService { private add_post(post: Post) { return this.http.post(this.postUrl, post.serialize()); } + /** + * Adds category to database + */ + addCategory(category: Category): Promise<string> { + return new Promise<string>( + (resolve, reject) => { + this.add_category(category).subscribe((data: any) => { + try { + resolve(data.status); + } catch (err: any) { + reject(err); + } + }, + (err: any) => { + console.log(err.message); + reject(err); + }); + } + ); + } + private add_category(category: Category) { + return this.http.post(this.categoryUrl, category.serialize()); + } /** * Get all categories from database.