diff --git a/api_v1/admin.py b/api_v1/admin.py index c4fee19..465ffc4 100644 --- a/api_v1/admin.py +++ b/api_v1/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .user.models.user_information import UserInformation +from api_v1.profile.profile import Profile # Register your models here. -admin.site.register(UserInformation) +admin.site.register(Profile) diff --git a/api_v1/migrations/0002_rebrandUserInformationToProfile.py b/api_v1/migrations/0002_rebrandUserInformationToProfile.py new file mode 100644 index 0000000..63ae086 --- /dev/null +++ b/api_v1/migrations/0002_rebrandUserInformationToProfile.py @@ -0,0 +1,19 @@ +# Generated by Django 5.0.2 on 2024-02-28 19:41 + +from django.conf import settings +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api_v1', '0001_createBasicUserInformation'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.RenameModel( + old_name='UserInformation', + new_name='Profile', + ), + ] diff --git a/api_v1/models.py b/api_v1/models.py index 460966d..69f6446 100644 --- a/api_v1/models.py +++ b/api_v1/models.py @@ -1 +1 @@ -from .user.models.user_information import UserInformation +from api_v1.profile.profile import Profile diff --git a/api_v1/user/__init__.py b/api_v1/profile/__init__.py similarity index 100% rename from api_v1/user/__init__.py rename to api_v1/profile/__init__.py diff --git a/api_v1/user/models/user_information.py b/api_v1/profile/profile.py similarity index 85% rename from api_v1/user/models/user_information.py rename to api_v1/profile/profile.py index 0dbfc5a..7229c28 100644 --- a/api_v1/user/models/user_information.py +++ b/api_v1/profile/profile.py @@ -2,7 +2,7 @@ from django.contrib.auth.models import User from django.db import models -class UserInformation(models.Model): +class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True) display_name = models.CharField(max_length=150, null=False) diff --git a/api_v1/profile/profile_services.py b/api_v1/profile/profile_services.py new file mode 100644 index 0000000..c84b59b --- /dev/null +++ b/api_v1/profile/profile_services.py @@ -0,0 +1,48 @@ +from api_v1.profile.profile import Profile +from django.contrib.auth.models import User +from typing import Optional + + +async def acreate_profile(user: User, *, display_name: Optional[str] = None) -> Profile: + """Async. Create a Profile object for the given profile. + + @param user: The profile to create the Profile object for. + @param display_name: The display name for the profile. If None, the profile's username will be used. + @return: The created Profile object. + """ + profile = await Profile.objects.acreate(user=user, display_name=user.username) + + # Use the given display name if provided. + if display_name is not None: + profile.display_name = display_name + await profile.asave() + + return profile + + +async def aget_profile(user: User) -> Profile: + """Async. Get the Profile object for the given profile. + + @param user: The profile to get the Profile object for. + @return: The Profile object for the given profile. + """ + return await Profile.objects.aget(user) + + +async def aset_user_display_name(user: User, display_name: Optional[str] = None) -> Profile: + """Async. Set the display name for the given profile. + + @param user: The profile to set the display name for. + @param display_name: The display name to set for the profile. If None, the profile's username will be used. + @return: The Profile object for the given profile. + """ + profile = await Profile.objects.aget(user) + + # Set the display name to the given display name, or the profile's username if None. + if display_name is not None: + profile.display_name = display_name + else: + profile.display_name = user.username + + await profile.asave() + return profile diff --git a/api_v1/user/models/__init__.py b/api_v1/user/models/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/api_v1/user/user_services.py b/api_v1/user/user_services.py deleted file mode 100644 index ea2141f..0000000 --- a/api_v1/user/user_services.py +++ /dev/null @@ -1,48 +0,0 @@ -from .models.user_information import UserInformation -from django.contrib.auth.models import User -from typing import Optional - - -async def acreate_user_information(user: User, *, display_name: Optional[str] = None) -> UserInformation: - """Async. Create a UserInformation object for the given user. - - @param user: The user to create the UserInformation object for. - @param display_name: The display name for the user. If None, the user's username will be used. - @return: The created UserInformation object. - """ - user_information = await UserInformation.objects.acreate(user=user, display_name=user.username) - - # Use the given display name if provided. - if display_name is not None: - user_information.display_name = display_name - await user_information.asave() - - return user_information - - -async def aget_user_information(user: User) -> UserInformation: - """Async. Get the UserInformation object for the given user. - - @param user: The user to get the UserInformation object for. - @return: The UserInformation object for the given user. - """ - return await UserInformation.objects.aget(user) - - -async def aset_user_display_name(user: User, display_name: Optional[str] = None) -> UserInformation: - """Async. Set the display name for the given user. - - @param user: The user to set the display name for. - @param display_name: The display name to set for the user. If None, the user's username will be used. - @return: The UserInformation object for the given user. - """ - user_information = await UserInformation.objects.aget(user) - - # Set the display name to the given display name, or the user's username if None. - if display_name is not None: - user_information.display_name = display_name - else: - user_information.display_name = user.username - - await user_information.asave() - return user_information