update(self, id, **data) - mansukim1125/JudgeInterface GitHub Wiki

Prototype

update(self, id: int, **data: Dict) -> None

์„ค๋ช…

id๋กœ ์ง€์ •๋˜๋Š” ํ•œ ํŠœํ”Œ์„ data๋กœ ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค. perform_update(self, id, **data)์™€ ๋‹ค๋ฅธ ์ ์ด๋ผ๋ฉด ์˜ค๋ฒ„๋ผ์ด๋“œํ•˜์—ฌ data์˜ ํŠน์ • field์˜ ๊ฐ’์„ ๊ฐ€๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‚ฌ์šฉ ์˜ˆ

๋‹ค์Œ์€ Users์˜ ์˜ค๋ฒ„๋ผ์ด๋“œ๋œ update์ž…๋‹ˆ๋‹ค.

def update(self, id: int, **data: Dict):
    if 'password' in data:
        password = data.get('password')
        hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
        data['password'] = hashed_password.decode()

    return super().update(id, **data)

์œ„ ์˜ˆ์‹œ๋ฅผ ๋ณด๋ฉด ์ž…๋ ฅ๋œ password๋ฅผ bcrypt๋ฅผ ํ†ตํ•ด ์•”ํ˜ธํ™”ํ•œ ๊ฐ’์œผ๋กœ ๋ฎ์–ด์”€์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.