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

【デプロイ用プルリク】デプロイ用にここまで実装したものをmasterに取り込む #8

Merged
merged 76 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
00fb404
Created app directories in backend and frontend directories.
duyoji Aug 11, 2022
c306c01
Impl local strategy of passport.
duyoji Aug 11, 2022
e4c26c1
Impl LocalAuthGuard
duyoji Aug 11, 2022
0ca2320
Impl jwt auth guard.
duyoji Aug 11, 2022
e950460
Created Docker related files for setup db locally.
duyoji Aug 12, 2022
a200ff7
Created db for test with docker_postgres_init.sql
duyoji Aug 12, 2022
c958b04
Setup TypeORM and create User entity to create User table
duyoji Aug 12, 2022
509e072
Imple create-user feature with prisma
duyoji Aug 12, 2022
053ee98
remove unique directive in prisma from email
duyoji Aug 12, 2022
eed66a5
Impl send confirm email feature
duyoji Aug 12, 2022
dc260f4
Added reference for sendgrid module in nest.js
duyoji Aug 12, 2022
f7ae90f
Modified method name from sendHelloMail to sendSignUpConfirmMail
duyoji Aug 12, 2022
c736270
Impl confirmation
duyoji Aug 12, 2022
235df94
modified jwt strategy
duyoji Aug 13, 2022
d28621d
Changed the method name "login" to "signin" and created a type for Si…
duyoji Aug 13, 2022
a8f74cf
Removed console.log
duyoji Aug 13, 2022
8285303
created update method in usersservice
duyoji Aug 13, 2022
19f7b31
Impl refreshToken
duyoji Aug 13, 2022
252ffdd
Modified signup flow a little.
duyoji Aug 13, 2022
d2a66eb
Solved bcrypt 72 problem.
duyoji Aug 13, 2022
f96c450
Impl request password reset and reset password features.
duyoji Aug 13, 2022
d5bd7c6
Merge pull request #2 from tsuyopon-xyz/backend/db
tsuyopon-xyz Aug 13, 2022
d9e11f8
Merge pull request #1 from tsuyopon-xyz/backend/auth
tsuyopon-xyz Aug 13, 2022
68f1cbb
Created migration for post and modified user model in prisma.
duyoji Aug 14, 2022
7aa0fdc
Assign length values to constants for dto.
duyoji Aug 14, 2022
886d6f9
Run nest g resource for REST API and impl create feature for post.
duyoji Aug 14, 2022
2ceb87c
Impl delete post feature.
duyoji Aug 14, 2022
5ce1e5e
Impl find all posts feature.
duyoji Aug 14, 2022
ebad684
Throw UnauthroziedException when a user has not confirmed email when …
duyoji Aug 14, 2022
aaa25bf
Added sort desc for find all posts
duyoji Aug 14, 2022
5a3c8d4
Impl pagination feature.
duyoji Aug 14, 2022
b402d4c
Include total count of posts.
duyoji Aug 14, 2022
974b17e
Merge pull request #3 from tsuyopon-xyz/backend/post
tsuyopon-xyz Aug 14, 2022
b737069
Created the src directory and moved some code to src
duyoji Aug 15, 2022
4620547
Configure cors setting and comment out sending mail part.
duyoji Aug 15, 2022
889b912
Minimum implement signup page.
duyoji Aug 15, 2022
57e9b6d
Created minimum signin page.
duyoji Aug 15, 2022
fc024db
Created Layout, Header and Footer components.
duyoji Aug 15, 2022
31cf31b
moved pages component to features/xx/components
duyoji Aug 16, 2022
62aa105
Created store, slice and asyncThunkAction for signup
duyoji Aug 16, 2022
9efc4da
Impl signin with redux toolkit
duyoji Aug 16, 2022
8750183
Impl logout feature with redux toolkit.
duyoji Aug 16, 2022
c0ce0a0
Separate reducers.
duyoji Aug 16, 2022
d317ffc
Display username left to signout on navbar
duyoji Aug 16, 2022
ebdbc0c
Fix redirect when signedin and signedout status.
duyoji Aug 16, 2022
919f9dd
Merge pull request #4 from tsuyopon-xyz/frontend/auth
tsuyopon-xyz Aug 16, 2022
f36a6d2
Empty commit to start impl frontend/posts
duyoji Aug 17, 2022
ff2f15d
fetch posts with rtk query.
duyoji Aug 17, 2022
befe0f9
Created PostList but no styling.
duyoji Aug 17, 2022
5306361
[WIP] pagination feature in frontend
duyoji Aug 17, 2022
5932c61
Change pagination style in backend.
duyoji Aug 17, 2022
c2a72bf
Impl pagination
duyoji Aug 17, 2022
f6e1439
Impl pagination with router push for history back.
duyoji Aug 17, 2022
ea57778
Impl createPost feature but no update after creating post.
duyoji Aug 18, 2022
c5d70bc
Impl revalidation feature after creating a post.
duyoji Aug 18, 2022
873a770
Imple remove feature and revalidate on success.
duyoji Aug 18, 2022
05c4553
Use overflow-wrap: break-word; for long english text.
duyoji Aug 18, 2022
be1fe45
break line with "\n" by white-space:prewrap
duyoji Aug 18, 2022
a52ce5b
use html-entities library for escape html special chars.
duyoji Aug 18, 2022
d6c6836
Revert "use html-entities library for escape html special chars."
duyoji Aug 18, 2022
82e9708
Added linkable feature in post that includes "http:https://..."
duyoji Aug 18, 2022
577ae17
Display post published date.
duyoji Aug 18, 2022
774d847
Set style for post item.
duyoji Aug 18, 2022
5d24bf6
Merge pull request #5 from tsuyopon-xyz/frontend/posts
tsuyopon-xyz Aug 18, 2022
0e279b9
Fix state id in signinstate
duyoji Aug 19, 2022
e346a8f
Resolved redirect problem with router.push in page components.
duyoji Aug 19, 2022
7f26e12
commit a file that is not saved in the previous commit.
duyoji Aug 19, 2022
a8d52b9
Merge pull request #6 from tsuyopon-xyz/frontend/fix-reload-router-pr…
tsuyopon-xyz Aug 19, 2022
040b570
Use prepares header to get token from store.
duyoji Aug 19, 2022
1493715
Use cookie in backend.
duyoji Aug 19, 2022
1b0e4ca
impl cookie features in backend.
duyoji Aug 19, 2022
9047453
remove tokens from auth state because tokens are used from cookies.
duyoji Aug 19, 2022
4b39b12
Impl auto login feature when flag in localstorage is true for tokens.
duyoji Aug 19, 2022
fac4dac
Changed Some text and comment
duyoji Aug 19, 2022
5e88660
Delete default value in signin form.
duyoji Aug 19, 2022
288eabf
Merge pull request #7 from tsuyopon-xyz/frontend/store-token-not-on-m…
tsuyopon-xyz Aug 19, 2022
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
Prev Previous commit
Next Next commit
Impl createPost feature but no update after creating post.
  • Loading branch information
