forked from kompetenzinventar/ki-backend
return full profile response
This commit is contained in:
62
ki/models.py
62
ki/models.py
@ -42,10 +42,17 @@ class Profile(db.Model):
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"user_id": self.user.id,
|
||||
"nickname": self.nickname,
|
||||
"pronouns": self.pronouns,
|
||||
"volunteerwork": self.volunteerwork,
|
||||
"freetext": self.freetext
|
||||
"freetext": self.freetext,
|
||||
"address": self.address.to_dict(),
|
||||
"contacts": list(
|
||||
map(lambda contact: contact.to_dict(), self.contacts)),
|
||||
"skills": list(map(lambda skill: skill.to_dict(), self.skills)),
|
||||
"languages": list(
|
||||
map(lambda language: language.to_dict(), self.languages))
|
||||
}
|
||||
|
||||
|
||||
@ -58,6 +65,9 @@ class Token(db.Model):
|
||||
|
||||
user = relationship("User", back_populates="tokens")
|
||||
|
||||
def to_dict(self):
|
||||
return {"user_id": self.user_id, "token": self.token}
|
||||
|
||||
|
||||
class Contact(db.Model):
|
||||
__tablename__ = "contact"
|
||||
@ -71,6 +81,14 @@ class Contact(db.Model):
|
||||
contacttype = relationship("ContactType")
|
||||
content = Column(String(200), nullable=False)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"profile_id": self.profile_id,
|
||||
"contacttype": self.contacttype.to_dict(),
|
||||
"content": self.content
|
||||
}
|
||||
|
||||
|
||||
class ContactType(db.Model):
|
||||
__tablename__ = "contacttype"
|
||||
@ -78,6 +96,9 @@ class ContactType(db.Model):
|
||||
id = Column(Integer, primary_key=True)
|
||||
name = Column(String(25), nullable=False)
|
||||
|
||||
def to_dict(self):
|
||||
return {"id": self.id, "name": self.name}
|
||||
|
||||
|
||||
class Address(db.Model):
|
||||
__tablename__ = "address"
|
||||
@ -94,6 +115,19 @@ class Address(db.Model):
|
||||
profile_id = Column(Integer, ForeignKey("profile.id"), nullable=False)
|
||||
profile = relationship("Profile", back_populates="address")
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"name": self.name,
|
||||
"street": self.street,
|
||||
"house_number": self.house_number,
|
||||
"additional": self.additional,
|
||||
"postcode": self.postcode,
|
||||
"city": self.city,
|
||||
"country": self.country,
|
||||
"profile_id": self.profile_id
|
||||
}
|
||||
|
||||
|
||||
class Skill(db.Model):
|
||||
__tablename__ = "skill"
|
||||
@ -104,7 +138,11 @@ class Skill(db.Model):
|
||||
profiles = relationship("ProfileSkill", back_populates="skill")
|
||||
|
||||
def to_dict(self):
|
||||
return {"id": self.id, "name": self.name}
|
||||
return {
|
||||
"id": self.id,
|
||||
"name": self.name,
|
||||
"icon_url": "/skills/{}/icon".format(self.id)
|
||||
}
|
||||
|
||||
|
||||
class ProfileSkill(db.Model):
|
||||
@ -117,6 +155,13 @@ class ProfileSkill(db.Model):
|
||||
profile = relationship("Profile", back_populates="skills")
|
||||
skill = relationship("Skill", back_populates="profiles")
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"profile_id": self.profile_id,
|
||||
"skill": self.skill.to_dict(),
|
||||
"level": self.level
|
||||
}
|
||||
|
||||
|
||||
class Language(db.Model):
|
||||
__tablename__ = "language"
|
||||
@ -127,7 +172,11 @@ class Language(db.Model):
|
||||
profiles = relationship("ProfileLanguage", back_populates="language")
|
||||
|
||||
def to_dict(self):
|
||||
return {"id": self.id, "name": self.name}
|
||||
return {
|
||||
"id": self.id,
|
||||
"name": self.name,
|
||||
"icon_url": "/languages/{}/icon".format(self.id)
|
||||
}
|
||||
|
||||
|
||||
class ProfileLanguage(db.Model):
|
||||
@ -139,3 +188,10 @@ class ProfileLanguage(db.Model):
|
||||
|
||||
profile = relationship("Profile", back_populates="languages")
|
||||
language = relationship("Language", back_populates="profiles")
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"profile_id": self.profile_id,
|
||||
"language": self.language.to_dict(),
|
||||
"level": self.level
|
||||
}
|
||||
|
Reference in New Issue
Block a user