Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
2b43c90
refactor: クエリを分けるためにファイル名を変更
kasa021 Oct 5, 2023
60b7fa2
feat:データベースにユーザーテーブルを作成
kasa021 Oct 5, 2023
8031db3
fix: UNIQUE KEY(username)を削除
kasa021 Oct 5, 2023
1833e57
fix:bioをtextからvarchar(1024)に修正
kasa021 Oct 5, 2023
3bc4414
fix:created_at,updated_atをCURRENT_TIMEATAMPを削除
kasa021 Oct 5, 2023
0d567bf
Merge pull request #48 from saitamau-maximum/feat/project-user-user-t…
a01sa01to Oct 6, 2023
d9e7271
feat:ユーザー一覧を取得するAPIを作成
kasa021 Oct 8, 2023
e540ac5
ユーザーをpostするapiを作成
kasa021 Oct 8, 2023
1b1cf20
refactor: POST,Userの構造体をmodel.goに切り分けた
kasa021 Oct 8, 2023
709ce3a
feat: build check用のCI追加
seiei-n Oct 4, 2023
42289cf
feat: Go用のBuild Checkも追加
seiei-n Oct 4, 2023
235f29a
feat: PRが開かれた時にfront, backのbuild checkを並列で行うように変更
seiei-n Oct 6, 2023
217c83d
feat: トリガー修正
seiei-n Oct 6, 2023
bc1a7bc
feat: posts.created_atにインデックスを作成
yukikamome316 Oct 5, 2023
214c5c9
feat: migration.goにmigrationの処理を移行
yukikamome316 Oct 5, 2023
9ef03f3
fix: indexを作成するクエリを削除
yukikamome316 Oct 5, 2023
e8a516a
fix: クエリの修正
yukikamome316 Oct 5, 2023
37680ce
fix: インデックス名の変更
yukikamome316 Oct 5, 2023
8676559
Merge pull request #52 from saitamau-maximum/feat/project-user-get-al…
a01sa01to Oct 8, 2023
b5a9894
refactor: POST,Userの構造体をmodel.goに切り分けた
kasa021 Oct 8, 2023
685e72f
feat: build check用のCI追加
seiei-n Oct 4, 2023
ad7f522
feat: Go用のBuild Checkも追加
seiei-n Oct 4, 2023
a4726d1
feat: PRが開かれた時にfront, backのbuild checkを並列で行うように変更
seiei-n Oct 6, 2023
83adb1e
feat: トリガー修正
seiei-n Oct 6, 2023
8562aed
feat: posts.created_atにインデックスを作成
yukikamome316 Oct 5, 2023
073c94a
feat: migration.goにmigrationの処理を移行
yukikamome316 Oct 5, 2023
9453850
fix: indexを作成するクエリを削除
yukikamome316 Oct 5, 2023
46b8993
fix: クエリの修正
yukikamome316 Oct 5, 2023
06287f4
fix: インデックス名の変更
yukikamome316 Oct 5, 2023
2210338
Merge pull request #53 from saitamau-maximum/feat/project-user-post-user
a01sa01to Oct 15, 2023
01be9d6
componentsにUserSelectBox.jsxを追加
Oct 17, 2023
817552e
UserSelectBoxの見た目をexport
Oct 17, 2023
3b2384c
UserSelectBoxをApp.jsxに引っ張ってきた
Oct 17, 2023
3f7de3b
ラベルとidの名前を変更した
Oct 17, 2023
65b0f1e
サンプルを削除
Oct 17, 2023
2154382
サンプル復元
Oct 17, 2023
5349cee
ユーザーセレクトボックスを表示させた。
Oct 19, 2023
a136ac7
変数名をわかりやすく変更user->selectedUser
Oct 23, 2023
6b16338
ユーザー一覧を取得してSelectBoxの選択肢に載せるようにした
Oct 23, 2023
8208a59
selectedUserの取り扱う値をユーザーIDにした
Oct 23, 2023
888e8ce
Merge branch 'feat-UserSelectBox' into feat/UserSelectBox
Oct 23, 2023
b47562b
ユーザー情報の表示の際、user.nameで正しく取得できるようにした
Oct 29, 2023
49fbdd0
mapの要素にkeyを追加
Oct 29, 2023
f6cca13
Merge pull request #83 from saitamau-maximum/feat/UserSelectBox
a01sa01to Oct 29, 2023
2559997
投稿のbody内にユーザーIDを含めるようにした
Oct 30, 2023
6f040f9
App.jsxのselectedUserをFormのモノとつなげた
Oct 30, 2023
db3c8ba
投稿作成者のIDをポストテーブルに追加
Oct 30, 2023
6b45fff
手法を変更するためいったん戻した
Oct 30, 2023
f3d5b4e
URLを用いてIDをやり取りする方針
Oct 30, 2023
481eb90
go側でIDを受け取る
Oct 30, 2023
8d42d9c
psottalbeに作成者IDを追加
Oct 30, 2023
a20c1d5
issueの内容を今理解した。もどした
Oct 31, 2023
11abf6a
BodyにUser_IDを含めるようにした
Nov 6, 2023
a18aa91
省略した
Nov 6, 2023
cce3423
Merge pull request #93 from saitamau-maximum/feature/get_user_id
a01sa01to Nov 10, 2023
75c4c50
ユーザー登録画面のためのAssign-User.jsxを作成
Nov 20, 2023
908f668
componentsに移動
Nov 20, 2023
982dc7f
試しにボックスを配置、出力
Nov 21, 2023
43881ef
書き方を省略した
Nov 21, 2023
d8024aa
React Routerの実装をもらうためdevelopmentをmergeした。migration.goとmodel.goは削除し、mo…
Nov 21, 2023
f7a977f
自身の環境で動かすためreact-router-domをnpmで取得
Nov 21, 2023
d3b52a6
Assignのルートを設置
Nov 21, 2023
f531e93
exact を追加、完全一致の場合のみ表示
Nov 21, 2023
f3e4fa5
nabigateを導入して登録後はホームに戻ってくるようにした
Nov 21, 2023
e1748c4
Assign からRegisterationに変更。登録完了を伝えるメッセージをついか
Nov 21, 2023
6a269b7
場所を中央に変更
Nov 21, 2023
0676c64
react-router導入し直し。コミットされてしまっていた方のnode_modulesを削除
Nov 22, 2023
df790dc
git rmでnode_modulesを削除
Nov 22, 2023
7741ff7
package-lock.json及びpackage.jsonをgit rmにより削除
Nov 22, 2023
c72db77
pathをRegistrationからregistrationに変更
Dec 10, 2023
11483fd
Merge pull request #97 from saitamau-maximum/feat/assign-user
a01sa01to Dec 10, 2023
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
48 changes: 46 additions & 2 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ type Handler struct {
}

