Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/week06 #6

Merged
merged 13 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ tasks:
generate:
aliases: [ "gen" ]
cmds:
- 'PATH="{{.TOOLS_DIR}}:$PATH" go generate ./...'
- task: gen:go
- task: gen:types
- task: ent:gen
- task: gen:api

gen:go:
cmds:
- echo "Run go generate ./..."
- 'PATH="{{.TOOLS_DIR}}:$PATH" go generate ./...'

gen:types:
vars:
TYPES: |-
Expand All @@ -146,20 +151,33 @@ tasks:

gen:api:
vars:
API_V1_TYPES: |
API_TYPES: |
client
manager
cmds:
- for: { var: API_V1_TYPES }
task: gen:api-v1
vars:
TYPE: "{{.ITEM}}"
- for: { var: API_V1_TYPES }
task: gen:api-v1-e2e
- for: { var: API_TYPES }
vars:
TYPE: "{{.ITEM}}"
task: gen:api-for-type
# - for: { var: API_V1_TYPES }
# task: gen:api-v1-e2e
# vars:
# TYPE: "{{.ITEM}}"
# - task: gen:api-events
# - task: gen:api-events-e2e

gen:api-for-type:
internal: true
cmds:
- "echo 'generate api for type: {{.TYPE}}'"
- task: gen:api-v1
vars: { TYPE: "{{.TYPE}}" }
- task: gen:api-v1-e2e
vars: { TYPE: "{{.TYPE}}" }
- task: gen:api-events
vars: { TYPE: "{{.TYPE}}" }
- task: gen:api-events-e2e
vars: { TYPE: "{{.TYPE}}" }

gen:api-v1:
internal: true
Expand All @@ -169,8 +187,9 @@ tasks:
DST: "{{.DIR}}/server.gen.go"
PKG: "{{.TYPE}}v1"
cmds:
- "echo 'generate api v1 for: {{.TYPE}}'"
- "mkdir -p {{.DIR}}"
- "{{.TOOLS_DIR}}/oapi-codegen -generate types,server,spec -package {{.PKG}} {{.SRC}} > {{.DST}}"
- "{{.TOOLS_DIR}}/oapi-codegen --old-config-style -generate types,server,spec -package {{.PKG}} {{.SRC}} > {{.DST}}"

gen:api-v1-e2e:
internal: true
Expand All @@ -188,23 +207,23 @@ tasks:
gen:api-events:
internal: true
vars:
SRC: ./api/client.events.swagger.yml
DST_DIR: ./internal/server-client/events
SRC: "./api/{{.TYPE}}.events.swagger.yml"
DST_DIR: "./internal/server-{{.TYPE}}/events"
DST: "{{.DST_DIR}}/events.gen.go"
PKG: clientevents
PKG: "{{.TYPE}}events"
cmds:
- "mkdir -p {{.DST_DIR}}"
- "{{.TOOLS_DIR}}/oapi-codegen --old-config-style -generate skip-prune,types,spec -package {{.PKG}} -o {{.DST}} {{.SRC}}"

gen:api-events-e2e:
internal: true
vars:
SRC: ./api/client.events.swagger.yml
DST_DIR: ./tests/e2e/api/client/events
SRC: "./api/{{.TYPE}}.events.swagger.yml"
DST_DIR: "./tests/e2e/api/{{.TYPE}}/events"
DST: "{{.DST_DIR}}/events.gen.go"
PKG: apiclientevents
PKG: "api{{.TYPE}}events"
cmds:
- echo "[E2E] Generate client events..."
- "echo '[E2E] Generate {{.TYPE}} events...'"
- "mkdir -p {{.DST_DIR}}"
- "{{.TOOLS_DIR}}/oapi-codegen --old-config-style -generate skip-prune,types -package {{.PKG}} {{.SRC}} > {{.DST}}"

