-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
214 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
module room | ||
|
||
go 1.13 | ||
go 1.14 | ||
|
||
require ( | ||
github.com/carlescere/scheduler v0.0.0-20170109141437-ee74d2f83d82 | ||
github.com/go-sql-driver/mysql v1.5.0 | ||
github.com/gofrs/uuid v3.2.0+incompatible | ||
github.com/gofrs/uuid v3.3.0+incompatible | ||
github.com/gorilla/sessions v1.2.0 | ||
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a | ||
github.com/jinzhu/gorm v1.9.12 | ||
github.com/json-iterator/go v1.1.9 | ||
github.com/jinzhu/gorm v1.9.15 | ||
github.com/json-iterator/go v1.1.10 | ||
github.com/labstack/echo-contrib v0.8.1-0.20200115200653-2d4a7f3c41d8 | ||
github.com/labstack/echo/v4 v4.1.16 | ||
github.com/patrickmn/go-cache v2.1.0+incompatible | ||
github.com/stretchr/testify v1.5.1 | ||
github.com/stretchr/testify v1.6.1 | ||
github.com/traPtitech/traQ v1.0.0-rc.2.0.20200309071637-82e15593b8c0 | ||
github.com/wader/gormstore v0.0.0-20190904144442-d36772af4310 | ||
go.uber.org/zap v1.15.0 | ||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d | ||
google.golang.org/api v0.22.0 | ||
google.golang.org/api v0.29.0 | ||
gopkg.in/gormigrate.v1 v1.6.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package migration | ||
|
||
import ( | ||
"gopkg.in/gormigrate.v1" | ||
) | ||
|
||
// Migrations is all db migrations | ||
func Migrations() []*gormigrate.Migration { | ||
return []*gormigrate.Migration{ | ||
v1(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package migration | ||
|
||
import ( | ||
"github.com/jinzhu/gorm" | ||
"gopkg.in/gormigrate.v1" | ||
) | ||
|
||
// Migrate execute migrations | ||
func Migrate(db *gorm.DB, tables []interface{}) error { | ||
m := gormigrate.New(db, gormigrate.DefaultOptions, Migrations()) | ||
|
||
m.InitSchema(func(tx *gorm.DB) error { | ||
mv1 := gormigrate.New(tx, gormigrate.DefaultOptions, []*gormigrate.Migration{ | ||
{ | ||
ID: "assume existing DB", | ||
Migrate: v1().Migrate, | ||
}, | ||
}) | ||
err := mv1.Migrate() | ||
if err != nil { | ||
return err | ||
} | ||
err = tx.AutoMigrate(tables...).Error | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}) | ||
return m.Migrate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Package migration migrate current struct | ||
package migration | ||
|
||
import ( | ||
"github.com/jinzhu/gorm" | ||
"gopkg.in/gormigrate.v1" | ||
) | ||
|
||
// v1 unique_index:idx_room_uniqueの削除 | ||
func v1() *gormigrate.Migration { | ||
return &gormigrate.Migration{ | ||
ID: "1", | ||
Migrate: func(db *gorm.DB) error { | ||
return db. | ||
Table("rooms"). | ||
RemoveIndex("idx_room_unique").Error | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package router | ||
|
||
import ( | ||
"reflect" | ||
repo "room/repository" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func Test_filterSameRooms(t *testing.T) { | ||
type args struct { | ||
currentRooms []*repo.Room | ||
targetRooms []*repo.Room | ||
} | ||
baseRoom := repo.Room{ | ||
Place: "sample place", | ||
Public: true, | ||
TimeStart: time.Now(), | ||
TimeEnd: time.Now().Add(3 * time.Hour), | ||
} | ||
room1 := baseRoom | ||
room1.Place = "room1" | ||
room2 := baseRoom | ||
room2.Place = "room2" | ||
room3 := baseRoom | ||
room3.Place = "room3" | ||
|
||
tests := []struct { | ||
name string | ||
args args | ||
want []*repo.Room | ||
}{ | ||
{ | ||
name: "nil", | ||
args: args{ | ||
currentRooms: []*repo.Room{ | ||
&baseRoom, | ||
}, | ||
targetRooms: []*repo.Room{ | ||
&baseRoom, | ||
}, | ||
}, | ||
want: []*repo.Room{}, | ||
}, | ||
{ | ||
name: "one ", | ||
args: args{ | ||
currentRooms: []*repo.Room{ | ||
&room1, &room2, | ||
}, | ||
targetRooms: []*repo.Room{ | ||
&room1, &room2, &room3, | ||
}, | ||
}, | ||
want: []*repo.Room{ | ||
&room3, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := filterSameRooms(tt.args.currentRooms, tt.args.targetRooms); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("filterSameRooms() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Submodule web
updated
from 92efb8 to 2c13f2