Spaces:
Sleeping
Sleeping
Commit ·
c49ed24
1
Parent(s): 342a1e4
feat: update book and user models, enhance subscription management with admin features, and modify connection string
Browse files- LibraryManagement.Backend/Features/Books/BookService.cs +5 -7
- LibraryManagement.Backend/Features/Subscriptions/SubscriptionController.cs +27 -2
- LibraryManagement.Backend/Features/Subscriptions/SubscriptionModels.cs +6 -0
- LibraryManagement.Backend/Features/Users/UserService.cs +7 -1
- LibraryManagement.Backend/appsettings.json +2 -1
LibraryManagement.Backend/Features/Books/BookService.cs
CHANGED
|
@@ -49,7 +49,6 @@ namespace LibraryManagement.Backend.Features.Books
|
|
| 49 |
Isbn = request.Isbn,
|
| 50 |
Author = request.Author,
|
| 51 |
Description = request.Description,
|
| 52 |
-
CoverUrl = request.CoverUrl,
|
| 53 |
TotalCopies = request.TotalCopies,
|
| 54 |
AvailableCopies = request.TotalCopies,
|
| 55 |
Status = request.TotalCopies > 0 ? "Available" : "Out Of Stock",
|
|
@@ -71,7 +70,6 @@ namespace LibraryManagement.Backend.Features.Books
|
|
| 71 |
book.Title = request.Title;
|
| 72 |
book.Author = request.Author;
|
| 73 |
book.Description = request.Description;
|
| 74 |
-
book.CoverUrl = request.CoverUrl;
|
| 75 |
|
| 76 |
// Basic logic to sync availability when total copies change
|
| 77 |
int difference = request.TotalCopies - book.TotalCopies;
|
|
@@ -108,11 +106,12 @@ namespace LibraryManagement.Backend.Features.Books
|
|
| 108 |
Isbn = book.Isbn,
|
| 109 |
Author = book.Author,
|
| 110 |
Status = book.Status,
|
|
|
|
| 111 |
Description = book.Description,
|
| 112 |
-
CoverUrl = book.CoverUrl,
|
| 113 |
TotalCopies = book.TotalCopies,
|
| 114 |
AvailableCopies = book.AvailableCopies,
|
| 115 |
-
CreatedAt = book.CreatedAt
|
|
|
|
| 116 |
};
|
| 117 |
}
|
| 118 |
}
|
|
@@ -124,11 +123,12 @@ namespace LibraryManagement.Backend.Features.Books
|
|
| 124 |
public string Isbn { get; set; } = string.Empty;
|
| 125 |
public string Author { get; set; } = string.Empty;
|
| 126 |
public string Status { get; set; } = string.Empty;
|
|
|
|
| 127 |
public string? Description { get; set; }
|
| 128 |
-
public string? CoverUrl { get; set; }
|
| 129 |
public int TotalCopies { get; set; }
|
| 130 |
public int AvailableCopies { get; set; }
|
| 131 |
public DateTime CreatedAt { get; set; }
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
public class BookCreateRequest
|
|
@@ -137,7 +137,6 @@ namespace LibraryManagement.Backend.Features.Books
|
|
| 137 |
public string Isbn { get; set; } = string.Empty;
|
| 138 |
public string Author { get; set; } = string.Empty;
|
| 139 |
public string? Description { get; set; }
|
| 140 |
-
public string? CoverUrl { get; set; }
|
| 141 |
public int TotalCopies { get; set; }
|
| 142 |
}
|
| 143 |
|
|
@@ -146,7 +145,6 @@ namespace LibraryManagement.Backend.Features.Books
|
|
| 146 |
public string Title { get; set; } = string.Empty;
|
| 147 |
public string Author { get; set; } = string.Empty;
|
| 148 |
public string? Description { get; set; }
|
| 149 |
-
public string? CoverUrl { get; set; }
|
| 150 |
public int TotalCopies { get; set; }
|
| 151 |
}
|
| 152 |
}
|
|
|
|
| 49 |
Isbn = request.Isbn,
|
| 50 |
Author = request.Author,
|
| 51 |
Description = request.Description,
|
|
|
|
| 52 |
TotalCopies = request.TotalCopies,
|
| 53 |
AvailableCopies = request.TotalCopies,
|
| 54 |
Status = request.TotalCopies > 0 ? "Available" : "Out Of Stock",
|
|
|
|
| 70 |
book.Title = request.Title;
|
| 71 |
book.Author = request.Author;
|
| 72 |
book.Description = request.Description;
|
|
|
|
| 73 |
|
| 74 |
// Basic logic to sync availability when total copies change
|
| 75 |
int difference = request.TotalCopies - book.TotalCopies;
|
|
|
|
| 106 |
Isbn = book.Isbn,
|
| 107 |
Author = book.Author,
|
| 108 |
Status = book.Status,
|
| 109 |
+
IsActive = book.IsActive,
|
| 110 |
Description = book.Description,
|
|
|
|
| 111 |
TotalCopies = book.TotalCopies,
|
| 112 |
AvailableCopies = book.AvailableCopies,
|
| 113 |
+
CreatedAt = book.CreatedAt,
|
| 114 |
+
UpdatedAt = book.UpdatedAt
|
| 115 |
};
|
| 116 |
}
|
| 117 |
}
|
|
|
|
| 123 |
public string Isbn { get; set; } = string.Empty;
|
| 124 |
public string Author { get; set; } = string.Empty;
|
| 125 |
public string Status { get; set; } = string.Empty;
|
| 126 |
+
public bool IsActive { get; set; }
|
| 127 |
public string? Description { get; set; }
|
|
|
|
| 128 |
public int TotalCopies { get; set; }
|
| 129 |
public int AvailableCopies { get; set; }
|
| 130 |
public DateTime CreatedAt { get; set; }
|
| 131 |
+
public DateTime? UpdatedAt { get; set; }
|
| 132 |
}
|
| 133 |
|
| 134 |
public class BookCreateRequest
|
|
|
|
| 137 |
public string Isbn { get; set; } = string.Empty;
|
| 138 |
public string Author { get; set; } = string.Empty;
|
| 139 |
public string? Description { get; set; }
|
|
|
|
| 140 |
public int TotalCopies { get; set; }
|
| 141 |
}
|
| 142 |
|
|
|
|
| 145 |
public string Title { get; set; } = string.Empty;
|
| 146 |
public string Author { get; set; } = string.Empty;
|
| 147 |
public string? Description { get; set; }
|
|
|
|
| 148 |
public int TotalCopies { get; set; }
|
| 149 |
}
|
| 150 |
}
|
LibraryManagement.Backend/Features/Subscriptions/SubscriptionController.cs
CHANGED
|
@@ -23,7 +23,7 @@ namespace LibraryManagement.Backend.Features.Subscriptions
|
|
| 23 |
}
|
| 24 |
|
| 25 |
[HttpGet("subscriptions/me")]
|
| 26 |
-
|
| 27 |
public async Task<ActionResult<SubscriptionDto>> GetMySubscription()
|
| 28 |
{
|
| 29 |
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
@@ -38,7 +38,7 @@ namespace LibraryManagement.Backend.Features.Subscriptions
|
|
| 38 |
}
|
| 39 |
|
| 40 |
[HttpPost("subscriptions/subscribe")]
|
| 41 |
-
|
| 42 |
public async Task<ActionResult<SubscriptionDto>> Subscribe([FromBody] SubscribeRequest request)
|
| 43 |
{
|
| 44 |
try
|
|
@@ -55,5 +55,30 @@ namespace LibraryManagement.Backend.Features.Subscriptions
|
|
| 55 |
return BadRequest(new { message = ex.Message });
|
| 56 |
}
|
| 57 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
}
|
| 59 |
}
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
[HttpGet("subscriptions/me")]
|
| 26 |
+
[Authorize]
|
| 27 |
public async Task<ActionResult<SubscriptionDto>> GetMySubscription()
|
| 28 |
{
|
| 29 |
var userIdStr = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
[HttpPost("subscriptions/subscribe")]
|
| 41 |
+
[Authorize]
|
| 42 |
public async Task<ActionResult<SubscriptionDto>> Subscribe([FromBody] SubscribeRequest request)
|
| 43 |
{
|
| 44 |
try
|
|
|
|
| 55 |
return BadRequest(new { message = ex.Message });
|
| 56 |
}
|
| 57 |
}
|
| 58 |
+
|
| 59 |
+
[HttpGet("subscriptions/user/{userId}")]
|
| 60 |
+
[Authorize(Roles = "Admin")]
|
| 61 |
+
public async Task<ActionResult<SubscriptionDto>> GetUserSubscription(int userId)
|
| 62 |
+
{
|
| 63 |
+
var subscription = await _subscriptionService.GetUserSubscriptionAsync(userId);
|
| 64 |
+
if (subscription == null) return NotFound(new { message = "No active subscription found." });
|
| 65 |
+
|
| 66 |
+
return Ok(subscription);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
[HttpPost("subscriptions/admin-subscribe")]
|
| 70 |
+
[Authorize(Roles = "Admin")]
|
| 71 |
+
public async Task<ActionResult<SubscriptionDto>> AdminSubscribe([FromBody] AdminSubscribeRequest request)
|
| 72 |
+
{
|
| 73 |
+
try
|
| 74 |
+
{
|
| 75 |
+
var subscription = await _subscriptionService.SubscribeUserAsync(request.UserId, request.MembershipId);
|
| 76 |
+
return Ok(subscription);
|
| 77 |
+
}
|
| 78 |
+
catch (Exception ex)
|
| 79 |
+
{
|
| 80 |
+
return BadRequest(new { message = ex.Message });
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
}
|
| 84 |
}
|
LibraryManagement.Backend/Features/Subscriptions/SubscriptionModels.cs
CHANGED
|
@@ -29,4 +29,10 @@ namespace LibraryManagement.Backend.Features.Subscriptions
|
|
| 29 |
{
|
| 30 |
public int MembershipId { get; set; }
|
| 31 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
|
|
|
| 29 |
{
|
| 30 |
public int MembershipId { get; set; }
|
| 31 |
}
|
| 32 |
+
|
| 33 |
+
public class AdminSubscribeRequest
|
| 34 |
+
{
|
| 35 |
+
public int UserId { get; set; }
|
| 36 |
+
public int MembershipId { get; set; }
|
| 37 |
+
}
|
| 38 |
}
|
LibraryManagement.Backend/Features/Users/UserService.cs
CHANGED
|
@@ -132,7 +132,10 @@ namespace LibraryManagement.Backend.Features.Users
|
|
| 132 |
IsActive = user.IsActive,
|
| 133 |
StudentId = user.StudentId,
|
| 134 |
Address = user.Address,
|
| 135 |
-
CreatedAt = user.CreatedAt
|
|
|
|
|
|
|
|
|
|
| 136 |
};
|
| 137 |
}
|
| 138 |
}
|
|
@@ -149,6 +152,9 @@ namespace LibraryManagement.Backend.Features.Users
|
|
| 149 |
public string? StudentId { get; set; }
|
| 150 |
public string? Address { get; set; }
|
| 151 |
public DateTime CreatedAt { get; set; }
|
|
|
|
|
|
|
|
|
|
| 152 |
}
|
| 153 |
|
| 154 |
public class UserCreateRequest
|
|
|
|
| 132 |
IsActive = user.IsActive,
|
| 133 |
StudentId = user.StudentId,
|
| 134 |
Address = user.Address,
|
| 135 |
+
CreatedAt = user.CreatedAt,
|
| 136 |
+
UpdatedAt = user.UpdatedAt,
|
| 137 |
+
BanStatus = user.BanStatus,
|
| 138 |
+
SuspensionEndDate = user.SuspensionEndDate
|
| 139 |
};
|
| 140 |
}
|
| 141 |
}
|
|
|
|
| 152 |
public string? StudentId { get; set; }
|
| 153 |
public string? Address { get; set; }
|
| 154 |
public DateTime CreatedAt { get; set; }
|
| 155 |
+
public DateTime? UpdatedAt { get; set; }
|
| 156 |
+
public bool? BanStatus { get; set; }
|
| 157 |
+
public DateTime? SuspensionEndDate { get; set; }
|
| 158 |
}
|
| 159 |
|
| 160 |
public class UserCreateRequest
|
LibraryManagement.Backend/appsettings.json
CHANGED
|
@@ -7,7 +7,8 @@
|
|
| 7 |
},
|
| 8 |
"AllowedHosts": "*",
|
| 9 |
"ConnectionStrings": {
|
| 10 |
-
"MssqlConnection": "Server=DESKTOP-BP9A061;Database=LibraryManagement;User Id=sa;Password=sasa@123;TrustServerCertificate=True;"
|
|
|
|
| 11 |
},
|
| 12 |
"Jwt": {
|
| 13 |
"Secret": "YourSuperSecretKeyForLibraryManagementSystem_AtLeast32CharsLong",
|
|
|
|
| 7 |
},
|
| 8 |
"AllowedHosts": "*",
|
| 9 |
"ConnectionStrings": {
|
| 10 |
+
//"MssqlConnection": "Server=DESKTOP-BP9A061;Database=LibraryManagement;User Id=sa;Password=sasa@123;TrustServerCertificate=True;"
|
| 11 |
+
"MssqlConnection": "Server=.;Database=LibraryManagement;User Id=sa;Password=sasa@123;TrustServerCertificate=True;"
|
| 12 |
},
|
| 13 |
"Jwt": {
|
| 14 |
"Secret": "YourSuperSecretKeyForLibraryManagementSystem_AtLeast32CharsLong",
|