Expand Down
8 changes: 5 additions & 3 deletions api/client.events.swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ info:
servers:
- url: ws://localhost:8080/ws
description: Development server
- url: /ws
description: E2E server

paths:
/stub:
Expand Down Expand Up @@ -39,7 +41,7 @@ components:
requestId:
$ref: "#/components/schemas/RequestID"
eventType:
$ref: "#/components/schemas/EventType"
type: string
authorId:
$ref: "#/components/schemas/AuthorID"
body:
Expand All @@ -60,7 +62,7 @@ components:
requestId:
$ref: "#/components/schemas/RequestID"
eventType:
$ref: "#/components/schemas/EventType"
type: string

MessageBlockedEvent:
required: [ eventId, messageId, requestId, eventType ]
Expand All @@ -72,7 +74,7 @@ components:
requestId:
$ref: "#/components/schemas/RequestID"
eventType:
$ref: "#/components/schemas/EventType"
type: string

EventType:
type: string
Expand Down
130 changes: 130 additions & 0 deletions api/manager.events.swagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
openapi: 3.1.0
info:
title: Bank Support Chat Manager Events
version: v1

servers:
- url: ws://localhost:8080/ws
description: Development server
- url: /ws
description: E2E server

paths:
/stub:
get:
description: It uses for generating events. Otherwise it doesn't.
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Event'

components:
schemas:
Event:
oneOf:
- $ref: "#/components/schemas/NewChatEvent"
- $ref: "#/components/schemas/ChatClosedEvent"
- $ref: "#/components/schemas/NewMessageEvent"
discriminator:
propertyName: eventType

NewChatEvent:
required: [ eventId, eventType, chatId, clientId, requestId, canTakeMoreProblems ]
properties:
eventId:
$ref: "#/components/schemas/EventID"
eventType:
type: string
chatId:
$ref: "#/components/schemas/ChatID"
clientId:
$ref: "#/components/schemas/ClientID"
requestId:
$ref: "#/components/schemas/RequestID"
canTakeMoreProblems:
type: boolean

ChatClosedEvent:
required: [ chatId, eventId, eventType, requestId, canTakeMoreProblems ]
properties:
chatId:
$ref: "#/components/schemas/ChatID"
eventId:
$ref: "#/components/schemas/EventID"
eventType:
type: string
requestId:
$ref: "#/components/schemas/RequestID"
canTakeMoreProblems:
type: boolean

NewMessageEvent:
required: [ authorId, body, createdAt, chatId, eventId, eventType, messageId, requestId ]
properties:
authorId:
$ref: "#/components/schemas/ClientID"
body:
type: string
createdAt:
type: string
format: date-time
chatId:
$ref: "#/components/schemas/ChatID"
eventId:
$ref: "#/components/schemas/EventID"
eventType:
type: string
messageId:
$ref: "#/components/schemas/MessageID"
requestId:
$ref: "#/components/schemas/RequestID"

EventType:
type: string
enum:
- NewChatEvent
- ChatClosedEvent
- NewMessageEvent

EventID:
type: string
format: uuid
x-go-type: types.EventID
x-go-name: ID
x-go-type-import:
path: "github.com/ekhvalov/bank-chat-service/internal/types"

ClientID:
type: string
format: uuid
x-go-type: types.UserID
x-go-name: ClientID
x-go-type-import:
path: "github.com/ekhvalov/bank-chat-service/internal/types"

ChatID:
type: string
format: uuid
x-go-type: types.ChatID
x-go-name: ChatID
x-go-type-import:
path: "github.com/ekhvalov/bank-chat-service/internal/types"

RequestID:
type: string
format: uuid
x-go-type: types.RequestID
x-go-name: RequestID
x-go-type-import:
path: "github.com/ekhvalov/bank-chat-service/internal/types"

MessageID:
type: string
format: uuid
x-go-type: types.MessageID
x-go-name: MessageID
x-go-type-import:
path: "github.com/ekhvalov/bank-chat-service/internal/types"
Loading
Loading