-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
ff9b822
commit 2ce990e
Showing
9 changed files
with
106 additions
and
52 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
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
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
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
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
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,18 +1,43 @@ | ||
import { User } from "../models/User"; | ||
|
||
// Generics Class | ||
export class UserManager <T extends User> { | ||
// User import | ||
private users: T[] = []; | ||
export class UserManager<T extends User> { | ||
// User import | ||
private users: T[] = []; | ||
|
||
// addUser | ||
public addUser(user: T): void { | ||
this.users.push(user); | ||
} | ||
// Kullanıcı Ekle | ||
public addUser(user: T): void { | ||
this.users.push(user); | ||
} | ||
|
||
// Bütün Kullanıcıları Getir | ||
public listUsers(): T[] { | ||
return this.users; | ||
} | ||
// Kullanıcıları Listele | ||
public listUsers(): T[] { | ||
return this.users; | ||
} | ||
|
||
// Kullanıcıyı Username Göre Bul | ||
public findUserByUsername(username: string): T | undefined { | ||
return this.users.find((u) => u.getUsername() === username); | ||
} | ||
|
||
} // end of class UserManager | ||
// Kullanıcıyı Username Göre Bul | ||
public findUserByUserId(userId: number): T | undefined { | ||
return this.users.find((u) => u.getId() === userId); | ||
} | ||
|
||
// Kullanıcı Obje'ye Göre Sil | ||
public removeUser(user: T): void { | ||
const index = this.users.indexOf(user); | ||
this.users.splice(index, 1); | ||
} | ||
|
||
// Kullanıcı ID'ye Göre Sil | ||
public removeUserById(userId: number): boolean { | ||
const user = this.users.findIndex((u) => u.getId() === userId); | ||
if (user !== -1) { | ||
this.users.splice(user, 1); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} // end of class UserManager |
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
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
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,5 @@ | ||
enum UserRole { | ||
User = "User", | ||
Admin = "Admin", | ||
Moderator = "Moderator", | ||
} |