commit 8dbbe65a09a61d5850009f1807ae26946547bd53 Author: libexi01 Date: Fri Jul 5 23:57:32 2024 +0530 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..22c82cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +src/.DS_Store \ No newline at end of file diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..58197da --- /dev/null +++ b/README.MD @@ -0,0 +1,3 @@ +# Welland Gouldsmith School Management System + +This is the repository for my Welland Gouldsmith School Management System project made using the V Programming language, SQLite3 and HTMX \ No newline at end of file diff --git a/app.db b/app.db new file mode 100644 index 0000000..e3d29a8 Binary files /dev/null and b/app.db differ diff --git a/databases/config_databases_sqlite.v b/databases/config_databases_sqlite.v new file mode 100644 index 0000000..df58d89 --- /dev/null +++ b/databases/config_databases_sqlite.v @@ -0,0 +1,8 @@ +module databases + +import db.sqlite // can change to 'db.mysql', 'db.pg' + +pub fn create_db_connection() !sqlite.DB { + mut db := sqlite.connect('app.db')! + return db +} diff --git a/src/faculty_controller.v b/src/faculty_controller.v new file mode 100644 index 0000000..fd41036 --- /dev/null +++ b/src/faculty_controller.v @@ -0,0 +1,39 @@ +module main + +import vweb + + +@['/controller/faculty'; post] +pub fn (mut app App) controller_get_faculty(email string, password string) vweb.Result { + response := app.service_get_faculty(email, password) or { + app.set_status(400, '') + return app.text('${err}') + } + return app.json(response) +} + +@['/controller/faculty/create'; post] +pub fn (mut app App) controller_create_faculty(firstname string, lastname string, email string, password string) vweb.Result { + if firstname == '' { + app.set_status(400, '') + return app.text('firstname cannot be empty') + } + if lastname == '' { + app.set_status(400, '') + return app.text('lastname cannot be empty') + } + if email == '' { + app.set_status(400, '') + return app.text('username cannot be empty') + } + if password == '' { + app.set_status(400, '') + return app.text('password cannot be empty') + } + app.service_add_faculty(firstname, lastname, email, password) or { + app.set_status(400, '') + return app.text('error: ${err}') + } + app.set_status(201, '') + return app.redirect('/faculty') +} \ No newline at end of file diff --git a/src/faculty_entities.v b/src/faculty_entities.v new file mode 100644 index 0000000..79b2287 --- /dev/null +++ b/src/faculty_entities.v @@ -0,0 +1,13 @@ +module main + +@[table: 'faculty'] +pub struct Faculty { +mut: + id int @[primary; sql: serial] + firstname string @[sql_type: 'TEXT'] + lastname string @[sql_type: 'TEXT'] + email string @[sql_type: 'TEXT'; unique] + access_level int @[sql_type: 'INTEGER'] + password string @[sql_type: 'TEXT'] + // products []Product @[fkey: 'user_id'] +} diff --git a/src/faculty_htmx.v b/src/faculty_htmx.v new file mode 100644 index 0000000..50960ff --- /dev/null +++ b/src/faculty_htmx.v @@ -0,0 +1 @@ +module main \ No newline at end of file diff --git a/src/faculty_service.v b/src/faculty_service.v new file mode 100644 index 0000000..b891a60 --- /dev/null +++ b/src/faculty_service.v @@ -0,0 +1,44 @@ +module main + +import databases + +// service_add_faculty is a function that adds a faculty member to the database. +fn (mut app App) service_add_faculty(firstname string, lastname string, email string, password string) ! { + mut db := databases.create_db_connection()! + + defer { + db.close() or { panic(err) } + } + + faculty_model := Faculty{ + firstname: firstname + lastname: lastname + email: email + password: password + } + + mut insert_error := '' + sql db { + insert faculty_model into Faculty + } or { insert_error = err.msg() } + if insert_error != '' { + return error(insert_error) + } +} + +fn (mut app App) service_get_faculty(email string, password string) !Faculty { + mut db := databases.create_db_connection() or { + println(err) + return err + } + defer { + db.close() or { panic(err) } + } + results := sql db { + select from Faculty where email == email && password == password + }! + if results.len == 0 { + return error('no results') + } + return results[0] +} \ No newline at end of file diff --git a/src/faculty_view.v b/src/faculty_view.v new file mode 100644 index 0000000..0a18464 --- /dev/null +++ b/src/faculty_view.v @@ -0,0 +1,33 @@ +module main + +import vweb + +@['/faculty/login'; get] +pub fn (mut app App) faculty_login() vweb.Result { + + return $vweb.html() +} + +@['/faculty'; get] +pub fn (mut app App) faculty_admin() vweb.Result { + + return $vweb.html() +} + +@['/faculty/schedule'; get] +pub fn (mut app App) faculty_schedule() vweb.Result { + + return $vweb.html() +} + +@['/faculty/attendance'; get] +pub fn (mut app App) faculty_attendance() vweb.Result { + + return $vweb.html() +} + +@['/faculty/signup'; get] +pub fn (mut app App) faculty_signup() vweb.Result { + + return $vweb.html() +} \ No newline at end of file diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..a6405f7 --- /dev/null +++ b/src/index.html @@ -0,0 +1,21 @@ + + + + + + School Management System + @css '/templates/style.css' + + +
+

