File size: 3,322 Bytes
504df0f
 
 
 
 
 
2ae57cb
504df0f
 
 
 
2ae57cb
 
504df0f
2ae57cb
504df0f
2ae57cb
 
 
504df0f
 
2ae57cb
 
504df0f
 
2ae57cb
504df0f
 
2ae57cb
 
504df0f
2ae57cb
 
 
504df0f
 
2ae57cb
 
 
 
504df0f
 
2ae57cb
 
504df0f
 
 
2ae57cb
 
 
 
 
504df0f
 
 
 
 
 
 
2ae57cb
504df0f
 
 
 
 
2ae57cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504df0f
 
2ae57cb
 
504df0f
2ae57cb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Database models for the Codingo application.
"""

from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
import json

db = SQLAlchemy()

class Job(db.Model):
    __tablename__ = 'jobs'

    id = db.Column(db.Integer, primary_key=True)
    role = db.Column(db.String(100), nullable=False)
    description = db.Column(db.Text, nullable=False)
    seniority = db.Column(db.String(50), nullable=False)
    skills = db.Column(db.Text, nullable=False)  # JSON string
    company = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime, default=datetime.utcnow)

    recruiter_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
    recruiter = db.relationship('User', backref='posted_jobs')

    def __repr__(self):
        return f"<Job {self.role} at {self.company}>"

class Application(db.Model):
    __tablename__ = 'applications'

    id = db.Column(db.Integer, primary_key=True)
    job_id = db.Column(db.Integer, db.ForeignKey('jobs.id'), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    name = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), nullable=False)
    resume_path = db.Column(db.String(255), nullable=True)
    cover_letter = db.Column(db.Text, nullable=True)
    extracted_features = db.Column(db.Text, nullable=True)
    status = db.Column(db.String(50), default='applied')
    date_applied = db.Column(db.DateTime, default=datetime.utcnow)

    user = db.relationship('User', backref='applications')

    def __repr__(self):
        return f"Application('{self.name}', '{self.email}', Job ID: {self.job_id})"

    def get_profile_data(self):
        try:
            return json.loads(self.extracted_features) if self.extracted_features else {}
        except:
            return {}

# Initialize the database
def init_db(app):
    """Initialize the database with the Flask app."""
    db.init_app(app)

    with app.app_context():
        from backend.models.user import User
        db.create_all()

        # Add sample data if jobs table is empty
        if Job.query.count() == 0:
            sample_jobs = [
                Job(
                    role='Senior Python Developer',
                    description='Experienced developer needed for backend systems.',
                    seniority='Senior',
                    skills=json.dumps(['Python', 'Flask', 'SQL', 'AWS']),
                    company='TechCorp'
                ),
                Job(
                    role='Data Scientist',
                    description='ML model development and statistical analysis.',
                    seniority='Mid',
                    skills=json.dumps(['Python', 'scikit-learn', 'Pandas', 'Spark']),
                    company='DataInsights'
                ),
                Job(
                    role='Frontend Developer',
                    description='Modern web frontend development with React.',
                    seniority='Junior',
                    skills=json.dumps(['HTML', 'CSS', 'JavaScript', 'React']),
                    company='WebSolutions'
                ),

            ]

        for job in sample_jobs:
            db.session.add(job)

        db.session.commit()
        print("Sample jobs added to database.")