Skip to content

Commit

Permalink
OV-52: + merge
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiy4 committed Aug 28, 2024
2 parents a1eeb57 + 46bf15d commit a31d874
Show file tree
Hide file tree
Showing 28 changed files with 270 additions and 15 deletions.
9 changes: 9 additions & 0 deletions backend/src/bundles/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class AuthController extends BaseController {
* format: email
* password:
* type: string
* fullName:
* type: string
* responses:
* 201:
* description: Successful operation
Expand All @@ -131,6 +133,13 @@ class AuthController extends BaseController {
* message:
* type: object
* $ref: '#/components/schemas/User'
* 400:
* description: Failed operation
* content:
* application/json:
* schema:
* type: object
* $ref: '#/components/schemas/Error'
*/

private async signUp(
Expand Down
10 changes: 9 additions & 1 deletion backend/src/bundles/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,17 @@ class AuthService {
return user.toObject();
}

public signUp(
public async signUp(
userRequestDto: UserSignUpRequestDto,
): Promise<UserSignUpResponseDto> {
const { email } = userRequestDto;
const emailExists = await this.userService.findByEmail(email);
if (emailExists) {
throw new HttpError({
message: UserValidationMessage.EMAIL_ALREADY_EXISTS,
status: HttpCode.BAD_REQUEST,
});
}
return this.userService.create(userRequestDto);
}
}
Expand Down
15 changes: 15 additions & 0 deletions backend/src/bundles/users/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,69 @@ class UserEntity implements Entity {

private 'email': string;

private 'fullName': string;

private 'passwordHash': string;

private 'passwordSalt': string;

private constructor({
id,
email,
fullName,
passwordHash,
passwordSalt,
}: {
id: number | null;
email: string;
fullName: string;
passwordHash: string;
passwordSalt: string;
}) {
this.id = id;
this.email = email;
this.fullName = fullName;
this.passwordHash = passwordHash;
this.passwordSalt = passwordSalt;
}

public static initialize({
id,
email,
fullName,
passwordHash,
passwordSalt,
}: {
id: number;
email: string;
fullName: string;
passwordHash: string;
passwordSalt: string;
}): UserEntity {
return new UserEntity({
id,
email,
fullName,
passwordHash,
passwordSalt,
});
}

public static initializeNew({
email,
fullName,
passwordHash,
passwordSalt,
}: {
email: string;
fullName: string;
passwordHash: string;
passwordSalt: string;
}): UserEntity {
return new UserEntity({
id: null,
email,
fullName,
passwordHash,
passwordSalt,
});
Expand All @@ -65,20 +76,24 @@ class UserEntity implements Entity {
public toObject(): {
id: number;
email: string;
fullName: string;
} {
return {
id: this.id as number,
email: this.email,
fullName: this.fullName,
};
}

public toNewObject(): {
email: string;
fullName: string;
passwordHash: string;
passwordSalt: string;
} {
return {
email: this.email,
fullName: this.fullName,
passwordHash: this.passwordHash,
passwordSalt: this.passwordSalt,
};
Expand Down
2 changes: 2 additions & 0 deletions backend/src/bundles/users/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
class UserModel extends AbstractModel {
public 'email': string;

public 'fullName': string;

public 'passwordHash': string;

public 'passwordSalt': string;
Expand Down
4 changes: 3 additions & 1 deletion backend/src/bundles/users/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class UserRepository implements Repository {
}

public async create(entity: UserEntity): Promise<UserEntity> {
const { email, passwordSalt, passwordHash } = entity.toNewObject();
const { email, fullName, passwordSalt, passwordHash } =
entity.toNewObject();

const item = await this.userModel
.query()
.insert({
email,
fullName,
passwordSalt,
passwordHash,
})
Expand Down
5 changes: 3 additions & 2 deletions backend/src/bundles/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class UserService implements Service {
const user = await this.userRepository.create(
UserEntity.initializeNew({
email: payload.email,
passwordSalt: salt, // TODO
passwordHash: hash, // TODO
fullName: payload.fullName,
passwordSalt: salt,
passwordHash: hash,
}),
);

Expand Down
2 changes: 1 addition & 1 deletion backend/src/common/services/open-ai/open-ai.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import OpenAI from 'openai';

import { type Message } from '~/bundles/chat/libs/types/types.js';
import { type BaseConfig } from '~/common/config/base-config.package.js';

import { type Message } from '../../../bundles/chat/libs/types/types.js';
import { CHAT_MODEL, MAX_TOKEN } from './libs/constants/constants.js';
import { type OpenAIService as OpenAIServiceType } from './libs/types/types.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type Knex } from 'knex';

const TABLE_NAME = 'users';

async function up(knex: Knex): Promise<void> {
await knex.schema.table(TABLE_NAME, (table) => {
table.string('full_name').notNullable();
});
}

async function down(knex: Knex): Promise<void> {
await knex.schema.table(TABLE_NAME, (table) => {
table.dropColumn('full_name');
});
}

export { down, up };
Binary file added frontend/src/assets/img/photo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ type Properties = {
label: string;
name: string;
hasError: boolean;
required?: boolean;
};

const PasswordInput: React.FC<Properties> = ({ label, name, hasError }) => {
const PasswordInput: React.FC<Properties> = ({
label,
name,
hasError,
required = false,
}) => {
const [isPasswordVisible, setIsPasswordVisible] = useState<boolean>(false);

const handlePasswordIconClick = useCallback((): void => {
Expand All @@ -31,6 +37,7 @@ const PasswordInput: React.FC<Properties> = ({ label, name, hasError }) => {
placeholder="••••••••"
name={name}
icon="right"
required={required}
/>
<InputRightElement top="unset" bottom={hasError ? '25px' : 0}>
<IconButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ const SignInForm: React.FC<Properties> = ({ onSubmit }) => {
label="Email"
placeholder="[email protected]"
name="email"
required
/>
<PasswordInput
label="Password"
name="password"
hasError={Boolean(errors.password)}
required
/>
<FormError
isVisible={dataStatus === DataStatus.REJECTED}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type UserSignUpRequestDto } from '~/bundles/users/users.js';

const DEFAULT_SIGN_UP_PAYLOAD: UserSignUpRequestDto = {
name: '',
fullName: '',
email: '',
password: '',
confirmPassword: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,27 @@ const SignUpForm: React.FC<Properties> = ({ onSubmit }) => {
type="text"
label="Full Name"
placeholder="Name"
name="name"
name="fullName"
required
/>
<Input
type="email"
label="Email"
placeholder="[email protected]"
name="email"
required
/>
<PasswordInput
label="Password"
name="password"
hasError={Boolean(errors.password)}
required
/>
<PasswordInput
label="Repeat password"
name="confirmPassword"
hasError={Boolean(errors.confirmPassword)}
required
/>
<FormError
isVisible={dataStatus === DataStatus.REJECTED}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/bundles/common/components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { VideoModal } from './video-modal/video-modal.js';
export { DownloadIcon } from '@chakra-ui/icons';
export { ViewIcon, ViewOffIcon } from '@chakra-ui/icons';
export {
Badge,
Box,
Center,
Circle,
Expand All @@ -18,7 +19,9 @@ export {
FormControl,
FormErrorMessage,
Heading,
Icon,
IconButton,
Image,
InputGroup,
InputRightElement,
SimpleGrid,
Expand Down
1 change: 0 additions & 1 deletion frontend/src/bundles/common/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const Header: React.FC<Properties> = ({ left, center, right }) => {
boxShadow="md"
zIndex="1000"
padding="4"
marginBottom="20px"
alignItems="center"
justifyContent="space-between"
>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/bundles/common/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import { Field } from 'formik';
import { useFormField } from '~/bundles/common/hooks/hooks.js';

type Properties<T extends FormValues> = {
type?: 'text' | 'email' | 'number' | 'password';
label: string;
name: FieldInputProps<T>['name'];
type?: 'text' | 'email' | 'number' | 'password';
required?: boolean;
placeholder?: string;
icon?: 'right' | 'none';
};

const Input = <T extends FormValues>({
type = 'text',
label,
name,
type = 'text',
required = false,
placeholder = '',
icon = 'none',
}: Properties<T>): JSX.Element => {
Expand All @@ -30,7 +32,7 @@ const Input = <T extends FormValues>({
const hasError = Boolean(error) && touched;

return (
<FormControl isInvalid={hasError}>
<FormControl isInvalid={hasError} isRequired={required}>
<FormLabel htmlFor={name}>{label}</FormLabel>
<Field
{...field}
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/bundles/common/icons/icon-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { faEllipsisVertical, faPen } from '@fortawesome/free-solid-svg-icons';

const IconName = {
OPTIONS_VERTICAL: faEllipsisVertical,
PEN: faPen,
} as const;

export { IconName };
1 change: 1 addition & 0 deletions frontend/src/bundles/common/icons/icons.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { IconName } from './icon-name.js';
3 changes: 3 additions & 0 deletions frontend/src/bundles/home/components/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { MainContent } from './main-content/main-content.js';
export { VideoCard } from './video-card/video-card.js';
export { VideoSection } from './video-section/video-section.js';
14 changes: 14 additions & 0 deletions frontend/src/bundles/home/components/main-content/main-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Box } from '~/bundles/common/components/components.js';

import { VideoSection } from '../components.js';

const MainContent: React.FC = () => {
return (
<Box bg="background.50" borderRadius="lg" margin="0 25px">
<VideoSection />
<VideoSection />
</Box>
);
};

export { MainContent };
Loading

0 comments on commit a31d874

Please sign in to comment.