Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 11257d2

Browse files
committed
themesよむところをなくす
1 parent 8e31fdb commit 11257d2

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

‎webapp/go/top_handler.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ func getStreamerThemeHandler(c echo.Context) error {
8080
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user: "+err.Error())
8181
}
8282

83-
themeModel := ThemeModel{}
84-
if err := tx.GetContext(ctx, &themeModel, "SELECT * FROM themes WHERE user_id = ?", userModel.ID); err != nil {
85-
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user theme: "+err.Error())
86-
}
83+
// themeModel := ThemeModel{}
84+
// if err := tx.GetContext(ctx, &themeModel, "SELECT * FROM themes WHERE user_id = ?", userModel.ID); err != nil {
85+
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to get user theme: "+err.Error())
86+
// }
8787

8888
if err := tx.Commit(); err != nil {
8989
return echo.NewHTTPError(http.StatusInternalServerError, "failed to commit: "+err.Error())
9090
}
9191

9292
theme := Theme{
93-
ID: themeModel.ID,
94-
DarkMode: themeModel.DarkMode,
93+
ID: userModel.ID,
94+
DarkMode: userModel.DarkMode,
9595
}
9696

9797
return c.JSON(http.StatusOK, theme)

‎webapp/go/user_handler.go‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type UserModel struct {
3838
DisplayName string `db:"display_name"`
3939
Description string `db:"description"`
4040
HashedPassword string `db:"password"`
41+
DarkMode bool `db:"dark_mode"`
4142
}
4243

4344
type User struct {
@@ -261,9 +262,10 @@ func registerHandler(c echo.Context) error {
261262
DisplayName: req.DisplayName,
262263
Description: req.Description,
263264
HashedPassword: string(hashedPassword),
265+
DarkMode: req.Theme.DarkMode,
264266
}
265267

266-
result, err := tx.NamedExecContext(ctx, "INSERT INTO users (name, display_name, description, password) VALUES(:name, :display_name, :description, :password)", userModel)
268+
result, err := tx.NamedExecContext(ctx, "INSERT INTO users (name, display_name, description, password, darkmode) VALUES(:name, :display_name, :description, :password, :dark_mode)", userModel)
267269
if err != nil {
268270
return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert user: "+err.Error())
269271
}
@@ -275,13 +277,13 @@ func registerHandler(c echo.Context) error {
275277

276278
userModel.ID = userID
277279

278-
themeModel := ThemeModel{
279-
UserID: userID,
280-
DarkMode: req.Theme.DarkMode,
281-
}
282-
if _, err := tx.NamedExecContext(ctx, "INSERT INTO themes (user_id, dark_mode) VALUES(:user_id, :dark_mode)", themeModel); err != nil {
283-
return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert user theme: "+err.Error())
284-
}
280+
// themeModel := ThemeModel{
281+
// UserID: userID,
282+
// DarkMode: req.Theme.DarkMode,
283+
// }
284+
// if _, err := tx.NamedExecContext(ctx, "INSERT INTO themes (user_id, dark_mode) VALUES(:user_id, :dark_mode)", themeModel); err != nil {
285+
// return echo.NewHTTPError(http.StatusInternalServerError, "failed to insert user theme: "+err.Error())
286+
// }
285287

286288
if out, err := exec.Command("pdnsutil", "add-record", "u.isucon.dev", req.Name, "A", "0", powerDNSSubdomainAddress).CombinedOutput(); err != nil {
287289
return echo.NewHTTPError(http.StatusInternalServerError, string(out)+": "+err.Error())
@@ -426,10 +428,10 @@ func verifyUserSession(c echo.Context) error {
426428
}
427429

428430
func fillUserResponse(ctx context.Context, tx *sqlx.Tx, userModel UserModel) (User, error) {
429-
themeModel := ThemeModel{}
430-
if err := tx.GetContext(ctx, &themeModel, "SELECT * FROM themes WHERE user_id = ?", userModel.ID); err != nil {
431-
return User{}, err
432-
}
431+
// themeModel := ThemeModel{}
432+
// if err := tx.GetContext(ctx, &themeModel, "SELECT * FROM themes WHERE user_id = ?", userModel.ID); err != nil {
433+
// return User{}, err
434+
// }
433435

434436
// if err := tx.GetContext(ctx, &image, "SELECT image FROM icons WHERE user_id = ?", userModel.ID); err != nil {
435437
// if !errors.Is(err, sql.ErrNoRows) {
@@ -461,8 +463,8 @@ func fillUserResponse(ctx context.Context, tx *sqlx.Tx, userModel UserModel) (Us
461463
DisplayName: userModel.DisplayName,
462464
Description: userModel.Description,
463465
Theme: Theme{
464-
ID: themeModel.ID,
465-
DarkMode: themeModel.DarkMode,
466+
ID: userModel.ID,
467+
DarkMode: userModel.DarkMode,
466468
},
467469
IconHash: iconHashStr,
468470
}

‎webapp/sql/initdb.d/10_schema.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CREATE TABLE `users` (
2020
`display_name` VARCHAR(255) NOT NULL,
2121
`password` VARCHAR(255) NOT NULL,
2222
`description` TEXT NOT NULL,
23+
`dark_mode` BOOLEAN DEFAULT FALSE,
2324
UNIQUE `uniq_user_name` (`name`)
2425
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
2526

0 commit comments

Comments
 (0)