diff --git a/package.json b/package.json index dff9520..0f482ad 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "todolist-site", + "name": "confess-site", "version": "0.0.0", "scripts": { "ng": "ng", diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 143258f..8a53d72 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -14,16 +14,16 @@ describe('AppComponent', () => { expect(app).toBeTruthy(); }); - it(`should have the 'todolist-site' title`, () => { + it(`should have the 'confess-site' title`, () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.componentInstance; - expect(app.title).toEqual('todolist-site'); + expect(app.title).toEqual('confess-site'); }); it('should render title', () => { const fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('h1')?.textContent).toContain('Hello, todolist-site'); + expect(compiled.querySelector('h1')?.textContent).toContain('Hello, confess-site'); }); }); diff --git a/src/app/confess-detail/confess-detail.component.css b/src/app/confess-detail/confess-detail.component.css deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/confess-detail/confess-detail.component.html b/src/app/confess-detail/confess-detail.component.html deleted file mode 100644 index 0dee9a5..0000000 --- a/src/app/confess-detail/confess-detail.component.html +++ /dev/null @@ -1,55 +0,0 @@ -
-

{{ todo.title }}

-

{{ todo.description || 'Deskripsi tidak tersedia' }}

- - -
- Tanggal Tenggat: -

Tanggal : {{ todo.dueDate | date:'short' }}

-
- - -
- Pengguna: - {{ todo.user.username || 'Pengguna tidak tersedia' }} -
- - -
- Dibuat pada: - {{ todo.createdAt ? (todo.createdAt | date: 'short') : 'Tanggal tidak tersedia' }} -
- - -
-

Komentar

- - -
-
- {{ comment.user.username }} - {{ comment.createdAt | date: 'short' }} -
-

{{ comment.text }}

-
- - -
- - -
-
-
- - -
- {{ errorMessage }} -
diff --git a/src/app/confess-detail/confess-detail.component.spec.ts b/src/app/confess-detail/confess-detail.component.spec.ts deleted file mode 100644 index 6d8d646..0000000 --- a/src/app/confess-detail/confess-detail.component.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { ConfessDetailComponent } from './confess-detail.component'; - -describe('ConfessDetailComponent', () => { - let component: ConfessDetailComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [ConfessDetailComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(ConfessDetailComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/confess-detail/confess-detail.component.ts b/src/app/confess-detail/confess-detail.component.ts deleted file mode 100644 index 46ea4ed..0000000 --- a/src/app/confess-detail/confess-detail.component.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { Component, OnInit } from '@angular/core'; -import { Todo } from '../models/todo.model'; -import { TodosService } from '../services/todos.service'; -import { ActivatedRoute } from '@angular/router'; -import { CommonModule, DatePipe } from '@angular/common'; -import { FormsModule } from '@angular/forms'; - -@Component({ - selector: 'app-todo-detail', - standalone: true, - imports: [CommonModule, DatePipe, FormsModule], - templateUrl: './confess-detail.component.html', - styleUrls: ['./confess-detail.component.css'], - providers: [DatePipe] -}) -export class TodoDetailComponent implements OnInit { - todo: Todo | null = null; - newCommentText: string = ''; // To bind new comment input - errorMessage: string = ''; - - constructor( - private todosService: TodosService, - private route: ActivatedRoute, - private datePipe: DatePipe - ) {} - - ngOnInit(): void { - const todoId = this.route.snapshot.paramMap.get('id'); - if (todoId) { - this.loadTodoDetail(todoId); - } - } - - loadTodoDetail(id: string): void { - this.todosService.getTodoById(id).subscribe( - (todo) => { - this.todo = todo; - }, - (error) => { - console.error('Error loading todo detail:', error); - this.errorMessage = 'Gagal memuat detail Todo. Silakan coba lagi nanti.'; - } - ); - } - - addComment(todoId: string): void { - if (!this.newCommentText.trim()) { - alert('Komentar tidak boleh kosong'); - return; - } - - this.todosService.addComment(todoId, this.newCommentText).subscribe( - (updatedTodo) => { - this.todo = updatedTodo; // Update the todo with the new comment - this.newCommentText = ''; // Clear the textarea after submitting - }, - (error) => { - console.error('Error adding comment:', error); - this.errorMessage = 'Gagal menambahkan komentar. Silakan coba lagi nanti.'; - } - ); - } -} diff --git a/src/app/models/todo.model.ts b/src/app/models/todo.model.ts deleted file mode 100644 index 7629353..0000000 --- a/src/app/models/todo.model.ts +++ /dev/null @@ -1,23 +0,0 @@ -export interface Comment { - user: { username: string; email: string }; // Atau objek user yang lebih lengkap jika diperlukan - text: string; - createdAt: string; // Tanggal pembuatan komentar -} - -export interface Todo { - _id: string; - title: string; - description: string; - dueDate: Date; - user: { username: string; email: string }; - category: { name: string }; - isEditing?: boolean; - createdAt: string; - liked: boolean; - comments: Comment[]; // Menambahkan properti comments yang merupakan array dari Comment -} - -export interface TodoResponse { - message: string; - todos: Todo[]; -} diff --git a/src/app/services/todos.service.ts b/src/app/services/todos.service.ts deleted file mode 100644 index ccea5a1..0000000 --- a/src/app/services/todos.service.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; -import { Observable } from 'rxjs'; -import { TodoResponse, Todo } from '../models/todo.model'; // Pastikan model sudah sesuai -import { UserService } from './user.service'; -import { environment } from '../environments/environment'; - -export interface User { - username: string; - email: string; -} - -export interface Category { - name: string; -} - -@Injectable({ - providedIn: 'root', -}) -export class TodosService { - private apiUrl = environment.apiUrl; // URL API dari environment - - constructor(private http: HttpClient, private userService: UserService) {} - - // Mendapatkan username dari localStorage - getUsername(): string | null { - return localStorage.getItem('username'); - } - - // Mendapatkan user ID dari localStorage - getUserId(): string | null { - return localStorage.getItem('userId'); - } - - // Mendapatkan semua Todo - getTodos(): Observable { - return this.http.get(`${this.apiUrl}/todos`); - } - - // Mendapatkan detail Todo berdasarkan ID - getTodoById(id: string): Observable { - return this.http.get(`${this.apiUrl}/todos/${id}`); - } - - // Memperbarui Todo - updateTodo(id: string, updatedData: Partial): Observable { - return this.http.put(`${this.apiUrl}/todos/${id}`, updatedData); - } - - // Menghapus Todo - deleteTodo(id: string): Observable { - return this.http.delete(`${this.apiUrl}/todos/${id}`); - } - - // Menambahkan komentar ke Todo - addComment(todoId: string, comment: string): Observable { - const payload = { comment }; // Data yang dikirim ke API - return this.http.post(`${this.apiUrl}/todos/${todoId}/comments`, payload); - } -}