From 17af2c8b86b2419c878b2d2639a490779facc8b9 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:07:20 +0530 Subject: [PATCH 01/21] Added auto sized text --- frontend/pubspec.lock | 8 ++++++++ frontend/pubspec.yaml | 1 + 2 files changed, 9 insertions(+) diff --git a/frontend/pubspec.lock b/frontend/pubspec.lock index ae084b6..ee7bde3 100644 --- a/frontend/pubspec.lock +++ b/frontend/pubspec.lock @@ -49,6 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + auto_size_text: + dependency: "direct main" + description: + name: auto_size_text + sha256: "3f5261cd3fb5f2a9ab4e2fc3fba84fd9fcaac8821f20a1d4e71f557521b22599" + url: "https://pub.dev" + source: hosted + version: "3.0.0" awesome_notifications: dependency: "direct main" description: diff --git a/frontend/pubspec.yaml b/frontend/pubspec.yaml index ad1eaba..beb3561 100644 --- a/frontend/pubspec.yaml +++ b/frontend/pubspec.yaml @@ -59,6 +59,7 @@ dependencies: image_cropper: ^5.0.1 url_launcher: ^6.2.4 flutter_dotenv: ^5.1.0 + auto_size_text: ^3.0.0 dev_dependencies: flutter_test: From b6f53faf622d7cbe399a58f7f6f2fdea62547b06 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:07:52 +0530 Subject: [PATCH 02/21] added message for lost and found --- backend/constants/messages.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/constants/messages.js b/backend/constants/messages.js index 81edfbc..ce504a3 100644 --- a/backend/constants/messages.js +++ b/backend/constants/messages.js @@ -30,4 +30,9 @@ export const invalidUserType = "Invalid user type"; export const tokenUpdateError = "Error updating token"; export const badRequest = "Bad request"; export const notFound = "Not found"; -export const deleted = "Deleted"; \ No newline at end of file +export const deleted = "Deleted"; + +// Lost and Found +export const itemNotFound = "Item not found"; +export const itemAdded = "Item added successfully"; +export const itemDeleted = "Item deleted successfully"; From 6e2f66a9ba90e2d931954a15bd261c3c847860d5 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:08:06 +0530 Subject: [PATCH 03/21] remove unused resource --- .../resources/rooms/occupantListResource.js | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 backend/resources/rooms/occupantListResource.js diff --git a/backend/resources/rooms/occupantListResource.js b/backend/resources/rooms/occupantListResource.js deleted file mode 100644 index 1fb4034..0000000 --- a/backend/resources/rooms/occupantListResource.js +++ /dev/null @@ -1,27 +0,0 @@ -import { Router } from "express"; -import Room from "../../models/room.js"; -import Student from "../../models/student.js"; -const router = Router(); - -//GET method -router.get("/", async (req, res) => { - try { - const documentIds = req.body.documentIds; // Assuming the documentIds are sent in the request body - - const occupants = await Promise.all( - documentIds.map(async (documentId) => { - const room = await Room.findOne({ documentId }); - const occupant = await Student.findOne({ _id: room.occupantId }); - return { - occupantName: occupant.name, - roomId: room._id, - }; - }) - ); - - res.json(occupants); - } catch (error) { - console.error(error); - res.status(500).json({ message: "Internal Server Error" }); - } -}); From 4e1337f895e248e9dae08c288e8f84c21926fa43 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:12:34 +0530 Subject: [PATCH 04/21] added a list Id attribute to track who listed a item --- backend/models/lost_and_found.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/models/lost_and_found.js b/backend/models/lost_and_found.js index a191c73..83bc4e1 100644 --- a/backend/models/lost_and_found.js +++ b/backend/models/lost_and_found.js @@ -19,6 +19,10 @@ const lostAndFoundItemSchema = new mongoose.Schema({ type: String, required: true, }, + listerId: { + type: String, + required: true, + }, isLost: { type: Boolean, required: true, From 7c042d564fd39d51ed589c1e0f47519c4a1a84cb Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:27:47 +0530 Subject: [PATCH 05/21] Create uploads folder if not exist --- backend/middlewares/multerConfig.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/middlewares/multerConfig.js b/backend/middlewares/multerConfig.js index 384f487..af51179 100644 --- a/backend/middlewares/multerConfig.js +++ b/backend/middlewares/multerConfig.js @@ -1,9 +1,16 @@ import multer from "multer"; +import fs from "fs"; + +const uploadsFolder = "uploads/"; + +if (!fs.existsSync(uploadsFolder)) { + fs.mkdirSync(uploadsFolder); +} // Define storage configuration const storage = multer.diskStorage({ destination: function (req, file, cb) { - cb(null, "uploads/"); + cb(null, uploadsFolder); }, filename: function (req, file, cb) { cb(null, file.originalname); From 14e15d18db5bb5d24f5b319c49f9ec5b6b762579 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:30:54 +0530 Subject: [PATCH 06/21] added occupant name to room schema --- backend/models/room.js | 4 ++++ frontend/lib/models/room.dart | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/models/room.js b/backend/models/room.js index a2ca4c1..76865cb 100644 --- a/backend/models/room.js +++ b/backend/models/room.js @@ -13,6 +13,10 @@ const roomSchema = new mongoose.Schema({ type: String, default: null, }, + occupantName: { + type: String, + default: null, + }, }); const Room = mongoose.model("Room", roomSchema); diff --git a/frontend/lib/models/room.dart b/frontend/lib/models/room.dart index ea40e55..cf71ec3 100644 --- a/frontend/lib/models/room.dart +++ b/frontend/lib/models/room.dart @@ -1,10 +1,11 @@ class Room { - Room({this.occupantId, this.id, required this.name, this.vacant = true}); + Room({this.occupantId, this.id, required this.name, this.vacant = true, this.occupantName}); final String? id; final String name; final bool vacant; final String? occupantId; + final String? occupantName; factory Room.fromJson(Map json) { return Room( @@ -12,6 +13,7 @@ class Room { name: json['name'], vacant: json['vacant'], occupantId: json['occupantId'], + occupantName: json['occupantName'], ); } @@ -20,6 +22,7 @@ class Room { 'name': name, 'vacant': vacant, 'occupantId': occupantId, + 'occupantName': occupantName, }; } } From fc62bc3ff4ef3280f9015e5c8863adb36674b01f Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:32:15 +0530 Subject: [PATCH 07/21] Added delete method for lost and found alongwith logic to remove listing image --- .../lostAndFound/lostAndFoundResource.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 backend/resources/lostAndFound/lostAndFoundResource.js diff --git a/backend/resources/lostAndFound/lostAndFoundResource.js b/backend/resources/lostAndFound/lostAndFoundResource.js new file mode 100644 index 0000000..cd49c2b --- /dev/null +++ b/backend/resources/lostAndFound/lostAndFoundResource.js @@ -0,0 +1,32 @@ +import express from "express"; +import * as messages from "../../constants/messages.js"; +import LostAndFoundItem from "../../models/lost_and_found.js"; +import fs from "fs"; + +const lostAndFoundRouter = express.Router(); + +// DELETE item by id +lostAndFoundRouter.delete("/:id", async (req, res) => { + const itemId = req.params.id; + + try { + const item = await LostAndFoundItem.findByIdAndDelete(itemId); + + if (!item) { + return res.status(404).json({ message: messages.itemNotFound }); + } + + // Delete the image file + fs.unlink(item.imagePath, (err) => { + if (err) { + console.error(err); + } + }); + + res.json(item); + } catch (err) { + res.status(500).json({ message: messages.internalServerError }); + } +}); + +export default lostAndFoundRouter; From 286ca1d4638982b5f22f53a0e2fc274c6b9c14f8 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:33:05 +0530 Subject: [PATCH 08/21] Accomodated listerId inn get, post and put method --- .../lostAndFound/lostAndFoundListResource.js | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/backend/resources/lostAndFound/lostAndFoundListResource.js b/backend/resources/lostAndFound/lostAndFoundListResource.js index e0c2e6c..6b5f936 100644 --- a/backend/resources/lostAndFound/lostAndFoundListResource.js +++ b/backend/resources/lostAndFound/lostAndFoundListResource.js @@ -2,6 +2,7 @@ import { Router } from "express"; import LostAndFoundItem from "../../models/lost_and_found.js"; import fs from "fs/promises"; import uploader from "../../middlewares/multerConfig.js"; +import messages from "../../constants/messages.js"; const router = Router(); @@ -13,7 +14,7 @@ router.get("/", async (req, res) => { // Create an empty array to store items with images const itemsWithImages = []; -`` + // Iterate through each item for (const item of items) { // Check if imagePath is null @@ -32,6 +33,7 @@ router.get("/", async (req, res) => { imagePath: imagePathBase64, // Set imagePath to null if null in the database description: item.description, contactNumber: item.contactNumber, + listerId: item.listerId, isLost: item.isLost, }; @@ -39,36 +41,38 @@ router.get("/", async (req, res) => { itemsWithImages.push(itemWithImage); } - console.log("Retrieved items:", itemsWithImages.length); - // Send the response with the items res.json(itemsWithImages); } catch (error) { // Handle errors - console.error("Error:", error); - res.status(500).send("Error retrieving items"); + res.status(500).json({ message: messages.internalServerError }); } }); // POST method router.post("/", uploader.single("image"), async (req, res) => { - // Access the uploaded file using req.file - const file = req.file; + try { + // Access the uploaded file using req.file + const file = req.file; - // Construct the LostAndFoundItem object with data from the request - const newItem = new LostAndFoundItem({ - name: req.body.name, - lastSeenLocation: req.body.lastSeenLocation, - imagePath: file ? file.path : null, - description: req.body.description, - contactNumber: req.body.contactNumber, - isLost: req.body.isLost, - }); + // Construct the LostAndFoundItem object with data from the request + const newItem = new LostAndFoundItem({ + name: req.body.name, + lastSeenLocation: req.body.lastSeenLocation, + imagePath: file ? file.path : null, + description: req.body.description, + contactNumber: req.body.contactNumber, + listerId: req.body.listerId, + isLost: req.body.isLost, + }); - // Save the new item to the database - await newItem.save(); + // Save the new item to the database + await newItem.save(); - res.send("Added new item"); + res.json({ message: messages.itemAdded }); + } catch (error) { + res.status(500).json({ message: messages.internalServerError }); + } }); export default router; From a64333b83a660fa8475782899d6e7762c00f6205 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:34:43 +0530 Subject: [PATCH 09/21] occupant name in post and put method --- backend/resources/rooms/roomListResource.js | 3 ++- backend/resources/rooms/roomResource.js | 13 ++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/resources/rooms/roomListResource.js b/backend/resources/rooms/roomListResource.js index ceb9cc6..6b07ab1 100644 --- a/backend/resources/rooms/roomListResource.js +++ b/backend/resources/rooms/roomListResource.js @@ -13,13 +13,14 @@ router.get("/", async (req, res) => { router.post("/", async (req, res) => { try { // Extract data from request body - const { name, vacant, occupantId } = req.body; + const { name, vacant, occupantId, occupantName } = req.body; // Create a new room instance const newRoom = new Room({ name, vacant: vacant || true, // Set default value if not provided occupantId: occupantId || null, // Set default value if not provided + occupantName: occupantName || null, // Set default value if not provided }); // Save the new room to the database diff --git a/backend/resources/rooms/roomResource.js b/backend/resources/rooms/roomResource.js index f78114f..edcab26 100644 --- a/backend/resources/rooms/roomResource.js +++ b/backend/resources/rooms/roomResource.js @@ -6,14 +6,21 @@ const router = Router(); router.put("/:id", async (req, res) => { try { const { id } = req.params; - const { occupantId } = req.body; + const { occupantName, occupantId, vacant } = req.body; const room = await Room.findById(id); if (!room) { return res.status(404).json({ error: "Room not found" }); } - room.vacant = false; - room.occupantId = occupantId || room.occupantId; + if (vacant) { + room.vacant = true; + room.occupantId = null; + room.occupantName = null; + } else { + room.vacant = false; + room.occupantId = occupantId; + room.occupantName = occupantName; + } await room.save(); From 3b9585f78a9ced5c071eec4b13745c3cfd6a5b8f Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:34:53 +0530 Subject: [PATCH 10/21] Fix imports and add lost-and-found resource --- backend/app.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/app.js b/backend/app.js index ee41b68..1f23981 100644 --- a/backend/app.js +++ b/backend/app.js @@ -16,7 +16,8 @@ import roomResource from "./resources/rooms/roomResource.js"; import lostAndFoundListResource from "./resources/lostAndFound/lostAndFoundListResource.js"; import studentListResource from "./resources/student/studentListResource.js"; import facultyListResource from "./resources/faculty/facultyListResource.js"; -import messageResource from './resources/chatroom/messageListResource.js' +import messageResource from "./resources/chatroom/messageListResource.js"; +import lostAndFoundResource from "./resources/lostAndFound/lostAndFoundResource.js"; const PORT = `${process.env.PORT || 3000}`; const app = express(); @@ -41,7 +42,8 @@ app.use("/", testResource); app.use("/rooms", roomListResource); app.use("/room", roomResource); app.use("/lost-and-found", lostAndFoundListResource); -app.use("/messages",messageResource); +app.use("/lost-and-found-item", lostAndFoundResource); +app.use("/messages", messageResource); app.get("/protected", tokenRequired, (req, res) => { res.json({ message: "Access granted" }); From 54e1d00319ec672c323e6ef4e188f8452cea4153 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:35:09 +0530 Subject: [PATCH 11/21] Updated dummy entries to add new attribute --- frontend/lib/constants/dummy_entries.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/lib/constants/dummy_entries.dart b/frontend/lib/constants/dummy_entries.dart index b1a941d..23a7a28 100644 --- a/frontend/lib/constants/dummy_entries.dart +++ b/frontend/lib/constants/dummy_entries.dart @@ -1015,6 +1015,7 @@ class DummyLostAndFound { description: 'Black Dell laptop with a sticker on the back', lastSeenLocation: 'Library', contactNumber: '+91 1234567890', + listerId: 'S001', isLost: false, ), LostAndFoundItem( @@ -1022,6 +1023,7 @@ class DummyLostAndFound { description: 'White iPhone 12 with a black case', lastSeenLocation: 'Cafeteria', contactNumber: '+91 9876543210', + listerId: 'S002', isLost: true, ), LostAndFoundItem( @@ -1029,6 +1031,7 @@ class DummyLostAndFound { description: 'Blue steel water bottle with a dent on the bottom', lastSeenLocation: 'Gymnasium', contactNumber: '+91 4567890123', + listerId: 'S003', isLost: false, ), LostAndFoundItem( @@ -1036,6 +1039,7 @@ class DummyLostAndFound { description: 'Red and black backpack with a broken zipper', lastSeenLocation: 'Auditorium', contactNumber: '+91 7890123456', + listerId: 'S004', isLost: true, ), LostAndFoundItem( @@ -1043,6 +1047,7 @@ class DummyLostAndFound { description: 'Silver wristwatch with a black leather strap', lastSeenLocation: 'Classroom 101', contactNumber: '+91 2345678901', + listerId: 'S005', isLost: false, ), LostAndFoundItem( @@ -1050,6 +1055,7 @@ class DummyLostAndFound { description: 'Green and white striped umbrella with a broken handle', lastSeenLocation: 'Student Lounge', contactNumber: '+91 8901234567', + listerId: 'S006', isLost: true, ), LostAndFoundItem( @@ -1057,6 +1063,7 @@ class DummyLostAndFound { description: 'Black aviator sunglasses with a scratch on the left lens', lastSeenLocation: 'Cafeteria', contactNumber: '+91 3456789012', + listerId: 'S007', isLost: false, ), LostAndFoundItem( @@ -1064,6 +1071,7 @@ class DummyLostAndFound { description: 'Brown leather wallet with a broken zipper', lastSeenLocation: 'Library', contactNumber: '+91 9012345678', + listerId: 'S008', isLost: true, ), LostAndFoundItem( @@ -1071,6 +1079,7 @@ class DummyLostAndFound { description: 'Black over-ear headphones with a missing ear cushion', lastSeenLocation: 'Auditorium', contactNumber: '+91 6789012345', + listerId: 'S009', isLost: false, ), LostAndFoundItem( @@ -1078,6 +1087,7 @@ class DummyLostAndFound { description: 'Blue denim jacket with a tear on the left sleeve', lastSeenLocation: 'Gymnasium', contactNumber: '+91 5678901234', + listerId: 'S010', isLost: true, ), ]; From b976caf041815aa932341606a82e012ffe7bd908 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:35:34 +0530 Subject: [PATCH 12/21] Add textAlign, maxLength, and maxLines properties to MaterialTextFormField --- .../lib/components/material_textformfield.dart | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/lib/components/material_textformfield.dart b/frontend/lib/components/material_textformfield.dart index a1a878e..cce0a4e 100644 --- a/frontend/lib/components/material_textformfield.dart +++ b/frontend/lib/components/material_textformfield.dart @@ -12,7 +12,10 @@ class MaterialTextFormField extends StatelessWidget { this.hintColor, this.enabled, this.controllerLessValue, - this.onTap}); + this.onTap, + this.textAlign, + this.maxLength, + this.maxLines}); final TextEditingController? controller; final String? Function(String?)? validator; @@ -24,6 +27,9 @@ class MaterialTextFormField extends StatelessWidget { final bool? enabled; final String? controllerLessValue; final Function? onTap; + final TextAlign? textAlign; + final int? maxLength; + final int? maxLines; @override Widget build(BuildContext context) { @@ -35,11 +41,12 @@ class MaterialTextFormField extends StatelessWidget { onTap: () => onTap != null ? onTap!() : null, enabled: enabled ?? true, controller: controller ?? substituteController, - maxLines: 1, + textAlign: textAlign ?? TextAlign.start, + maxLines: maxLines ?? 1, + maxLength: maxLength, onChanged: (value) => onChanged != null ? onChanged!(value) : null, validator: (value) => validator != null ? validator!(value) : null, - onFieldSubmitted: (value) => - onSubmitted != null ? onSubmitted!(value) : null, + onFieldSubmitted: (value) => onSubmitted != null ? onSubmitted!(value) : null, cursorColor: Colors.teal.shade900, style: TextStyle( color: Colors.teal.shade900, From 0d714d472f99aee41d7123090b7dc02e8e00ff28 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:35:42 +0530 Subject: [PATCH 13/21] Add listerId field to LostAndFoundItem model --- frontend/lib/models/lost_and_found_item.dart | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/lib/models/lost_and_found_item.dart b/frontend/lib/models/lost_and_found_item.dart index 38a9ef1..d8ad60b 100644 --- a/frontend/lib/models/lost_and_found_item.dart +++ b/frontend/lib/models/lost_and_found_item.dart @@ -7,6 +7,7 @@ class LostAndFoundItem { String? imagePath; String description; String contactNumber; + String listerId; bool isLost; LostAndFoundItem({ @@ -15,8 +16,9 @@ class LostAndFoundItem { required this.lastSeenLocation, this.imagePath, required this.description, - required this.isLost, required this.contactNumber, + required this.listerId, + required this.isLost, }); factory LostAndFoundItem.fromJson(Map json) { @@ -26,8 +28,9 @@ class LostAndFoundItem { lastSeenLocation: json['lastSeenLocation'], imagePath: json['imagePath'], description: json['description'], - isLost: json['isLost'], contactNumber: json['contactNumber'], + listerId: json['listerId'], + isLost: json['isLost'], ); } @@ -37,8 +40,9 @@ class LostAndFoundItem { 'lastSeenLocation': lastSeenLocation, 'imagePath': imagePath, 'description': description, - 'isLost': isLost, 'contact': contactNumber, + 'listerId': listerId, + 'isLost': isLost, }; } } From 79769e462b8cacf65f30a92e2bddd1e6403e085b Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:36:02 +0530 Subject: [PATCH 14/21] Add models and update provider in LostAndFoundProvider --- .../lib/provider/lost_and_found_provider.dart | 49 +++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/frontend/lib/provider/lost_and_found_provider.dart b/frontend/lib/provider/lost_and_found_provider.dart index 3b3968b..565dcef 100644 --- a/frontend/lib/provider/lost_and_found_provider.dart +++ b/frontend/lib/provider/lost_and_found_provider.dart @@ -11,13 +11,16 @@ import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'dart:io'; import '../constants/constants.dart'; +import '../models/admin.dart'; +import '../models/faculty.dart'; +import '../models/student.dart'; +import 'auth_provider.dart'; final lostAndFoundProvider = StateNotifierProvider((ref) => LostAndFoundStateNotifier(ref)); class LostAndFoundState { final List lostAndFoundItemList; - final List lostAndFoundImageList; final TextEditingController itemNameController; final TextEditingController itemDescriptionController; final TextEditingController lastSeenLocationController; @@ -29,7 +32,6 @@ class LostAndFoundState { LostAndFoundState({ required this.lostAndFoundItemList, - required this.lostAndFoundImageList, required this.itemNameController, required this.itemDescriptionController, required this.lastSeenLocationController, @@ -54,7 +56,6 @@ class LostAndFoundState { }) { return LostAndFoundState( lostAndFoundItemList: lostAndFoundItemList ?? this.lostAndFoundItemList, - lostAndFoundImageList: lostAndFoundImageList ?? this.lostAndFoundImageList, itemNameController: itemNameController ?? this.itemNameController, itemDescriptionController: itemDescriptionController ?? this.itemDescriptionController, lastSeenLocationController: lastSeenLocationController ?? this.lastSeenLocationController, @@ -69,11 +70,11 @@ class LostAndFoundState { class LostAndFoundStateNotifier extends StateNotifier { LostAndFoundStateNotifier(Ref ref) - : _api = ref.read(lostAndFoundRepositoryProvider), + : _authState = ref.read(authProvider), + _api = ref.read(lostAndFoundRepositoryProvider), super( LostAndFoundState( - lostAndFoundItemList: DummyLostAndFound.lostAndFoundItems, - lostAndFoundImageList: [], + lostAndFoundItemList: [], itemNameController: TextEditingController(), itemDescriptionController: TextEditingController(), lastSeenLocationController: TextEditingController(), @@ -88,21 +89,39 @@ class LostAndFoundStateNotifier extends StateNotifier { } final LostAndFoundRepository _api; - + final AuthState _authState; final Logger _logger = Logger(); - void addItem() { + Future addItem() async { + + String userId; + + if (_authState.currentUserRole == 'student') { + userId = (_authState.currentUser as Student).id; + } else if (_authState.currentUserRole == 'faculty') { + userId = (_authState.currentUser as Faculty).id; + } else if (_authState.currentUserRole == 'admin') { + userId = (_authState.currentUser as Admin).id; + } else { + return; + } + final LostAndFoundItem item = LostAndFoundItem( name: state.itemNameController.text, lastSeenLocation: state.lastSeenLocationController.text, imagePath: state.selectedImage?.path, description: state.itemDescriptionController.text, isLost: state.listingStatus == LostAndFoundConstants.lostState, + listerId: userId, contactNumber: state.contactNumberController.text, ); state = state.copyWith(loadingState: LoadingState.progress); - _api.addLostAndFoundItem(item); - loadItems(); + if(await _api.addLostAndFoundItem(item)){ + loadItems(); + } + else{ + state = state.copyWith(loadingState: LoadingState.error); + } } launchCaller(String number) async { @@ -178,4 +197,14 @@ class LostAndFoundStateNotifier extends StateNotifier { Image imageFromBase64String(String base64String) { return Image.memory(base64Decode(base64String)); } + + Future deleteItem(String id) async { + state = state.copyWith(loadingState: LoadingState.progress); + if(await _api.deleteLostAndFoundItem(id)){ + loadItems(); + } + else{ + state = state.copyWith(loadingState: LoadingState.error); + } + } } From 3525383c9b3c36377790bda5af0379df6d79d911 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:36:44 +0530 Subject: [PATCH 15/21] Add user models and import auth provider --- frontend/lib/provider/room_provider.dart | 45 ++++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/frontend/lib/provider/room_provider.dart b/frontend/lib/provider/room_provider.dart index b4a40b2..f53df4f 100644 --- a/frontend/lib/provider/room_provider.dart +++ b/frontend/lib/provider/room_provider.dart @@ -7,8 +7,12 @@ import 'package:smart_insti_app/components/borderless_button.dart'; import 'package:smart_insti_app/constants/dummy_entries.dart'; import 'package:smart_insti_app/components/menu_tile.dart'; import 'package:smart_insti_app/models/room.dart'; +import 'package:smart_insti_app/provider/auth_provider.dart'; import 'dart:io'; import '../constants/constants.dart'; +import '../models/admin.dart'; +import '../models/faculty.dart'; +import '../models/student.dart'; import '../repositories/room_repository.dart'; final roomProvider = StateNotifierProvider((ref) => RoomProvider(ref)); @@ -46,7 +50,8 @@ class RoomState { class RoomProvider extends StateNotifier { RoomProvider(Ref ref) - : _api = ref.read(roomRepositoryProvider), + : _authState = ref.read(authProvider), + _api = ref.read(roomRepositoryProvider), super( RoomState( roomList: DummyRooms.rooms, @@ -61,6 +66,7 @@ class RoomProvider extends StateNotifier { final RoomRepository _api; final Logger _logger = Logger(); + final AuthState _authState; void pickSpreadsheet() async { FilePickerResult? result = await FilePicker.platform.pickFiles(); @@ -95,20 +101,45 @@ class RoomProvider extends StateNotifier { } Future loadRooms() async { - state = state.copyWith(loadingState: LoadingState.progress); final rooms = await _api.getRooms(); + // _api.getOccupants(); final newState = state.copyWith(roomList: rooms, loadingState: LoadingState.success); state = newState; } Future reserveRoom(Room room) async { - state = state.copyWith( - loadingState: LoadingState.progress, - ); + String userId; + String userName; + + if (_authState.currentUserRole == 'student') { + userId = (_authState.currentUser as Student).id; + userName = (_authState.currentUser as Student).name; + } else if (_authState.currentUserRole == 'faculty') { + userId = (_authState.currentUser as Faculty).id; + userName = (_authState.currentUser as Faculty).name; + } else if (_authState.currentUserRole == 'admin') { + userId = (_authState.currentUser as Admin).id; + userName = (_authState.currentUser as Admin).name; + } else { + return; + } - await _api.reserveRoom(room.id!, '12345'); + state = state.copyWith(loadingState: LoadingState.progress); + if (await _api.reserveRoom(room.id!, userId, userName)) { + loadRooms(); + } else { + state = state.copyWith(loadingState: LoadingState.error); + } + } + + Future vacateRoom(Room room) async { + state = state.copyWith(loadingState: LoadingState.progress); - await loadRooms(); + if (await _api.vacateRoom(room.id!)) { + loadRooms(); + } else { + state = state.copyWith(loadingState: LoadingState.error); + } } void buildRoomTiles(BuildContext context) async { From 7bc0c8477d25f05a9ed5211692fca8f27ac39285 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:36:57 +0530 Subject: [PATCH 16/21] Add logger and implement deleteLostAndFoundItem method --- .../lost_and_found_repository.dart | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/frontend/lib/repositories/lost_and_found_repository.dart b/frontend/lib/repositories/lost_and_found_repository.dart index ac04aab..59abad5 100644 --- a/frontend/lib/repositories/lost_and_found_repository.dart +++ b/frontend/lib/repositories/lost_and_found_repository.dart @@ -17,6 +17,8 @@ class LostAndFoundRepository { ), ); + final Logger _logger = Logger(); + Future> lostAndFoundItems() async { try { final response = await _client.get('/lost-and-found'); @@ -31,26 +33,42 @@ class LostAndFoundRepository { } } - Future addLostAndFoundItem(LostAndFoundItem item) async { + Future deleteLostAndFoundItem(String id) async { + try { + final response = await _client.delete('/lost-and-found-item/$id'); + Logger().i(response.data); + return true; + } catch (e) { + Logger().e(e); + return false; + } + } + + Future addLostAndFoundItem(LostAndFoundItem item) async { try { String? fileName = item.imagePath?.split('/').last; - FormData formData = FormData.fromMap({ - "name": item.name, - "lastSeenLocation": item.lastSeenLocation, - "description": item.description, - "contactNumber": item.contactNumber, - "isLost": item.isLost, - "image": item.imagePath != null - ? await MultipartFile.fromFile( - item.imagePath!, - filename: fileName, - ) - : null, - }); + FormData formData = FormData.fromMap( + { + "name": item.name, + "lastSeenLocation": item.lastSeenLocation, + "description": item.description, + "contactNumber": item.contactNumber, + "isLost": item.isLost, + "listerId": item.listerId, + "image": item.imagePath != null + ? await MultipartFile.fromFile( + item.imagePath!, + filename: fileName, + ) + : null, + }, + ); final response = await _client.post('/lost-and-found', data: formData); - Logger().w(response.data); + Logger().i(response.data); + return true; } catch (e) { Logger().e(e); + return false; } } } From 57da56d16862f602fe49069553eaf3f2312ac588 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:37:06 +0530 Subject: [PATCH 17/21] Add occupant name to reserveRoom method and add vacateRoom method --- frontend/lib/repositories/room_repository.dart | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/frontend/lib/repositories/room_repository.dart b/frontend/lib/repositories/room_repository.dart index e14a1a7..d6c0334 100644 --- a/frontend/lib/repositories/room_repository.dart +++ b/frontend/lib/repositories/room_repository.dart @@ -27,12 +27,25 @@ class RoomRepository { } } - Future reserveRoom(String roomId, String occupantId) async { + Future reserveRoom(String roomId, String occupantId, String userName) async { try { - final response = await _client.put('/room/$roomId', data: {'occupantId': occupantId}); + final response = await _client.put('/room/$roomId', data: {'occupantName' : userName ,'occupantId': occupantId, 'vacant': false }); Logger().i(response.data); + return true; } catch (e) { Logger().e(e); + return false; + } + } + + Future vacateRoom(String roomId) async { + try { + final response = await _client.put('/room/$roomId', data: {'occupantId': null, 'vacant': true }); + Logger().i(response.data); + return true; + } catch (e) { + Logger().e(e); + return false; } } From c2b50b8df579a16810bf2959fbc83c48457b2ad2 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:37:40 +0530 Subject: [PATCH 18/21] Updated lost and found listing info card and added delete functionality --- frontend/lib/screens/user/lost_and_found.dart | 223 ++++++++++++++---- 1 file changed, 176 insertions(+), 47 deletions(-) diff --git a/frontend/lib/screens/user/lost_and_found.dart b/frontend/lib/screens/user/lost_and_found.dart index ce2bbda..cb0423a 100644 --- a/frontend/lib/screens/user/lost_and_found.dart +++ b/frontend/lib/screens/user/lost_and_found.dart @@ -1,13 +1,18 @@ import 'package:animated_toggle_switch/animated_toggle_switch.dart'; +import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; +import 'package:logger/logger.dart'; import 'package:responsive_framework/responsive_framework.dart'; import 'package:smart_insti_app/components/borderless_button.dart'; import 'package:smart_insti_app/components/material_textformfield.dart'; import 'package:smart_insti_app/provider/lost_and_found_provider.dart'; import '../../components/image_tile.dart'; import '../../constants/constants.dart'; +import '../../models/admin.dart'; +import '../../models/faculty.dart'; +import '../../models/student.dart'; import '../../provider/auth_provider.dart'; class LostAndFound extends ConsumerWidget { @@ -189,7 +194,7 @@ class LostAndFound extends ConsumerWidget { label: const Text('Cancel'), ), const Spacer(), - ElevatedButton( + BorderlessButton( onPressed: () { if (_formKey.currentState!.validate()) { ref.read(lostAndFoundProvider.notifier).addItem(); @@ -197,7 +202,9 @@ class LostAndFound extends ConsumerWidget { context.pop(); } }, - child: const Text('Add'), + label: const Text('Add'), + backgroundColor: Colors.blueAccent.shade100.withOpacity(0.5), + splashColor: Colors.blue.shade700, ), ], ), @@ -256,51 +263,170 @@ class LostAndFound extends ConsumerWidget { context: context, builder: (_) => Dialog( child: Padding( - padding: const EdgeInsets.all(15.0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - "Item name : ${item.name}", - textAlign: TextAlign.center, - style: const TextStyle(fontSize: 20), - ), - const SizedBox(height: 20), - Text( - "Item description : \n${item.description}", - textAlign: TextAlign.center, - style: const TextStyle(fontSize: 16), - ), - const SizedBox(height: 20), - Text( - "Last seen at : ${item.lastSeenLocation}", - textAlign: TextAlign.center, - style: const TextStyle(fontSize: 16), - ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - item.contactNumber, - style: const TextStyle(fontSize: 16), + padding: const EdgeInsets.only(left: 35, right: 35, top: 20, bottom: 20), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text("Item Name", style: TextStyle(fontSize: 20)), + const SizedBox(height: 10), + Container( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: Colors.tealAccent.withOpacity(0.4), ), - const SizedBox(width: 10), - IconButton( - onPressed: () => ref - .read(lostAndFoundProvider.notifier) - .launchCaller(item.contactNumber), - icon: const Icon(Icons.call, color: Colors.green)), - ], - ), - const SizedBox(height: 20), - BorderlessButton( - onPressed: () => context.pop(), - backgroundColor: Colors.redAccent.shade100.withOpacity(0.5), - splashColor: Colors.red.shade700, - label: const Text('Close'), - ), - ], + width: double.infinity, + child: AutoSizeText( + item.name, + style: TextStyle(fontSize: 15, color: Colors.teal.shade900), + maxLines: 5, + overflow: TextOverflow.ellipsis, + ), + ), + const SizedBox(height: 20), + const Text("Item Description", style: TextStyle(fontSize: 20)), + const SizedBox(height: 10), + Container( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: Colors.tealAccent.withOpacity(0.4), + ), + width: double.infinity, + child: AutoSizeText( + item.description, + style: TextStyle(fontSize: 15, color: Colors.teal.shade900), + maxLines: 5, + overflow: TextOverflow.ellipsis, + ), + ), + const SizedBox(height: 20), + const Text("Last seen at", style: TextStyle(fontSize: 20)), + const SizedBox(height: 10), + Container( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: Colors.tealAccent.withOpacity(0.4), + ), + width: double.infinity, + child: AutoSizeText( + item.lastSeenLocation, + style: TextStyle(fontSize: 15, color: Colors.teal.shade900), + maxLines: 5, + overflow: TextOverflow.ellipsis, + ), + ), + const SizedBox(height: 20), + const Text("Contact", style: TextStyle(fontSize: 20)), + const SizedBox(height: 10), + Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Container( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: Colors.tealAccent.withOpacity(0.4), + ), + width: 185, + child: AutoSizeText( + item.contactNumber, + style: TextStyle(fontSize: 15, color: Colors.teal.shade900), + maxLines: 5, + overflow: TextOverflow.ellipsis, + ), + ), + const SizedBox(width: 10), + Container( + width: 65, + height: 65, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: Colors.orangeAccent.withOpacity(0.5), + ), + child: GestureDetector( + onTap: () => ref + .read(lostAndFoundProvider.notifier) + .launchCaller(item.contactNumber), + child: const Icon( + Icons.call, + color: Colors.orange, + ), + ), + ), + ], + ), + const SizedBox(height: 30), + Consumer( + builder: (_, ref, __) { + String userId; + final authState = ref.watch(authProvider); + if (ref.read(authProvider).currentUserRole == 'student') { + userId = (authState.currentUser as Student).id; + } else if (authState.currentUserRole == 'faculty') { + userId = (authState.currentUser as Faculty).id; + } else if (authState.currentUserRole == 'admin') { + userId = (authState.currentUser as Admin).id; + } else { + return const SizedBox.shrink(); + } + + if (userId == item.listerId) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + SizedBox( + height: 55, + width: 100, + child: BorderlessButton( + onPressed: () => context.pop(), + backgroundColor: Colors.blueAccent.shade100.withOpacity(0.5), + splashColor: Colors.blue.shade700, + label: const Text('Close'), + ), + ), + Container( + width: 55, + height: 55, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.redAccent.withOpacity(0.5), + ), + child: GestureDetector( + onTap: () { + ref.read(lostAndFoundProvider.notifier).deleteItem(item.id!); + context.pop(); + }, + child: const Icon( + Icons.delete, + color: Colors.red, + ), + ), + ), + ], + ); + } else { + return Center( + child: SizedBox( + height: 55, + width: 100, + child: BorderlessButton( + onPressed: () => context.pop(), + backgroundColor: Colors.blueAccent.shade100.withOpacity(0.5), + splashColor: Colors.blue.shade700, + label: const Text('Close'), + ), + ), + ); + } + }, + ), + ], + ), ), ), ), @@ -309,7 +435,10 @@ class LostAndFound extends ConsumerWidget { ], ) : const Center( - child: Text("No Listings"), + child: Text( + 'No lost items :)', + style: TextStyle(fontSize: 30, color: Colors.black38), + ), )) : const Center(child: CircularProgressIndicator()), ), From 707df948c041a3f7632d1b339a18de5c9918d998 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:38:18 +0530 Subject: [PATCH 19/21] Added logic to vaccant room for the occupier only --- frontend/lib/screens/user/room_vacancy.dart | 128 ++++++++++++++------ 1 file changed, 90 insertions(+), 38 deletions(-) diff --git a/frontend/lib/screens/user/room_vacancy.dart b/frontend/lib/screens/user/room_vacancy.dart index 665804f..b352e66 100644 --- a/frontend/lib/screens/user/room_vacancy.dart +++ b/frontend/lib/screens/user/room_vacancy.dart @@ -6,7 +6,10 @@ import 'package:smart_insti_app/components/borderless_button.dart'; import 'package:smart_insti_app/components/menu_tile.dart'; import 'package:smart_insti_app/constants/constants.dart'; import 'package:smart_insti_app/provider/room_provider.dart'; +import '../../models/admin.dart'; +import '../../models/faculty.dart'; import '../../models/room.dart'; +import '../../models/student.dart'; import '../../provider/auth_provider.dart'; class RoomVacancy extends ConsumerWidget { @@ -34,44 +37,81 @@ class RoomVacancy extends ConsumerWidget { for (Room room in ref.read(roomProvider).roomList) MenuTile( title: room.name, - onTap: () => showDialog( - context: context, - builder: (_) => Dialog( - child: Padding( - padding: const EdgeInsets.all(15.0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text("${room.name} : ${room.vacant ? 'Vacant' : 'Occupied'}", - style: const TextStyle(fontSize: 20)), - const SizedBox(height: 20), - room.vacant - ? Row( - children: [ - BorderlessButton( - onPressed: () => context.pop(), - label: const Text('Cancel'), - backgroundColor: Colors.red.shade100, - splashColor: Colors.redAccent, - ), - const Spacer(), - BorderlessButton( - onPressed: () { - ref.read(roomProvider.notifier).reserveRoom(room); - context.pop(); - }, - label: const Text('Reserve'), - backgroundColor: Colors.blue.shade100, - splashColor: Colors.blueAccent, - ), - ], - ) - : Container(), - ], + onTap: () { + showDialog( + context: context, + builder: (_) => Dialog( + child: Padding( + padding: const EdgeInsets.all(15.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text("${room.name} : ${room.vacant ? 'Vacant' : 'Occupied'}", + style: const TextStyle(fontSize: 20)), + room.vacant + ? const SizedBox.shrink() + : Text( + "by : ${room.occupantName}", + textAlign: TextAlign.center, + maxLines: 1, + style: const TextStyle(overflow: TextOverflow.ellipsis), + ), + const SizedBox(height: 20), + room.vacant + ? Row( + children: [ + BorderlessButton( + onPressed: () => context.pop(), + label: const Text('Cancel'), + backgroundColor: Colors.red.shade100, + splashColor: Colors.redAccent, + ), + const Spacer(), + BorderlessButton( + onPressed: () { + ref.read(roomProvider.notifier).reserveRoom(room); + context.pop(); + }, + label: const Text('Reserve'), + backgroundColor: Colors.blue.shade100, + splashColor: Colors.blueAccent, + ), + ], + ) + : Consumer( + builder: (_, ref, __) { + String userId; + final authState = ref.watch(authProvider); + if (authState.currentUserRole == 'student') { + userId = (authState.currentUser as Student).id; + } else if (authState.currentUserRole == 'faculty') { + userId = (authState.currentUser as Faculty).id; + } else if (authState.currentUserRole == 'admin') { + userId = (authState.currentUser as Admin).id; + } else { + return const SizedBox.shrink(); + } + if (userId == room.occupantId) { + return BorderlessButton( + onPressed: () { + ref.read(roomProvider.notifier).vacateRoom(room); + context.pop(); + }, + label: const Text('Vacate'), + backgroundColor: Colors.red.shade100, + splashColor: Colors.redAccent, + ); + } else { + return const SizedBox.shrink(); + } + }, + ), + ], + ), ), ), - ), - ), + ); + }, body: [ const SizedBox(height: 5), Text( @@ -80,7 +120,14 @@ class RoomVacancy extends ConsumerWidget { style: const TextStyle(fontSize: 14), ), const SizedBox(height: 10), - room.vacant ? Container() : const Text("by : Aadarsh"), + room.vacant + ? Container() + : Text( + "by : ${room.occupantName}", + textAlign: TextAlign.center, + maxLines: 1, + style: const TextStyle(overflow: TextOverflow.ellipsis), + ), ], icon: Icons.class_, primaryColor: room.vacant ? Colors.greenAccent.shade100 : Colors.redAccent.shade100, @@ -88,7 +135,12 @@ class RoomVacancy extends ConsumerWidget { ), ], ) - : const Center(child: Text('No rooms found')) + : const Center( + child: Text( + 'No Rooms to go to', + style: TextStyle(fontSize: 30, color: Colors.black38), + ), + ) : const Center(child: CircularProgressIndicator()), ), ); From b69898eb4a6e2ff6d6b90f06181d13febdf59c90 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 22:51:01 +0530 Subject: [PATCH 20/21] Post merge cleanup --- backend/app.js | 1 - backend/resources/lostAndFound/lostAndFoundListResource.js | 2 +- frontend/lib/components/material_textformfield.dart | 4 +--- frontend/lib/main.dart | 2 -- frontend/lib/screens/loading_page.dart | 3 --- frontend/lib/screens/user/timetables.dart | 2 -- 6 files changed, 2 insertions(+), 12 deletions(-) diff --git a/backend/app.js b/backend/app.js index 5231d3d..64cd569 100644 --- a/backend/app.js +++ b/backend/app.js @@ -20,7 +20,6 @@ import messageResource from "./resources/chatroom/messageListResource.js"; import lostAndFoundResource from "./resources/lostAndFound/lostAndFoundResource.js"; import timetableListResource from "./resources/timetable/timetableListResource.js"; import timetableResource from "./resources/timetable/timetableResource.js"; -import messageResource from './resources/chatroom/messageListResource.js' const PORT = `${process.env.PORT || 3000}`; const app = express(); diff --git a/backend/resources/lostAndFound/lostAndFoundListResource.js b/backend/resources/lostAndFound/lostAndFoundListResource.js index 6b5f936..a88285a 100644 --- a/backend/resources/lostAndFound/lostAndFoundListResource.js +++ b/backend/resources/lostAndFound/lostAndFoundListResource.js @@ -2,7 +2,7 @@ import { Router } from "express"; import LostAndFoundItem from "../../models/lost_and_found.js"; import fs from "fs/promises"; import uploader from "../../middlewares/multerConfig.js"; -import messages from "../../constants/messages.js"; +import * as messages from "../../constants/messages.js"; const router = Router(); diff --git a/frontend/lib/components/material_textformfield.dart b/frontend/lib/components/material_textformfield.dart index 426eb45..82e03fb 100644 --- a/frontend/lib/components/material_textformfield.dart +++ b/frontend/lib/components/material_textformfield.dart @@ -17,8 +17,7 @@ class MaterialTextFormField extends StatelessWidget { this.maxLength, this.maxLines, this.textAlign, - this.inputFormatters, - this.onTap}); + this.inputFormatters,}); final TextEditingController? controller; final String? Function(String?)? validator; @@ -32,7 +31,6 @@ class MaterialTextFormField extends StatelessWidget { final TextAlign? textAlign; final List? inputFormatters; final Function? onTap; - final TextAlign? textAlign; final int? maxLength; final int? maxLines; diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart index 265db95..11c1468 100644 --- a/frontend/lib/main.dart +++ b/frontend/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:auto_orientation/auto_orientation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -8,7 +7,6 @@ import 'package:smart_insti_app/routes/routes.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await dotenv.load(fileName: ".env"); - AutoOrientation.portraitUpMode(); runApp(const ProviderScope(child: SmartInstiApp())); } diff --git a/frontend/lib/screens/loading_page.dart b/frontend/lib/screens/loading_page.dart index e22d9a9..89566c0 100644 --- a/frontend/lib/screens/loading_page.dart +++ b/frontend/lib/screens/loading_page.dart @@ -1,12 +1,9 @@ import 'package:animated_text_kit/animated_text_kit.dart'; -import 'package:auto_orientation/auto_orientation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; -import 'package:logger/logger.dart'; import 'package:responsive_framework/responsive_framework.dart'; import 'package:smart_insti_app/provider/auth_provider.dart'; -import 'package:smart_insti_app/services/auth/auth_service.dart'; class LoadingPage extends ConsumerWidget { const LoadingPage({super.key}); diff --git a/frontend/lib/screens/user/timetables.dart b/frontend/lib/screens/user/timetables.dart index f3a291a..8e8d05a 100644 --- a/frontend/lib/screens/user/timetables.dart +++ b/frontend/lib/screens/user/timetables.dart @@ -1,10 +1,8 @@ import 'package:animated_toggle_switch/animated_toggle_switch.dart'; -import 'package:auto_orientation/auto_orientation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; -import 'package:logger/logger.dart'; import 'package:responsive_framework/responsive_framework.dart'; import 'package:smart_insti_app/components/borderless_button.dart'; import 'package:smart_insti_app/components/material_textformfield.dart'; From 63d7d874ca352187f7832cd69b81bfebc0bd2c88 Mon Sep 17 00:00:00 2001 From: nailsonseat Date: Fri, 16 Feb 2024 23:19:24 +0530 Subject: [PATCH 21/21] Messages for room resources --- backend/constants/messages.js | 5 +++++ backend/resources/rooms/roomListResource.js | 9 +++------ backend/resources/rooms/roomResource.js | 9 ++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/backend/constants/messages.js b/backend/constants/messages.js index ce504a3..beceb3f 100644 --- a/backend/constants/messages.js +++ b/backend/constants/messages.js @@ -36,3 +36,8 @@ export const deleted = "Deleted"; export const itemNotFound = "Item not found"; export const itemAdded = "Item added successfully"; export const itemDeleted = "Item deleted successfully"; + +// Rooom Vacancy +export const roomNotFound = "Room not found"; +export const roomUpdated = "Room updated successfully"; +export const roomCreated = "Room created successfully"; diff --git a/backend/resources/rooms/roomListResource.js b/backend/resources/rooms/roomListResource.js index 6b07ab1..a1cf459 100644 --- a/backend/resources/rooms/roomListResource.js +++ b/backend/resources/rooms/roomListResource.js @@ -1,5 +1,6 @@ import { Router } from "express"; import Room from "../../models/room.js"; +import * as messages from "../../constants/messages.js"; const router = Router(); // GET method @@ -25,16 +26,12 @@ router.post("/", async (req, res) => { // Save the new room to the database await newRoom.save(); - console.log("Room created successfully"); // Respond with success message - res - .status(201) - .json({ message: "Room created successfully", room: newRoom }); + res.status(201).json({ message: messages.roomCreated, room: newRoom }); } catch (error) { // Handle errors - console.error("Error creating room:", error); - res.status(500).json({ error: "Internal server error" }); + res.status(500).json({ message: messages.internalServerError }); } }); diff --git a/backend/resources/rooms/roomResource.js b/backend/resources/rooms/roomResource.js index edcab26..1cd1a4b 100644 --- a/backend/resources/rooms/roomResource.js +++ b/backend/resources/rooms/roomResource.js @@ -1,5 +1,6 @@ import { Router } from "express"; import Room from "../../models/room.js"; +import * as messages from "../../constants/messages.js"; const router = Router(); // PUT method @@ -9,7 +10,7 @@ router.put("/:id", async (req, res) => { const { occupantName, occupantId, vacant } = req.body; const room = await Room.findById(id); if (!room) { - return res.status(404).json({ error: "Room not found" }); + return res.status(404).json({ message: messages.roomNotFound }); } if (vacant) { @@ -24,11 +25,9 @@ router.put("/:id", async (req, res) => { await room.save(); - console.log("Room updated successfully"); - res.json({ message: "Room updated successfully", room }); + res.json({ message: messages.roomUpdated, room }); } catch (error) { - console.error("Error updating room:", error); - res.status(500).json({ error: "Internal server error" }); + res.status(500).json({ message: messages.internalServerError }); } });