Skip to content

Commit

Permalink
Merge pull request #16 from fy23-gw-gackathon/feature/#15_use_job_queue
Browse files Browse the repository at this point in the history
変換処理をworkerで動かす
  • Loading branch information
gari8 committed May 7, 2023
2 parents 4532dc0 + 426f60a commit b5135f0
Show file tree
Hide file tree
Showing 38 changed files with 555 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tmp_dir = "tmp"
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata", "docs"]
exclude_dir = ["assets", "tmp", "vendor", "testdata", "docs", "worker"]
exclude_regex = ["_test.go"]
exclude_unchanged = false
full_bin = ""
Expand Down
33 changes: 33 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ services:
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
env_file:
- .env
environment:
AWS_SDK_LOAD_CONFIG: "true"
DATABASE_URL: "db:db@tcp(db:3306)/db?charset=utf8&parseTime=true"
DATASTORE_ADDRESS: "redis:6379"
TZ: Asia/Tokyo
db:
image: mysql:8.0
Expand All @@ -38,5 +41,35 @@ services:
- ./data/init:/docker-entrypoint-initdb.d
ports:
- "3306:3306"
redis:
image: redis:alpine
container_name: redis
command: ["redis-server", "/usl/local/etc/redis/redis.conf"]
healthcheck:
test: [ "CMD", "redis-cli", "--raw", "incr", "ping", "|", "grep", "PONG" ]
timeout: 5s
retries: 5
start_period: 5s
volumes:
- ./data/redis/redis.conf:/usl/local/etc/redis/redis.conf
ports:
- "6379:6379"
worker:
container_name: worker
build:
context: .
dockerfile: worker/Dockerfile
volumes:
- .:/app
depends_on:
redis:
condition: service_healthy
env_file:
- .env
environment:
DATASTORE_ADDRESS: "redis:6379"
TZ: Asia/Tokyo
ports:
- "8081:8081"


