Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User 모델에 user가 마지막으로 사용한 persona의 닉네임을 저장하는 nullable field 추가 #69

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.5 on 2023-04-11 22:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('graphql_app', '0038_alter_postreadingrecord_updated_at'),
]

operations = [
migrations.AddField(
model_name='user',
name='last_used_persona_nickname',
field=models.CharField(blank=True, default=None, max_length=20, null=True, verbose_name='마지막으로 사용한 페르소나의 닉네임'),
),
]
3 changes: 3 additions & 0 deletions back/graphql_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class User(AbstractBaseUser):
email = models.EmailField(verbose_name='유저의 이메일', unique=True)
username = models.CharField(max_length=254, unique=True)
signup_method = models.CharField(max_length=2, choices=SIGN_UP_METHOD_CHOICES, default=EMAIL)
# WARNING : 무결성을 보장하지는 않음
last_used_persona_nickname = models.CharField(max_length=20, null=True, blank=True, default=None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

유저 모델에서 persona 의 존재를 알아야 하는 이유를 잘 이해하지 못했습니다. persona 테이블에 last_used_at 같은 컬럼을 하나 달고, 페르소나 전환 시 마다 갱신해주고

SELECT nickname FROM persona WHERE user_id = 1 ORDER BY last_used_at DESC LIMIT 1;

graphql resolver 에서 이런 쿼리를 호출하도록 하면 어떤가요?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

적어도 nickname 을 2중 보관하는 지금보다는 깔끔한 구조라고 생각했습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그거 좋네용!
명시적으로 어떤 페르소나를 쓰겠다~고 상태를 바꿔주는 API를 써야 할까요? 아니면 알아서 백엔드에서 페르소나에 대한 API가 호출될 때 갱신해줘야 할까요?

verbose_name='마지막으로 사용한 페르소나의 닉네임')
created_at = models.DateTimeField(auto_now_add=True, verbose_name='생성 시각')
updated_at = models.DateTimeField(auto_now_add=True, verbose_name='갱신 시각')

Expand Down
1 change: 1 addition & 0 deletions back/graphql_app/resolvers/model_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class User(relay.Node):
username: auto = strawberry.field(description='사용자 ID (Unique)')
email: auto = strawberry.field(description='사용자 E-mail (Unique)')
signup_method: auto = strawberry.field(description='로그인 방법')
last_used_persona_nickname: Optional[str] = strawberry.field(description='마지막으로 사용한 페르소나의 닉네임')

created_at: auto = strawberry.field(description='생성 시각')
updated_at: auto = strawberry.field(description='갱신 시각')
Expand Down