This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use client"; | |
| import { useReducer } from "react"; | |
| import { fanSpeedInitial, fanSpeedReducer } from "./page-reducer"; | |
| export default function Home() { | |
| const [fanSpeedCurrent, fanSpeedHandler] = useReducer(fanSpeedReducer, fanSpeedInitial); | |
| return ( | |
| <main style={{ padding: 20 }}> | |
| <div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const fanSpeedInitial = { | |
| level: 0, | |
| status: 'OFF' | |
| }; | |
| export const ROTATE_RIGHT_ACTION = | |
| { type: 'ROTATE_RIGHT' }; | |
| export const ROTATE_LEFT_ACTION = | |
| { type: 'ROTATE_LEFT' } | |
| export function fanSpeedReducer(fanSpeed: any, action: any) { | |
| if (action.type == 'ROTATE_RIGHT') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INSTALLED_APPS = [ | |
| 'django.contrib.admin', | |
| 'django.contrib.auth', | |
| 'django.contrib.contenttypes', | |
| 'django.contrib.sessions', | |
| 'django.contrib.messages', | |
| 'django.contrib.staticfiles', | |
| 'rest_framework', | |
| 'notices' | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DATABASES = { | |
| 'default': { | |
| 'ENGINE': 'django.db.backends.mysql', | |
| 'NAME': 'notice_app', | |
| 'USER': 'root', | |
| 'PASSWORD': 'VeryStrongPa55Word$%', | |
| 'HOST': 'localhost', | |
| 'PORT': '3306', | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| REST_FRAMEWORK = { | |
| 'DEFAULT_AUTHENTICATION_CLASSES': [ | |
| 'rest_framework_simplejwt.authentication.JWTAuthentication', | |
| ], | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin | |
| from django.db import models | |
| from django.utils import timezone | |
| from django.utils.translation import gettext_lazy as _ | |
| from .managers import CustomUserManager | |
| from django.core.validators import RegexValidator | |
| phone_validator = RegexValidator(r"^[7-9]{1}[0-9]{9}$", "Exactly 10 digits are required") | |
| class CustomUser(AbstractBaseUser, PermissionsMixin): | |
| mobile = models.CharField(max_length=16, validators=[phone_validator], unique=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.auth.base_user import BaseUserManager | |
| from django.utils.translation import gettext_lazy as _ | |
| class CustomUserManager(BaseUserManager): | |
| def create_user(self, mobile, password, **extra_fields): | |
| if not mobile: | |
| raise ValueError(_("The mobile must be set")) | |
| user = self.model(mobile=mobile, **extra_fields) | |
| user.set_password(password) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Notice(models.Model): | |
| title = models.CharField(max_length=80,unique=True) | |
| description = models.CharField(max_length=255,unique=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NoticeSerializer(serializers.ModelSerializer): | |
| class Meta: | |
| model = Notice | |
| fields = ('__all__') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [ | |
| { | |
| "model": "notices.Notice", | |
| "pk": 1, | |
| "fields": { | |
| "title": "This is Notice 1", | |
| "description": "This is description of Notice 1" | |
| } | |
| }, | |
| { |