type Post struct {
ID string `db:"id" json:"id"`
Body string `db:"body" json:"body"`
ID string `db:"id" json:"id"`
Body string `db:"body" json:"body"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
}

type User struct {
ID string `db:"id" json:"id"`
Name string `db:"username" json:"name"`
CreatedAt string `db:"created_at" json:"created_at"`
UpdatedAt string `db:"updated_at" json:"updated_at"`
ProfileImageURL string `db:"profile_image_url" json:"profile_image_url"`
Bio string `db:"bio" json:"bio"`
}

var (
SQL_PATH = "./sql"
IMAGES_DIR = "./public/images"
Expand Down Expand Up @@ -104,6 +113,8 @@ func main() {
e.Logger.Info("health check")
return c.JSON(200, "ok")
})
api.GET("/users", h.GetUsers)
api.POST("/users/new", h.CreateUser)
e.Logger.Fatal(e.Start(":8000"))
}

Expand Down Expand Up @@ -199,3 +210,36 @@ func (h *Handler) CreatePost(c echo.Context) error {

return c.JSON(200, post)
}

func (h *Handler) GetUsers(c echo.Context) error {
users := []User{}
err := h.DB.Select(&users, "SELECT * FROM users")
if err != nil {
h.Logger.Error(err)
return c.JSON(500, err)
}
return c.JSON(200, users)
}

func (h *Handler) CreateUser(c echo.Context) error {
id, err := uuid.NewRandom()
if err != nil {
h.Logger.Error(err)
return c.JSON(500, err)
}
user := new(User)
if err := c.Bind(user); err != nil {
h.Logger.Error(err)
return c.JSON(500, err)
}
user.ID = id.String()
user.CreatedAt = time.Now().Format("2006-01-02 15:04:05")
user.UpdatedAt = time.Now().Format("2006-01-02 15:04:05")

_, err = h.DB.Exec("INSERT INTO users (id, username, created_at, updated_at, profile_image_url, bio) VALUES (?, ?, ?, ?, ?, ?)", user.ID, user.Name, user.CreatedAt, user.UpdatedAt, user.ProfileImageURL, user.Bio)
if err != nil {
h.Logger.Error(err)
return c.JSON(500, err)
}
return c.JSON(200, user)
}
File renamed without changes.
9 changes: 9 additions & 0 deletions backend/sql/2_create_user_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `users` (
`id` varchar(36) NOT NULL COMMENT 'ユーザーID',
`username` varchar(255) NOT NULL COMMENT 'ユーザー名',
`created_at` datetime NOT NULL COMMENT '登録日時',
`updated_at` datetime NOT NULL COMMENT '更新日時',
`profile_image_url` varchar(255) DEFAULT NULL COMMENT 'プロフィール画像のURL',
`bio` varchar(1024) DEFAULT NULL COMMENT '自己紹介文',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
26 changes: 13 additions & 13 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@mui/material": "^5.14.11",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.17.0"
"react-router-dom": "^6.19.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CssBaseline } from "@mui/material";
import { GlobalStyles } from "@mui/material";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import { BrowserRouter as Router, Route, Routes,Link } from "react-router-dom";
import { Header } from "./components/Header";
import { ColorModeProvider } from "./components/theme/ColorModeProvider.jsx";
import { ToggleTheme } from "./components/theme/ToggleTheme.jsx";
import { Home } from "./pages/Home.jsx";
import { Registration } from "./pages/Registration.jsx";

function App() {
return (
Expand All @@ -22,7 +23,8 @@ function App() {
/>
<Router>
<Routes>
<Route path="/" element={<Home />}></Route>
<Route exact path="/" element={<Home />}></Route>
<Route path="/registration" element={<Registration />}></Route>
</Routes>
</Router>
</ColorModeProvider>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Form.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Box, Button, FormLabel, TextField } from "@mui/material";
import { useState } from "react";

export const Form = ({ onSubmitted }) => {
export const Form = ({ onSubmitted ,selectedUser}) => {
const [body, setBody] = useState("");
const [isSending, setIsSending] = useState(false);

const sendPost = async (e) => {
e.preventDefault();
setIsSending(true);
const res = await fetch("/api/posts", {
const res = await fetch(`/api/posts`, {
method: "POST",
body: JSON.stringify({ body }),
body: JSON.stringify({ body,user_id:selectedUser }),
headers: {
"Content-Type": "application/json",
},
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/components/UserSelectBox.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
FormControl,
InputLabel,
Select,
MenuItem,
} from '@mui/material';


export const UserSelectBox = ({users,selectedUser, handleChange}) =>{
return(
<>
<FormControl fullWidth>
<InputLabel id="user">User</InputLabel>
<Select
labelId="user"
id="user"
value={selectedUser}
label="User"
onChange={handleChange}
>
{users.map((user) => (
<MenuItem value = {user.id} key = {user.id}>{user.name}</MenuItem>
))}
</Select>
</FormControl>
</>
)
}
39 changes: 37 additions & 2 deletions frontend/src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { Container } from "@mui/material";
import { useEffect, useState } from "react";
import { Form } from "../components/Form";
import { Timeline } from "../components/Timeline";
import { UserSelectBox } from "../components/UserSelectBox";
import { Link } from "react-router-dom";

export const Home = () => {
const [posts, setPosts] = useState([]);
const [users, setUsers] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [selectedUser, setSelectedUser] = useState('');//現在選択されているユーザーidを保持する変数
const onSubmitted = (post) => {
setPosts([post, ...posts]);
};
Expand All @@ -22,8 +26,23 @@ export const Home = () => {
setIsLoading(false);
};

const fetchUsers = async () =>{
const res = await fetch("/api/users");
if(res.ok){
const data = await res.json();
setUsers(data);
} else{
console.error(data);
}
}
//セレクトボックスの人が変更されたときに呼ばれるハンドラ関数
const handleChange = (event) => {
setSelectedUser(event.target.value);
};

useEffect(() => {
fetchPosts();
fetchUsers();
}, []);

return (
Expand All @@ -33,8 +52,24 @@ export const Home = () => {
py: 3,
}}
>
<Form onSubmitted={onSubmitted} />
<Timeline posts={posts} isLoading={isLoading} fetchPosts={fetchPosts} />
<div>
<Link to={"/registration"}>ユーザー登録</Link>
</div>
<UserSelectBox
users={users}
selectedUser={selectedUser}
handleChange={handleChange}
/>
<Form
onSubmitted={onSubmitted}
selectedUser={selectedUser}
/>
<Timeline
posts={posts}
isLoading={isLoading}
fetchPosts={fetchPosts}
/>

</Container>
);
};
Loading