문제상황
해결방법
스키마
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`hashed_password` varchar(255) NOT NULL,
`profile` varchar(255) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
`name` varchar(255) NOT NULL,
`deleted` tinyint(1) NOT NULL DEFAULT '0',
`type` varchar(255) NOT NULL DEFAULT 'image_us',
PRIMARY KEY (`id`)
)
*deleted는 1비트의 이진수로 해놓았는데 1이면 삭제된 상태,0이면 삭제되지 않은 상태를 나타낸다.
상세코드
def get_user_info(self,user_id):
result=self.db.execute(text("""
select
id,
name,
email,
profile
from users
where id=:user_id
and deleted=0
"""),{'user_id':user_id})
row=result.fetchone()
result.close()
user_info={
'id':row['id'],
'name':row['name'],
'email':row['email'],
'profile':row['profile']
} if row else None
return user_info
*db와 통신하는 model단에서 deleted=0(삭제되지 않은)인 유저의 정보만 불러옴
*model에서 삭제상태 관계없이 불러오고 로직을 처리하는 service단에서 따로 deleted=0인 것들만 필터링해도 가능