Skip to content

Commit

Permalink
Merge pull request #4 from traPtitech/items
Browse files Browse the repository at this point in the history
/items 実装
  • Loading branch information
s9-sukyu authored Mar 27, 2024
2 parents 039f4b1 + 09903be commit 9c75770
Show file tree
Hide file tree
Showing 35 changed files with 1,309 additions and 112 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"database/sql"
"fmt"
"log"
"os"

_ "github.com/go-sql-driver/mysql"
)

func main() {
conn, err := sql.Open("mysql", fmt.Sprintf(
"%s:%s@tcp(%s:%s)/?charset=utf8mb4&parseTime=true",
getEnvOrDefault("MYSQL_USERNAME", "root"),
getEnvOrDefault("MYSQL_PASSWORD", "password"),
getEnvOrDefault("MYSQL_HOST", "127.0.0.1"),
getEnvOrDefault("MYSQL_PORT", "3306"),
))
if err != nil {
panic(err)
}
defer conn.Close()

dbs := []string{
"booq_test",
}

for _, name := range dbs {
if _, err = conn.Exec("DROP DATABASE IF EXISTS " + name); err != nil {
panic(err)
}
if _, err = conn.Exec("CREATE DATABASE `" + name + "` CHARACTER SET = utf8mb4"); err != nil {
panic(err)
}
log.Println("Database `" + name + "` was created")
}
}

func getEnvOrDefault(env string, def string) string {
s := os.Getenv(env)
if len(s) == 0 {
return def
}
return s
}
81 changes: 81 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
push:
branches:
- "main"
pull_request:

jobs:
build:
name: Server build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: mod
run: go mod download
- name: build
run: go build
- uses: actions/upload-artifact@v4
with:
name: booQ
path: booQ
lint:
name: Server lint
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: Install reviewdog
run: curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- name: Install golangci-lint
run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin
- name: golangci-lint
run: golangci-lint run --out-format=line-number | reviewdog -f=golangci-lint -name=golangci-lint -reporter=github-check
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test:
name: Server test
runs-on: ubuntu-latest
needs: [build]
env:
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_DATABASE: booq_test
services:
mysql:
image: mariadb:10.11.7
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: booq_test
ports:
- 3306:3306
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: Setup DB
run: go run .github/workflows/init.go
- name: Run model tests
run: go test . ./model -v -covermode=atomic -vet=off
- name: Run router tests
run: go test . ./router -v -covermode=atomic -vet=off
spectral:
name: OpenApi Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Spectral checks
uses: stoplightio/[email protected]
with:
file_glob: docs/swagger.yml
repo_token: ${{ secrets.GITHUB_TOKEN }}

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20.0-alpine AS build
FROM golang:1.22.0-alpine AS build
ENV CGO_ENABLED=0
ENV DOCKERIZE_VERSION v0.6.1
RUN apk add --update --no-cache git && \
Expand Down
13 changes: 7 additions & 6 deletions compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ services:
image: mariadb:10.6.4
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: booq
MYSQL_DATABASE: booq-v3
MYSQL_USERNAME: root
MYSQL_PASSWORD: password
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
expose:
- '3306'
- "3306"
ports:
- '3306:3306'
- "3306:3306"
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u$$MYSQL_USERNAME -p$$MYSQL_ROOT_PASSWORD
interval: 6s
Expand All @@ -26,13 +26,13 @@ services:
MYSQL_HOST: db
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_DATABASE: booq
MYSQL_DATABASE: booq-v3
DEBUG_USER_NAME: ryoha
volumes:
- './:/app'
- "./:/app"
tty: true
ports:
- '8080:3001'
- "8080:3001"
depends_on:
db:
condition: service_healthy
Expand All @@ -45,3 +45,4 @@ services:
API_URL: sample.yaml
ports:
- "4000:8080"

35 changes: 21 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
version: "3"
services:
db:
image: mariadb:10.6.4
image: mariadb:10.11.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: booq
MYSQL_DATABASE: booq-v3
MYSQL_USERNAME: root
MYSQL_PASSWORD: password
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
expose:
- '3306'
- "3306"
ports:
- '3306:3306'
- "3306:3306"
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u$$MYSQL_USERNAME -p$$MYSQL_ROOT_PASSWORD
interval: 6s
Expand All @@ -27,21 +27,28 @@ services:
MYSQL_HOST: db
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_DATABASE: booq
MYSQL_DATABASE: booq-v3_test
volumes:
- './:/app'
- "./:/app"
tty: true
ports:
- '8080:3001'
- "8080:3001"
depends_on:
db:
condition: service_healthy

swagger:
image: swaggerapi/swagger-ui
volumes:
- ./docs/swagger.yml:/usr/share/nginx/html/sample.yaml
environment:
API_URL: sample.yaml
# swagger:
# image: swaggerapi/swagger-ui
# volumes:
# - ./docs/swagger.yml:/usr/share/nginx/html/sample.yaml
# environment:
# API_URL: sample.yaml
# ports:
# - "4000:8080"

adminer:
image: adminer
restart: always
ports:
- "4000:8080"
- 8000:8080

39 changes: 10 additions & 29 deletions docs/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/itemPosted"
type: "array"
items:
$ref: "#/components/schemas/itemPosted"
"400":
description: "リクエストボディが不正です。"
"403":
Expand Down Expand Up @@ -520,37 +522,13 @@ components:
type: integer
schemas:
isBook:
type: integer
type: boolean
title: isBook
description: |-
アイテム種別
0: 本でない
1: 本
enum:
- 0
- 1
x-enum-varnames:
- notBook
- book
x-enum-descriptions:
- 本ではない物品
-
description: アイテム種別 本でない/本
isEquipment:
type: integer
type: boolean
title: isEquipment
description: |-
アイテム種別
0: 個人所有
1: 備品
enum:
- 0
- 1
x-enum-varnames:
- individual
- equipment
x-enum-descriptions:
- 個人所有
- 備品
description: アイテム種別 個人所有/備品
itemPosted:
type: "object"
properties:
Expand Down Expand Up @@ -963,6 +941,9 @@ components:
memo:
type: "string"
example: "おもしろいのでぜひ読んでください"
transaction:
type: "array"
$ref: "#/components/schemas/transaction"
required:
- id
- itemId
Expand Down
23 changes: 19 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,44 @@ go 1.22

require (
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/go-testfixtures/testfixtures/v3 v3.10.0
github.com/labstack/echo/v4 v4.11.4
github.com/labstack/gommon v0.4.2
github.com/ncw/swift v1.0.53
github.com/stretchr/testify v1.8.4
gorm.io/driver/mysql v1.5.4
gorm.io/gorm v1.25.7
)

require (
github.com/ClickHouse/ch-go v0.58.2 // indirect
github.com/ClickHouse/clickhouse-go/v2 v2.18.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.6.1 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/paulmach/orb v0.11.1 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 9c75770

Please sign in to comment.