Skip to content

Commit

Permalink
Merge branch 'development' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
a01sa01to committed Oct 16, 2023
2 parents be9f399 + 5b36f19 commit c4098cf
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
13 changes: 12 additions & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strconv"
"time"

_ "github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -72,8 +73,18 @@ type Post struct {
}

func (h *Handler) GetPosts(c echo.Context) error {
pageParam := c.QueryParam("page")
if pageParam == "" {
pageParam = "0"
}
page, err := strconv.ParseUint(pageParam, 10, 0)
if err != nil {
return c.JSON(400, err)
}

index := page * 20
posts := []Post{}
err := h.DB.Select(&posts, "SELECT * FROM posts ORDER BY created_at DESC LIMIT 20")
err = h.DB.Select(&posts, "SELECT * FROM posts ORDER BY created_at DESC LIMIT 20 OFFSET ?", index)
if err != nil {
h.Logger.Error(err)
return c.JSON(500, err)
Expand Down
2 changes: 1 addition & 1 deletion backend/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func migrate() {
}

// indexをposts.created_atにつける
_, err = db.Exec("CREATE INDEX posts_latest_idx ON posts (created_at)")
_, err = db.Exec("CREATE INDEX posts_latest_idx ON posts (created_at DESC)")
if err != nil {
log.Println("index already exists")
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<title>Maxitter | タイムライン</title>
</head>
<body>
<header>
<a href="/">
<img src="karilogo.png" width="200" height="60" alt="karilogo">
</a>
</header>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
Expand Down
Binary file added frontend/public/karilogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ function App() {
);
}

export default App;
export default App;
23 changes: 20 additions & 3 deletions frontend/src/components/Timeline.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { Box, Button, Card, CardContent, Typography , CardActionArea } from "@mui/material";
import {
Box,
Button,
Card,
CardContent,
Typography,
CardActionArea,
} from "@mui/material";

const formatDateTime = (dateTimeString) => {
const options = {timeZone: "Asia/Tokyo", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" };
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const options = {
timeZone,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
};
return new Date(dateTimeString).toLocaleString("ja-JP", options);
};

Expand All @@ -23,7 +38,9 @@ export const Timeline = ({ posts, isLoading, fetchPosts }) => {
<CardActionArea>
<CardContent>
<Typography variant="body1">{post.body}</Typography>
<Typography variant="subtitle2" color="text.secondary">{formatDateTime(post.created_at)}</Typography>
<Typography variant="subtitle2" color="text.secondary">
{formatDateTime(post.created_at)}
</Typography>
</CardContent>
</CardActionArea>
</Card>
Expand Down
1 change: 1 addition & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ echo "バックエンドのセットアップが完了しました!"

echo "Dockerのセットアップを開始します..."

docker compose down
docker compose build
docker compose up -d

Expand Down

0 comments on commit c4098cf

Please sign in to comment.