Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hayato24s committed Mar 5, 2024
1 parent 2a44bef commit 350f5c6
Show file tree
Hide file tree
Showing 19 changed files with 82 additions and 186 deletions.
12 changes: 8 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ AUTH_REDIRECT_URL=http://localhost:3000

OAUTH2_GOOGLE_CLIENT_ID=***
OAUTH2_GOOGLE_CLIENT_SECRET=***
OAUTH2_GOOGLE_CALLBACK_URL=http://localhost:8080/google/callback
OAUTH2_GOOGLE_CALLBACK_URL=http://localhost:8080/auth/v3/google/callback

OAUTH2_TWITTER_CLIENT_ID=***
OAUTH2_TWITTER_CLIENT_SECRET=***
OAUTH2_TWITTER_CALLBACK_URL=http://localhost:8080/twitter/callback
OAUTH2_TWITTER_CALLBACK_URL=http://localhost:8080/auth/v3/twitter/callback

OAUTH2_APPLE_CLIENT_ID=***
OAUTH2_APPLE_CLIENT_SECRET=***
OAUTH2_APPLE_CALLBACK_URL=http://localhost:8080/apple/callback
OAUTH2_APPLE_TEAM_ID=***
OAUTH2_APPLE_KEY_ID=***
OAUTH2_APPLE_PRIVATE_KEY=***
OAUTH2_APPLE_CALLBACK_URL=http://localhost:8080/auth/v3/apple/callback