Welcome to Welland Gouldsmith Management System

+
+
+
+

Choose an option:

+ Check Attendance (Student) + Faculty Login +
+
+ + diff --git a/src/main.v b/src/main.v new file mode 100644 index 0000000..7bd65a3 --- /dev/null +++ b/src/main.v @@ -0,0 +1,40 @@ +module main + +import vweb +import databases +import os + +const ( + port = 8082 +) + +struct App { + vweb.Context +} + +pub fn (app App) before_request() { + println('[web] before_request: ${app.req.method} ${app.req.url}') +} + +fn main() { + mut db := databases.create_db_connection() or { panic(err) } + + sql db { + create table Faculty + // create table Product + } or { panic('error on create table: ${err}') } + + db.close() or { panic(err) } + + mut app := &App{} + app.serve_static('/favicon.ico', 'src/assets/favicon.ico') + // makes all static files available. + app.mount_static_folder_at(os.resource_abs_path('.'), '/') + + vweb.run(app, port) +} + +pub fn (mut app App) index() vweb.Result { + + return $vweb.html() +} diff --git a/src/principle_controller.v b/src/principle_controller.v new file mode 100644 index 0000000..e69de29 diff --git a/src/principle_service.v b/src/principle_service.v new file mode 100644 index 0000000..e69de29 diff --git a/src/principle_view.v b/src/principle_view.v new file mode 100644 index 0000000..e69de29 diff --git a/src/students_entities.v b/src/students_entities.v new file mode 100644 index 0000000..858900b --- /dev/null +++ b/src/students_entities.v @@ -0,0 +1,11 @@ +module main + +@[table: 'students'] +pub struct Student { +mut: + id int @[primary; sql: serial] + firstname string @[sql_type: 'TEXT'] + lastname string @[sql_type: 'TEXT'] + email string @[sql_type: 'TEXT'; unique] + password string @[sql_type: 'TEXT'] +} diff --git a/src/students_service.v b/src/students_service.v new file mode 100644 index 0000000..e69de29 diff --git a/src/students_view.v b/src/students_view.v new file mode 100644 index 0000000..e3e5b4f --- /dev/null +++ b/src/students_view.v @@ -0,0 +1,9 @@ +module main + +import vweb + +@['/student'; get] +pub fn (mut app App) student_view() vweb.Result { + + return $vweb.html() +} \ No newline at end of file diff --git a/src/templates/faculty/admin.html b/src/templates/faculty/admin.html new file mode 100644 index 0000000..ceec8de --- /dev/null +++ b/src/templates/faculty/admin.html @@ -0,0 +1,27 @@ + + + + + + Faculty Admin + @css '/templates/style.css' + + +
+

Faculty Admin Panel

+
+
+
+

Welcome, [Faculty Name]!

+ +
+
+ + diff --git a/src/templates/faculty/attendance.html b/src/templates/faculty/attendance.html new file mode 100644 index 0000000..8b935b4 --- /dev/null +++ b/src/templates/faculty/attendance.html @@ -0,0 +1,36 @@ + + + + + + Take Attendance + @css '/templates/style.css' + + +
+

Faculty Admin Panel

+
+
+
+

Take Attendance (Select Class)

+
+ + +
+

+ + Back to Admin Panel +
+
+ + diff --git a/src/templates/faculty/login.html b/src/templates/faculty/login.html new file mode 100644 index 0000000..6994c09 --- /dev/null +++ b/src/templates/faculty/login.html @@ -0,0 +1,24 @@ + + + + + + Faculty Login + @css '/templates/style.css' + + +
+

Faculty Login

+
+
+ +
+ + diff --git a/src/templates/faculty/schedule.html b/src/templates/faculty/schedule.html new file mode 100644 index 0000000..d04c249 --- /dev/null +++ b/src/templates/faculty/schedule.html @@ -0,0 +1,25 @@ + + + + + + View Class Schedule + @css '/templates/style.css' + + +
+

Faculty Admin Panel

+
+
+
+

Your Class Schedule

+

**Day** | **Time** | **Course** | **Location**

+

----- | -------- | -------- | --------

+

Monday | 9:00 AM - 10:00 AM | Math | Room 201

+

Tuesday | 10:30 AM - 12:00 PM | English | Room 305

+

Wednesday | 1:00 PM - 2:00 PM | Science | Lab 102

+ Back to Admin Panel +
+
+ + diff --git a/src/templates/faculty/signup.html b/src/templates/faculty/signup.html new file mode 100644 index 0000000..acdd2e4 --- /dev/null +++ b/src/templates/faculty/signup.html @@ -0,0 +1,29 @@ + + + + + + Faculty Login + @css '/templates/style.css' + + +
+

Faculty Login

+
+
+ +
+ + diff --git a/src/templates/header_component.html b/src/templates/header_component.html new file mode 100644 index 0000000..60f1a88 --- /dev/null +++ b/src/templates/header_component.html @@ -0,0 +1,15 @@ + diff --git a/src/templates/products.css b/src/templates/products.css new file mode 100644 index 0000000..d83d2d1 --- /dev/null +++ b/src/templates/products.css @@ -0,0 +1,11 @@ +h1.title { + font-family: Arial, Helvetica, sans-serif; + color: #3b7bbf; +} + +div.products-table { + border: 1px solid; + max-width: 720px; + padding: 10px; + margin: 10px; +} \ No newline at end of file diff --git a/src/templates/products.html b/src/templates/products.html new file mode 100644 index 0000000..959c3ee --- /dev/null +++ b/src/templates/products.html @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + Login + @css 'src/templates/products.css' + + +
@include 'header_component.html'
+

Hi, ${user.username}! you are online

+ +
+
+
+ + +
+
+ +
+
+ +
+ +
+ + + + + + + + + + + @for product in user.products + + + + + + @end + +
IDNameCreated date
${product.id}${product.name}${product.created_at}
+
+ + \ No newline at end of file diff --git a/src/templates/student/student.js b/src/templates/student/student.js new file mode 100644 index 0000000..5ca8c3e --- /dev/null +++ b/src/templates/student/student.js @@ -0,0 +1,6 @@ +function checkAttendance() { + // Simulate attendance check (replace with actual logic) + const studentId = document.getElementById('student_id').value; + const attendanceMessage = document.getElementById('attendance_message'); + attendanceMessage.textContent = `Attendance data for student ID ${studentId} is not available in this demo.`; +} \ No newline at end of file diff --git a/src/templates/student/view.html b/src/templates/student/view.html new file mode 100644 index 0000000..61238ed --- /dev/null +++ b/src/templates/student/view.html @@ -0,0 +1,23 @@ + + + + + + Student Attendance + @css '/templates/style.css' + + +
+

Check Attendance

+
+
+
+

Enter your Student ID:

+ + +

+
+
+ @js '/templates/student/attendance.js' + + diff --git a/src/templates/style.css b/src/templates/style.css new file mode 100644 index 0000000..09c0987 --- /dev/null +++ b/src/templates/style.css @@ -0,0 +1,33 @@ +body { + font-family: sans-serif; + margin: 0; + padding: 20px; +} + +header { + text-align: center; +} + +main { + display: flex; + justify-content: center; + align-items: center; + min-height: calc(100vh - 120px); /* Subtract header and footer height */ +} + +.options { + text-align: center; +} + +.options a { + display: block; + margin-bottom: 10px; + padding: 10px 20px; + border: 1px solid #ddd; + text-decoration: none; + color: #000; +} + +.options a:hover { + background-color: #eee; +} diff --git a/v.mod b/v.mod new file mode 100644 index 0000000..a6c67b9 --- /dev/null +++ b/v.mod @@ -0,0 +1,7 @@ +Module { + name: 'v4' + description: 'School Management System' + version: '0.0.0' + license: 'MIT' + dependencies: [] +}