2 changes: 2 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
database:
url: ""
datastore:
address: "127.0.0.1:6379"
app:
debug: "false"
port: 8080
Expand Down
5 changes: 5 additions & 0 deletions config/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import (

type Config struct {
Database `yaml:"database"`
Datastore `yaml:"datastore"`
App `yaml:"app"`
OpenAI `yaml:"openAI"`
AllowOrigins []string `yaml:"allowOrigins"`
Cognito `yaml:"cognito"`
}

type Datastore struct {
Address string `yaml:"address"`
}

type App struct {
Debug bool `yaml:"debug"`
Port int `yaml:"port"`
Expand Down
3 changes: 2 additions & 1 deletion controller/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package controller

import (
"github.com/fy23-gw-gackathon/reportify-backend/entity"
"golang.org/x/net/context"
"reportify-backend/entity"
)

type UserUseCase interface {
Expand All @@ -21,4 +21,5 @@ type ReportUseCase interface {
GetReport(ctx context.Context, organizationID, reportID string) (*entity.Report, error)
GetReports(ctx context.Context, organizationID string) ([]*entity.Report, error)
CreateReport(ctx context.Context, organizationID, userID, body string, task []entity.Task) (*entity.Report, error)
ReviewReport(ctx context.Context, reportId, reviewBody string) error
}
2 changes: 1 addition & 1 deletion controller/organization.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package controller

import (
"github.com/fy23-gw-gackathon/reportify-backend/entity"
"github.com/gin-gonic/gin"
"net/http"
"reportify-backend/entity"
)

type OrganizationController struct {
Expand Down
31 changes: 25 additions & 6 deletions controller/report.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package controller

import (
"github.com/fy23-gw-gackathon/reportify-backend/entity"
"github.com/gin-gonic/gin"
"net/http"
"reportify-backend/entity"
"time"
)

Expand Down Expand Up @@ -40,15 +40,15 @@ type ReportResponse struct {

// GetReports godoc
// @Summary 日報リスト取得API
// @Tags Report
// @Accept json
// @Produce json
// @Tags Report
// @Accept json
// @Produce json
// @Param organizationCode path string true "組織コード"
// @Success 200 {object} ReportsResponse "OK"
// @Failure 400 {object} entity.ErrorResponse "BadRequest"
// @Failure 401 {object} entity.ErrorResponse "Unauthorized"
// @Failure 403 {object} entity.ErrorResponse "Forbidden"
// @Failure 404 {object} entity.ErrorResponse "Not Found"
// @Failure 404 {object} entity.ErrorResponse "Not Found"
// @Router /organizations/{organizationCode}/reports [get]
// @Security Bearer
func (c *ReportController) GetReports(ctx *gin.Context) (interface{}, error) {
Expand Down Expand Up @@ -79,7 +79,7 @@ func (c *ReportController) GetReports(ctx *gin.Context) (interface{}, error) {
// @Accept json
// @Produce json
// @Param organizationCode path string true "組織コード"
// @Param reportId path string true "日報ID"
// @Param reportId path string true "日報ID"
// @Success 200 {object} ReportResponse "OK"
// @Failure 401 {object} entity.ErrorResponse "Unauthorized"
// @Failure 403 {object} entity.ErrorResponse "Forbidden"
Expand Down Expand Up @@ -143,3 +143,22 @@ func (c *ReportController) CreateReport(ctx *gin.Context) (interface{}, error) {
Tasks: report.Tasks,
}, nil
}

// ReviewReport godoc
// @Summary バッチ処理用の日報レビューAPI
// @Tags Report
// @Accept json
// @Produce json
// @Param reportId path string true "日報ID"
// @Param request body entity.ReviewReportRequest true "日報レビューリクエスト"
// @Success 204 "No Content"
// @Failure 404 {object} entity.ErrorResponse "Not Found"
// @Router /reports/{reportId} [put]
func (c *ReportController) ReviewReport(ctx *gin.Context) (interface{}, error) {
var req *entity.ReviewReportRequest
if err := ctx.Bind(&req); err != nil {
return nil, entity.NewError(http.StatusBadRequest, err)
}
reportID := ctx.Params.ByName("reportId")
return nil, c.ReportUseCase.ReviewReport(ctx, reportID, req.ReviewBody)
}
2 changes: 1 addition & 1 deletion controller/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package controller

import (
"errors"
"github.com/fy23-gw-gackathon/reportify-backend/entity"
"github.com/gin-gonic/gin"
"net/http"
"reportify-backend/entity"
"strings"
)

Expand Down
Empty file added data/redis/redis.conf
Empty file.
63 changes: 57 additions & 6 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,49 @@ const docTemplate = `{
}
}
},
"/reports/{reportId}": {
"put": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Report"
],
"summary": "バッチ処理用の日報レビューAPI",
"parameters": [
{
"type": "string",
"description": "日報ID",
"name": "reportId",
"in": "path",
"required": true
},
{
"description": "日報レビューリクエスト",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/entity.ReviewReportRequest"
}
}
],
"responses": {
"204": {
"description": "No Content"
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/entity.ErrorResponse"
}
}
}
}
},
"/users/me": {
"get": {
"security": [
Expand Down Expand Up @@ -706,6 +749,14 @@ const docTemplate = `{
}
}
},
"entity.ReviewReportRequest": {
"type": "object",
"properties": {
"reviewBody": {
"type": "string"
}
}
},
"entity.Task": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -773,12 +824,12 @@ const docTemplate = `{

// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "",
Host: "",
BasePath: "",
Schemes: []string{},
Title: "",
Description: "",
Version: "1.0",
Host: "localhost:8080",
BasePath: "/",
Schemes: []string{"http"},
Title: "Reportify",
Description: "Reportify",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
}
Expand Down
61 changes: 60 additions & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"schemes": [
"http"
],
"swagger": "2.0",
"info": {
"contact": {}
"description": "Reportify",
"title": "Reportify",
"contact": {},
"version": "1.0"
},
"host": "localhost:8080",
"basePath": "/",
"paths": {
"/organizations": {
"get": {
Expand Down Expand Up @@ -486,6 +494,49 @@
}
}
},
"/reports/{reportId}": {
"put": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Report"
],
"summary": "バッチ処理用の日報レビューAPI",
"parameters": [
{
"type": "string",
"description": "日報ID",
"name": "reportId",
"in": "path",
"required": true
},
{
"description": "日報レビューリクエスト",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/entity.ReviewReportRequest"
}
}
],
"responses": {
"204": {
"description": "No Content"
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/entity.ErrorResponse"
}
}
}
}
},
"/users/me": {
"get": {
"security": [
Expand Down Expand Up @@ -694,6 +745,14 @@
}
}
},
"entity.ReviewReportRequest": {
"type": "object",
"properties": {
"reviewBody": {
"type": "string"
}
}
},
"entity.Task": {
"type": "object",
"properties": {
Expand Down
Loading

0 comments on commit b5135f0

Please sign in to comment.