duyoji committed Aug 18, 2022
commit ea57778e03fd73d3abf26506d7e6ef9f120b87c8
7 changes: 6 additions & 1 deletion backend/app/src/posts/posts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ export class PostsService {
select: {
id: true,
content: true,
authorId: true,
author: {
select: {
id: true,
name: true,
},
},
createdAt: true,
},
});
Expand Down
23 changes: 20 additions & 3 deletions frontend/app/src/features/posts/api/posts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import type {
FindRequestInput,
FindResponse,
FindResponseSuccess,
CreateRequestInput,
CreateResponseSuccess,
} from '../types';

const END_POINT = 'posts';

export const postsApi = createApi({
reducerPath: 'postsApi',
baseQuery: fetchBaseQuery({
Expand All @@ -19,7 +22,7 @@ export const postsApi = createApi({
findPosts: builder.query<FindResponseSuccess, FindRequestInput>({
query: ({ page, take, accessToken }) => {
return {
url: 'posts',
url: END_POINT,
params: {
page,
take,
Expand All @@ -30,7 +33,21 @@ export const postsApi = createApi({
};
},
}),
createPost: builder.mutation<CreateResponseSuccess, CreateRequestInput>({
query: ({ content, accessToken }) => {
return {
method: 'POST',
url: END_POINT,
headers: {
Authorization: `Bearer ${accessToken}`,
},
body: {
content,
},
};
},
}),
}),
});

export const { useFindPostsQuery } = postsApi;
export const { useFindPostsQuery, useCreatePostMutation } = postsApi;
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { useRouter } from 'next/router';
import { useState, type FC } from 'react';
import type { FC } from 'react';
import ReactPaginate from 'react-paginate';
import { useAppSelector } from 'src/app/hooks';
import { useFindPostsQuery } from 'src/features/posts/api/posts';
import { PostList } from '../PostList';
import { PostForm } from '../PostForm';
import paginatorStyles from './paginator.module.css';

const TAKE = 10;
Expand All @@ -14,23 +15,19 @@ export const PostContainer: FC = () => {
const page = isNaN(parseInt(router.query.page as string))
? DEFAULT_PAGE_NUMBER
: parseInt(router.query.page as string);
const { accessToken } = useAppSelector((state) => state.auth.signin);

// src/pages/index.tsx内で、signinしていなかったら、このコンポーネントは使われないため、
// signinState.accessTokenはある前提でこのコンポーネントが読み込まれている
const accessToken = useAppSelector(
(state) => state.auth.signin.accessToken
) as string;

const { data, error, isFetching, isLoading } = useFindPostsQuery({
accessToken: accessToken as string,
page: page,
take: TAKE,
});

console.log({
isFetching,
isLoading,
data,
error,
});

if (isFetching) {
return <p>Fetching...</p>;
}
Expand All @@ -49,7 +46,9 @@ export const PostContainer: FC = () => {

return (
<div>
<PostForm />
<p>トータル {data.total}件</p>

<PostList posts={data.data} />

{/* https://github.com/AdeleD/react-paginate#props */}
Expand Down
71 changes: 71 additions & 0 deletions frontend/app/src/features/posts/components/PostForm/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ChangeEventHandler, FormEventHandler, useState, type FC } from 'react';
import { useAppSelector } from 'src/app/hooks';
import { useCreatePostMutation } from 'src/features/posts/api/posts';
import { CreateRequestInput } from '../../types';
import styles from './style.module.css';

const MAX_CONTENT_LENGTH = 500;

export const PostForm: FC = () => {
// src/pages/index.tsx内で、signinしていなかったら、このコンポーネントは使われないため、
// signinState.accessTokenはある前提でこのコンポーネントが読み込まれている
const accessToken = useAppSelector(
(state) => state.auth.signin.accessToken
) as string;
const [requestInput, setRequestInput] = useState<CreateRequestInput>({
accessToken,
content: '',
});

const [createPost, { error, isLoading, isSuccess, reset }] =
useCreatePostMutation();

if (isSuccess && requestInput.content.length > 0) {
setRequestInput({
...requestInput,
content: '',
});
reset();
}

const onChangeHandler: ChangeEventHandler<HTMLTextAreaElement> = (event) => {
setRequestInput({
...requestInput,
[event.target.name]: event.target.value,
});
};

const onSubmitHandler: FormEventHandler<HTMLFormElement> = (event) => {
event.preventDefault();
createPost(requestInput);
};

const canPost = () => {
if (requestInput.content.trim().length === 0) return false;
// if (MAX_CONTENT_LENGTH < requestInput.content.length) return false;
if (isLoading) return false;

return true;
};

return (
<>
{error ? <p>{JSON.stringify(error)}</p> : null}
<form method="post" onSubmit={onSubmitHandler}>
<textarea
className={styles.textArea}
name="content"
id="content"
value={requestInput.content}
onChange={onChangeHandler}
></textarea>
<div className={styles.belowTextAreaContainer}>
<span>
{requestInput.content.length}/{MAX_CONTENT_LENGTH}
</span>
<input type="submit" value="投稿する" disabled={!canPost()} />
</div>
</form>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.textArea {
width: 100%;
height: 100px;
resize: none;
}

.belowTextAreaContainer {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 1rem;
}
20 changes: 15 additions & 5 deletions frontend/app/src/features/posts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ export type Post = {
createdAt: Date;
};

export interface PostsState {
posts: Post[];
isLoading: boolean;
}

export type FindRequestInput = {
page?: number;
take?: number;
Expand All @@ -32,3 +27,18 @@ export type FindResponseError = {
};

export type FindResponse = FindResponseSuccess | FindResponseError;

export type CreateRequestInput = {
content: string;
accessToken: string;
};

export type CreateResponseSuccess = Post;

export type CreateResponseError = {
message: string;
statusCode: number;
error?: string;
};

export type CreateResponse = CreateResponseSuccess | CreateResponseError;