Skip to content

Commit

Permalink
仮コミット
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaki256 committed Nov 23, 2023
1 parent 982ba49 commit 1c2c5bb
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package main

import (
"fmt"
"os"

"github.com/Kaki256/multiple-word-search-backend/internal/handler"
"github.com/Kaki256/multiple-word-search-backend/internal/migration"
"github.com/Kaki256/multiple-word-search-backend/internal/pkg/config"
"github.com/Kaki256/multiple-word-search-backend/internal/repository"
"github.com/go-sql-driver/mysql"

"github.com/jmoiron/sqlx"
"github.com/labstack/echo/v4"
Expand All @@ -16,12 +18,14 @@ import (
)

type Word struct {
Name string `json:"name"`
Name string `json:"name" db:"name"`
Length int `json:"length" db:"length"`
Sort string `json:"sort" db:"sort"`
IsUnvoiced bool `json:"is_unvoiced" db:"is_unvoiced"`
Dictionary string `json:"dictionary" db:"dictionary"`
}

type Dictionary struct {
Words []Word `json:"words"`
}
const dictionaryName = "Basic"

func main() {
e := echo.New()
Expand All @@ -31,7 +35,13 @@ func main() {
e.Use(middleware.Logger())
e.Use(middleware.CORS())

e.POST("/api/dictionary", postDictionaryHandler)
e.POST("/dictionary", postMakeDictionaryHandler)

e.GET("/ping", func(c echo.Context) error {
return c.String(http.StatusOK, "pong\n")
})

e.GET("/search:strRegEx", wordSearchRegExHandler)

// connect to database
db, err := sqlx.Connect("mysql", config.MySQL().FormatDSN())
Expand All @@ -56,12 +66,40 @@ func main() {
e.Logger.Fatal(e.Start(config.AppAddr()))
}

func postDictionaryHandler(c echo.Context) error {
dict := &Dictionary{}
func wordSearchRegExHandler(c echo.Context) error {
searchKey := c.Param("strRegEx")

Check failure on line 70 in main.go

View workflow job for this annotation

GitHub Actions / Build

searchKey declared and not used
dictoinaryName := c.QueryParam("dictName")

Check failure on line 71 in main.go

View workflow job for this annotation

GitHub Actions / Build

dictoinaryName declared and not used

}

Check failure on line 73 in main.go

View workflow job for this annotation

GitHub Actions / Build

missing return

func getDictionaryNameHandler(c echo.Context) error {
dictionaryName := c.QueryParam("dictName")

Check failure on line 76 in main.go

View workflow job for this annotation

GitHub Actions / Build

dictionaryName declared and not used
}

Check failure on line 77 in main.go

View workflow job for this annotation

GitHub Actions / Build

missing return

func postMakeDictionaryHandler(c echo.Context) error {
echo.New().GET("/dictionary/name", getDictionaryNameHandler)
var dict []Word
err := c.Bind(dict)

if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("%+v", err))
}

conf := mysql.Config{
User: os.Getenv("DB_USERNAME"),
Passwd: os.Getenv("DB_PASSWORD"),
Addr: os.Getenv("DB_HOSTNAME") + ":" + os.Getenv("DB_PORT"),
DBName: os.Getenv("DB_DATABASE"),
Collation: "utf8mb4_general_ci",
}
db, err := sqlx.Open("mysql", conf.FormatDSN())
if err != nil {
echo.New().Logger.Fatal(err)
}
defer db.Close()

// 辞書を作る
_, err = db.Exec("INSERT INTO dictionary name VALUES ?", dictionaryName)

return c.JSON(http.StatusOK, dict)
}

0 comments on commit 1c2c5bb

Please sign in to comment.