COOKIE_SECURE=false
COOKIE_SESSION_NAME=twinte_session
Expand Down
16 changes: 10 additions & 6 deletions appenv/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ var (
ADDR string = loadString("ADDR")
AUTH_REDIRECT_URL string = loadString("AUTH_REDIRECT_URL")

OAUTH2_GOOGLE_CLIENT_ID string = loadString("OAUTH2_GOOGLE_CLIENT_ID")
OAUTH2_GOOGLE_CLIENT_SECRET string = loadString("OAUTH2_GOOGLE_CLIENT_SECRET")
OAUTH2_GOOGLE_CALLBACK_URL string = loadString("OAUTH2_GOOGLE_CALLBACK_URL")
OAUTH2_GOOGLE_CLIENT_ID string = loadString("OAUTH2_GOOGLE_CLIENT_ID")
OAUTH2_GOOGLE_CLIENT_SECRET string = loadString("OAUTH2_GOOGLE_CLIENT_SECRET")
OAUTH2_GOOGLE_CALLBACK_URL string = loadString("OAUTH2_GOOGLE_CALLBACK_URL")

OAUTH2_TWITTER_CLIENT_ID string = loadString("OAUTH2_TWITTER_CLIENT_ID")
OAUTH2_TWITTER_CLIENT_SECRET string = loadString("OAUTH2_TWITTER_CLIENT_SECRET")
OAUTH2_TWITTER_CALLBACK_URL string = loadString("OAUTH2_TWITTER_CALLBACK_URL")
OAUTH2_APPLE_CLIENT_ID string = loadString("OAUTH2_APPLE_CLIENT_ID")
OAUTH2_APPLE_CLIENT_SECRET string = loadString("OAUTH2_APPLE_CLIENT_SECRET")
OAUTH2_APPLE_CALLBACK_URL string = loadString("OAUTH2_APPLE_CALLBACK_URL")

OAUTH2_APPLE_CLIENT_ID string = loadString("OAUTH2_APPLE_CLIENT_ID")
OAUTH2_APPLE_TEAM_ID string = loadString("OAUTH2_APPLE_TEAM_ID")
OAUTH2_APPLE_KEY_ID string = loadString("OAUTH2_APPLE_KEY_ID")
OAUTH2_APPLE_PRIVATE_KEY string = loadString("OAUTH2_APPLE_PRIVATE_KEY")
OAUTH2_APPLE_CALLBACK_URL string = loadString("OAUTH2_APPLE_CALLBACK_URL")

COOKIE_SECURE bool = loadBool("COOKIE_SECURE")
COOKIE_SESSION_NAME string = loadString("COOKIE_SESSION_NAME")
Expand Down
2 changes: 1 addition & 1 deletion db/gen/model/courses.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions db/gen/model/registered_courses.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions db/gen/query/courses.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions db/gen/query/registered_courses.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions db/gorm_gen.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"log"

"github.com/twin-te/twinte-back/appenv"
"gorm.io/driver/postgres"
"gorm.io/gen"
Expand All @@ -19,15 +21,11 @@ func main() {

db, err := gorm.Open(postgres.Open(appenv.DB_URL))
if err != nil {
panic(err)
log.Fatalln(err)
}
g.UseDB(db)

var dataMap = map[string]func(gorm.ColumnType) (dataType string){
"numeric": func(columnType gorm.ColumnType) (dataType string) {
return "string"
},

"jsonb": func(columnType gorm.ColumnType) (dataType string) {
return "[]byte"
},
Expand All @@ -39,8 +37,6 @@ func main() {

g.WithDataTypeMap(dataMap)

g.WithImportPkgPath("github.com/google/uuid")

g.ApplyBasic(g.GenerateAllTable()...)

g.ApplyBasic(
Expand All @@ -50,7 +46,12 @@ func main() {
),
g.GenerateModel(
"registered_courses",
gen.FieldRelate(field.HasMany, "Tags", g.GenerateModel("registered_course_tags"), nil),
gen.FieldRelate(field.HasMany, "Tags", g.GenerateModel("registered_course_tags"), &field.RelateConfig{
GORMTag: field.GormTag{
"foreignKey": []string{"RegisteredCourse"},
"references": []string{"ID"},
},
}),
),
g.GenerateModel(
"courses",
Expand Down
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ mv ./migrate /usr/local/bin/
```

## Environment Variables
`.env.example`をご参照ください。

### Export
下記のコマンドを実行することで`.env`ファイルに定義されている環境変数を設定することができます。

```sh
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
cloud.google.com/go v0.112.1
github.com/bufbuild/connect-go v1.10.0
github.com/getkin/kin-openapi v0.123.0
github.com/golang-jwt/jwt/v5 v5.2.0
github.com/google/uuid v1.6.0
github.com/labstack/echo/v4 v4.11.4
github.com/oapi-codegen/runtime v1.1.1
Expand All @@ -19,10 +18,10 @@ require (
golang.org/x/sync v0.6.0
google.golang.org/api v0.167.0
google.golang.org/protobuf v1.32.0
gorm.io/driver/postgres v1.5.6
gorm.io/driver/postgres v1.5.4
gorm.io/gen v0.3.25
gorm.io/gorm v1.25.7
gorm.io/plugin/dbresolver v1.5.1
gorm.io/gorm v1.25.6
gorm.io/plugin/dbresolver v1.5.0
)

require (
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
Expand Down Expand Up @@ -291,8 +289,8 @@ gorm.io/datatypes v1.1.1-0.20230130040222-c43177d3cf8c/go.mod h1:SH2K9R+2RMjuX1C
gorm.io/driver/mysql v1.4.3/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c=
gorm.io/driver/mysql v1.5.2 h1:QC2HRskSE75wBuOxe0+iCkyJZ+RqpudsQtqkp+IMuXs=
gorm.io/driver/mysql v1.5.2/go.mod h1:pQLhh1Ut/WUAySdTHwBpBv6+JKcj+ua4ZFx1QQTBzb8=
gorm.io/driver/postgres v1.5.6 h1:ydr9xEd5YAM0vxVDY0X139dyzNz10spDiDlC7+ibLeU=
gorm.io/driver/postgres v1.5.6/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo=
gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0=
gorm.io/driver/sqlite v1.1.6/go.mod h1:W8LmC/6UvVbHKah0+QOC7Ja66EaZXHwUTjgXY8YNWX8=
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
Expand All @@ -305,11 +303,11 @@ gorm.io/gorm v1.22.2/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.6 h1:V92+vVda1wEISSOMtodHVRcUIOPYa2tgQtyF+DfFx+A=
gorm.io/gorm v1.25.6/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/hints v1.1.0 h1:Lp4z3rxREufSdxn4qmkK3TLDltrM10FLTHiuqwDPvXw=
gorm.io/hints v1.1.0/go.mod h1:lKQ0JjySsPBj3uslFzY3JhYDtqEwzm+G1hv8rWujB6Y=
gorm.io/plugin/dbresolver v1.5.1 h1:s9Dj9f7r+1rE3nx/Ywzc85nXptUEaeOO0pt27xdopM8=
gorm.io/plugin/dbresolver v1.5.1/go.mod h1:l4Cn87EHLEYuqUncpEeTC2tTJQkjngPSD+lo8hIvcT0=
gorm.io/plugin/dbresolver v1.5.0 h1:XVHLxh775eP0CqVh3vcfJtYqja3uFl5Wr3cKlY8jgDY=
gorm.io/plugin/dbresolver v1.5.0/go.mod h1:l4Cn87EHLEYuqUncpEeTC2tTJQkjngPSD+lo8hIvcT0=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
8 changes: 7 additions & 1 deletion handler/api/rest/v3/openapi/post_registered_courses.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package openapi

import "encoding/json"
import (
"encoding/json"
)

func FromRegisteredCourse(registeredCourse RegisteredCourse) (res PostRegisteredCourses200JSONResponse, err error) {
res.union, err = json.Marshal(registeredCourse)
Expand All @@ -12,6 +14,10 @@ func FromRegisteredCourses(registeredCourses []RegisteredCourse) (res PostRegist
return
}

func (body *PostRegisteredCoursesJSONRequestBody) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &body.union)
}

func ToPostRegisteredCoursesJSONBody0(reqBody *PostRegisteredCoursesJSONRequestBody) (ret PostRegisteredCoursesJSONBody0, err error) {
err = json.Unmarshal(reqBody.union, &ret)
return
Expand Down
6 changes: 3 additions & 3 deletions handler/api/rest/v3/registered_course.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ func (h *impl) postRegisteredCourses2(ctx context.Context, reqBody openapi.PostR
// 講義を登録する
// (POST /registered-courses)
func (h *impl) PostRegisteredCourses(ctx context.Context, request openapi.PostRegisteredCoursesRequestObject) (openapi.PostRegisteredCoursesResponseObject, error) {
if reqBody, err := openapi.ToPostRegisteredCoursesJSONBody0(request.Body); err != nil {
if reqBody, err := openapi.ToPostRegisteredCoursesJSONBody0(request.Body); err == nil {
apiRegisteredCourse, err := h.postRegisteredCourses0(ctx, reqBody)
if err != nil {
return nil, err
}
return openapi.FromRegisteredCourse(apiRegisteredCourse)
}

if reqBody, err := openapi.ToPostRegisteredCoursesJSONBody1(request.Body); err != nil {
if reqBody, err := openapi.ToPostRegisteredCoursesJSONBody1(request.Body); err == nil {
apiRegisteredCourses, err := h.postRegisteredCourses1(ctx, reqBody)
if err != nil {
return nil, err
}
return openapi.FromRegisteredCourses(apiRegisteredCourses)
}

if reqBody, err := openapi.ToPostRegisteredCoursesJSONBody2(request.Body); err != nil {
if reqBody, err := openapi.ToPostRegisteredCoursesJSONBody2(request.Body); err == nil {
apiRegisteredCourse, err := h.postRegisteredCourses2(ctx, reqBody)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 350f5c6

Please sign in to comment.