Skip to content

feat: complete Web (Weather App) and Mobile (Library Management) challenges#6

Open
abdelrzz9 wants to merge 1 commit into
MicroClub-USTHB:mainfrom
abdelrzz9:web/abderazek/chellenges
Open

feat: complete Web (Weather App) and Mobile (Library Management) challenges#6
abdelrzz9 wants to merge 1 commit into
MicroClub-USTHB:mainfrom
abdelrzz9:web/abderazek/chellenges

Conversation

@abdelrzz9

Copy link
Copy Markdown
Member

Overview
This Pull Request includes the completion of two main challenges: a Weather Web Application and a Library Management System (Dart/Mobile).

🌤️ Weather CLI App — Backend Challenge #1

📋 Description

A Node.js command-line application that fetches real-time weather data for any city using the OpenWeatherMap API and displays it in a clean console format.


✅ Challenge Requirements Completed

  • Project initialized with npm init
  • API key stored securely in .env
  • Fetch weather data using async/await
  • Error handling with try/catch
  • Clean and readable code structure
  • README file included

🔧 What Was Built

File Purpose
index.js Main app with 5 clean functions
.env Stores API key securely
package.json ES Modules + dependencies
README.md Full project documentation

🧠 Functions Overview

Function Purpose
validateApiKey() Checks API key exists in .env
getCity() Reads city from command-line args
fetchWeather() Fetches data from OpenWeatherMap
displayWeather() Prints formatted weather result
main() Entry point with try/catch

❌ Errors Handled

  • Invalid API key (401)
  • City not found (404)
  • Missing city argument
  • Network errors

🧪 How to Test

npm install
node index.js London
node index.js Riyadh
node index.js "New York"

📤 Expected Output

🔍 Fetching weather for "London"...


  🌍 Weather in London, GB

  🌡️  Temperature : 18°C (Feels like 16°C)
  🌤️  Weather     : Clear Sky
 💧 Humidity    : 60%
  💨 Wind Speed  : 3.5 m/s

image

🎯 Library Management System - Dart Workshop Challenge

Pull Request

feat: Complete Library Management System with all 17 Dart concepts


✅ Requirements Met (17/17)

✓ Variables: var, final, const, nullable (String?), ??, !
✓ Collections: List, Set, Map with .where(), .map(), .reduce(), .forEach()
✓ Functions: named params, optional params, arrow, anonymous, higher-order
✓ Constructors: default, named, optional (3 types in each model class)
✓ Abstract class: LibraryItem with abstract methods
✓ Inheritance: extends, override, super
✓ Interface: implements Borrowable
✓ Mixins: Timestampable, Searchable with with keyword
✓ Enums: BookStatus, MemberTier with switch statements
✓ Async: All DB operations return Future with await
✓ Stream: Broadcast StreamController for real-time activity log
✓ Isolate: Search runs in separate isolate with SendPort/ReceivePort
✓ Exceptions: 3 custom classes with try/catch/finally
✓ Unicode Runes: '\u{1F4DA}', '\u2713', '\u2717'
✓ Demo Data: 7 books, 5 members, 3 active loans pre-loaded


🏗️ Architecture

Single file (~2,000 lines): library_management.dart

Structure:

  • Enums (2) → Exceptions (3) → Mixins (2) → Abstract (2)
  • Models: Book, Member, Loan
  • LibraryManager with 49 methods
  • Isolate worker for search
  • Helper functions (~30) + Menu functions (~28)
  • Main function with demo data

📊 Components

Book Class

  • Extends LibraryItem, with Timestampable & Searchable, implements Borrowable
  • 3 constructors, 12 methods
  • Properties: title, author, isbn?, status, genreTags (Set), pages

Member Class

  • With Timestampable mixin
  • 3 constructors, 10 methods
  • Tier-based limits: Standard=3, Premium=10 books

Loan Class

  • 3 constructors, 10 methods
  • Logic: isOverdue() compares DateTime.now() with dueDate
  • Tracks: loanDate, dueDate?, returnDate?, isReturned

LibraryManager

  • Storage: Map<String, Book>, Map<String, Member>, List
  • 49 async methods for CRUD operations
  • Real-time Stream broadcasting
  • Isolate-based search

🔧 Key Features

Defensive Programming

// Double validation: manager validates for UX, models validate for integrity
void borrow(String memberId) {
  if (!isAvailable()) throw InvalidLoanException('...');
  // proceed
}

Collection Operations

.where((book) => book.isAvailable())     // Filter
.map((book) => book.title)               // Transform
.reduce((a, b) => a + b)                 // Aggregate

Isolate Search

// Runs in separate thread to prevent blocking
Future<List> searchCatalog(String query) async {
  Isolate isolate = await Isolate.spawn(catalogSearchWorker, ...);
  // Heavy search operation
}

Stream Broadcasting

manager.activityLog.listen((event) => print('🔔 $event'));
// 🔔 [14:30:15] 📚 Added book: Harry Potter
// 🔔 [14:30:20] 📤 Loan: Harry Potter → Ahmed

🌱 Demo Data

Pre-loaded with:

  • 7 Books (Harry Potter, 1984, The Alchemist, etc.)
  • 5 Members (3 Premium, 2 Standard)
  • 3 Active Loans

📱 UI

Console menu system:

  1. Books Management (CRUD + Search)
  2. Members Management (CRUD + Upgrade)
  3. Loans Management (Loan/Return/View)
  4. Search Catalog (Isolate)
  5. Statistics
  6. Exit

🚀 Run

dart lib/library_management.dart

Output:

  • Demo data loads automatically
  • Interactive menu appears
  • Stream broadcasts all activities in real-time
  • All 17 concepts demonstrated

📏 Metrics

  • Lines: ~2,000
  • Classes: 10
  • Methods: 137
  • Single file as required

🎯 Design Highlights

✓ Separation of concerns (each class handles own validation)
✓ Type safety (no dynamic types)
✓ Defensive programming (double validation)
✓ DRY principle (mixins for shared behavior)
✓ Performance (Map for O(1) lookup, Isolate for heavy operations)
✓ Real-time feedback (Stream for activity log)
✓ Comprehensive error handling (custom exceptions + try/catch everywhere)


📝 Notes for Reviewer

  • All code in single file: lib/library_management.dart
  • Each of 17 requirements searchable in code
  • Demo data auto-loads, no setup needed
  • Stream listener shows all operations live
  • Isolate testable via menu option 4
  • Error handling testable by invalid operations

Status: Ready for Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant