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

UserドメインにAgent,Admin情報の追加 #24

Merged
merged 20 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
113f405
✨ (writer/event)UpdateName
Shion1305 Feb 14, 2023
be393db
✅ (uc/line)Httpベーステストのためのクエリからのダミーデータ取得を追加
Shion1305 Feb 14, 2023
66d2baf
✅ (testing/op)UserCreate/UserInfo
Shion1305 Feb 14, 2023
02e8842
✅ (testing/sce)TestUserCreation
Shion1305 Feb 14, 2023
c88ebfd
✅ (testing/sce)UserInfoUpdate
Shion1305 Feb 15, 2023
bbe5d97
🔧 (CI)GitHubActionsCIのON条件を変更
Shion1305 Feb 15, 2023
f56effd
♻️ Member -> User, #21に基づく
Shion1305 Feb 15, 2023
f8319ef
🎨 (settings)Application>Admin -> Service>Authentication
Shion1305 Feb 15, 2023
abe23d0
♻️ Admin -> Agent, according to #21
Shion1305 Feb 15, 2023
d5e097d
🔨 reload.ps1
Shion1305 Feb 15, 2023
36305fe
🙈 DevYAMLファイル,exeファイル,JSON認証ファイルの削除
Shion1305 Feb 15, 2023
639beea
Merge branch 'issue/21' into issue/2
Shion1305 Feb 16, 2023
0baa544
✨ (model)UserModelにAdmin,Agentの追加
Shion1305 Feb 16, 2023
113fe6a
✨ (model)NewRoleLevelメゾット
Shion1305 Feb 17, 2023
1362be0
✨ (entity)Admin,Agentデータの追加
Shion1305 Feb 17, 2023
1755d83
✨ (model/user)TypeにMemberの追加
Shion1305 Feb 17, 2023
ecde8ec
🎨 (model,writer/user)GrantedTimeをポインタに変更
Shion1305 Feb 17, 2023
0e03853
🐛 (writer/user)UpdateDetailにStatus更新の追加
Shion1305 Feb 17, 2023
3e8b9a6
✨ (writer/user)UpdateAgent,UpdateAdmin
Shion1305 Feb 17, 2023
4d28eae
✨ (command/user)UpdateAgent,UpdateAdmin
Shion1305 Feb 17, 2023
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
9 changes: 8 additions & 1 deletion .github/workflows/go test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
name: go test with firestore emulator
on: [ push ]
on:
push:
branches:
- main
- develop
pull_request:
paths:
- '**.go'
jobs:
go-test-with-firestore-emulator:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.idea
.env
.env
setting.dev.yaml
gcloud-credential.json
*.exe
7 changes: 2 additions & 5 deletions pkg/setting/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ package setting

type (
Application struct {
Server Server `yaml:"server"`
Admin Admin `yaml:"admin"`
Server Server `yaml:"server"`
Authentication Authentication `yaml:"authentication"`
}
Server struct {
OnProduction bool `yaml:"on_production"`
Frontend Frontend `yaml:"frontend"`
Backend Backend `yaml:"backend"`
}
Admin struct {
JwtSecret string `yaml:"jwt_secret"`
}
Frontend struct {
Protocol string `yaml:"protocol"`
Domain string `yaml:"domain"`
Expand Down
3 changes: 1 addition & 2 deletions pkg/setting/files/setting.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ application:
domain: "ynufes-mypage.shion.pro"
port: ":1306"
# CONCATING PROTOCOL, DOMAIN, AND PORT TOGETHER SHOULD GIVE THE FULL URL
admin:
jwt_secret: "ADMIN_AUTH_CIPHER_KEY_TEST_TOKEN"
infrastructure:
firestore:
project_id: "ynufes-mypage"
Expand All @@ -27,5 +25,6 @@ third_party:
enable_line_auth: true
service:
authentication:
jwt_secret: "LEN32_AUTH_CIPHER_KEY_TEST_TOKEN"
secure_cookie: true
# YOU CAN DISABLE SECURE COOKIE FOR TESTING PURPOSES
3 changes: 1 addition & 2 deletions pkg/setting/files/setting.testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ application:
domain: "ynufes-mypage.shion.pro"
port: ""
# CONCATING PROTOCOL, DOMAIN, AND PORT TOGETHER SHOULD GIVE THE FULL URL
admin:
jwt_secret: "ADMIN_AUTH_CIPHER_KEY_TEST_TOKEN"
infrastructure:
firestore:
project_id: "ynufes-mypage"
Expand All @@ -29,5 +27,6 @@ third_party:
# DISABLE LINE AUTH ON TESTING
service:
authentication:
jwt_secret: "LEN32_AUTH_CIPHER_KEY_TEST_TOKEN"
secure_cookie: false
# DISABLE SECURE COOKIE ON TESTING
3 changes: 2 additions & 1 deletion pkg/setting/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type (
Authentication Authentication `yaml:"authentication"`
}
Authentication struct {
SecureCookie bool `yaml:"secure_cookie"`
SecureCookie bool `yaml:"secure_cookie"`
JwtSecret string `yaml:"jwt_secret"`
}
)
1 change: 1 addition & 0 deletions reload.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go build -o ynufes-mypage-backend.exe ./svc/cmd/dev/main.go
2 changes: 1 addition & 1 deletion svc/cmd/dev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
log.Fatalf("Failed to start server... %v", err)
return
}
if err := runner.ImplementAdmin(apiV1); err != nil {
if err := runner.ImplementAgent(apiV1); err != nil {
log.Fatalf("Failed to start server... %v", err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion svc/cmd/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
log.Fatalf("Failed to start server... %v", err)
return
}
if err := runner.ImplementAdmin(apiV1); err != nil {
if err := runner.ImplementAgent(apiV1); err != nil {
log.Fatalf("Failed to start server... %v", err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion svc/pkg/config/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var JWT jwt

func init() {
config := setting.Get()
JWT = jwt{JWTSecret: config.Application.Admin.JwtSecret}
JWT = jwt{JWTSecret: config.Application.Authentication.JwtSecret}
}

type jwt struct {
Expand Down
2 changes: 1 addition & 1 deletion svc/pkg/domain/command/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (

type Event interface {
Create(context.Context, event.Event) error
UpdateAll(context.Context, *event.Event) error
UpdateName(context.Context, event.Event) error
Delete(context.Context, *event.Event) error
}
2 changes: 1 addition & 1 deletion svc/pkg/domain/command/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
type Org interface {
Create(context.Context, org.Org) error
Set(context.Context, org.Org) error
UpdateMembers(context.Context, org.Org) error
UpdateUsers(context.Context, org.Org) error
UpdateIsOpen(context.Context, org.Org) error
}
2 changes: 2 additions & 0 deletions svc/pkg/domain/command/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ type User interface {
Create(context.Context, user.User) error
UpdateLine(ctx context.Context, oldUser *user.User, update user.Line) error
UpdateUserDetail(ctx context.Context, oldUser *user.User, update user.Detail) error
UpdateAgent(ctx context.Context, oldUser *user.User, update user.Agent) error
UpdateAdmin(ctx context.Context, oldUser *user.User, update user.Admin) error
UpdateAll(context.Context, user.User) error
Delete(context.Context, user.User) error
}
10 changes: 5 additions & 5 deletions svc/pkg/domain/model/org/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

type (
Org struct {
ID ID
Event event.Event
Name string
Members []user.ID
IsOpen bool
ID ID
Event event.Event
Name string
Users []user.ID
IsOpen bool
}
ID util.ID
)
13 changes: 13 additions & 0 deletions svc/pkg/domain/model/user/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package user

import (
"time"
)

type (
Admin struct {
IsSuperAdmin bool
GrantedTime *time.Time
// if IsSuperAdmin is false, GrantedTime should be nil.
}
)
39 changes: 39 additions & 0 deletions svc/pkg/domain/model/user/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package user

import (
"time"
"ynufes-mypage-backend/svc/pkg/domain/model/util"
"ynufes-mypage-backend/svc/pkg/exception"
)

type (
Agent struct {
Roles []Role
}
Role struct {
ID RoleID
Level RoleLevel
GrantedTime time.Time
}
RoleID util.ID
RoleLevel int
)

const (
Viewer RoleLevel = 1
Editor RoleLevel = 2
Manager RoleLevel = 3
)

func NewRoleLevel(level int) (RoleLevel, error) {
switch RoleLevel(level) {
case Viewer:
return Viewer, nil
case Editor:
return Editor, nil
case Manager:
return Manager, nil
default:
return 0, exception.ErrInvalidRoleLevel
}
}
2 changes: 2 additions & 0 deletions svc/pkg/domain/model/user/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ type (
Status Status
Detail Detail
Line Line
Admin Admin
Agent Agent
}
ID util.ID
Status int
Expand Down
7 changes: 5 additions & 2 deletions svc/pkg/domain/model/user/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ type Type int

const (
TypeNormal Type = 1
TypeMember Type = 2
)

func NewType(t int) (Type, error) {
switch t {
case int(TypeNormal):
switch Type(t) {
case TypeNormal:
return TypeNormal, nil
case TypeMember:
return TypeMember, nil
default:
return -1, errors.New("USER TYPE VALUE IS INVALID")
}
Expand Down
7 changes: 4 additions & 3 deletions svc/pkg/exception/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package exception
import "errors"

var (
ErrorInvalidHeader = errors.New("INVALID Authorization Header")
ErrInvalidJWT = errors.New("INVALID JWT")
ErrIDNotAssigned = errors.New("ID NOT ASSIGNED")
ErrorInvalidHeader = errors.New("INVALID Authorization Header")
ErrInvalidJWT = errors.New("INVALID JWT")
ErrIDNotAssigned = errors.New("ID NOT ASSIGNED")
ErrInvalidRoleLevel = errors.New("INVALID ROLE LEVEL")
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package admin
package agent

import (
"github.com/gin-gonic/gin"
"ynufes-mypage-backend/svc/pkg/registry"
"ynufes-mypage-backend/svc/pkg/schema/admin"
"ynufes-mypage-backend/svc/pkg/schema/agent"
"ynufes-mypage-backend/svc/pkg/uc/event"
)

Expand Down Expand Up @@ -33,7 +33,7 @@ func (uc Event) CreateHandler() gin.HandlerFunc {
if err != nil {
return
}
resp := admin.CreateEventResponse{
resp := agent.CreateEventResponse{
EventID: opt.Event.ID.ExportID(),
EventName: opt.Event.Name,
}
Expand Down
10 changes: 5 additions & 5 deletions svc/pkg/handler/admin/org.go → svc/pkg/handler/agent/org.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package admin
package agent

import (
"github.com/gin-gonic/gin"
Expand All @@ -8,7 +8,7 @@ import (
"ynufes-mypage-backend/pkg/jwt"
"ynufes-mypage-backend/pkg/setting"
"ynufes-mypage-backend/svc/pkg/registry"
"ynufes-mypage-backend/svc/pkg/schema/admin"
"ynufes-mypage-backend/svc/pkg/schema/agent"
"ynufes-mypage-backend/svc/pkg/uc/org"
)

Expand All @@ -23,7 +23,7 @@ func NewOrg(rgst registry.Registry) *Org {
return &Org{
createOrgUC: org.NewCreateOrg(rgst),
infoOrgUC: org.NewInfo(rgst),
jwtSecret: config.Application.Admin.JwtSecret,
jwtSecret: config.Application.Authentication.JwtSecret,
}
}

Expand Down Expand Up @@ -52,7 +52,7 @@ func (o Org) CreateHandler() gin.HandlerFunc {
c.AbortWithStatusJSON(500, gin.H{"error": "failed to create org"})
return
}
resp := admin.CreateOrgResponse{
resp := agent.CreateOrgResponse{
EventID: opt.Org.Event.ID.ExportID(),
EventName: opt.Org.Event.Name,
OrgID: opt.Org.ID.ExportID(),
Expand Down Expand Up @@ -91,7 +91,7 @@ func (o Org) IssueOrgInviteToken() gin.HandlerFunc {
if err != nil {
return
}
resp := admin.IssueOrgInviteTokenResponse{
resp := agent.IssueOrgInviteTokenResponse{
Token: issueJWT,
OrgID: opt.Org.ID.ExportID(),
ValidUntil: time.Now().Add(duration).Format(time.RFC3339),
Expand Down
14 changes: 7 additions & 7 deletions svc/pkg/infra/entity/org/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ type Org struct {
EventID int64 `firestore:"event_id"`
EventName string `firestore:"event_name"`
Name string `firestore:"name"`
Members []int64 `firestore:"member_ids"`
Users []int64 `firestore:"user_ids"`
IsOpen bool `firestore:"is_open"`
}

func (o Org) ToModel() (*org.Org, error) {
var members []user.ID
for i := range o.Members {
members = append(members, identity.NewID(o.Members[i]))
var users []user.ID
for i := range o.Users {
users = append(users, identity.NewID(o.Users[i]))
}
id, err := identity.ImportID(o.ID)
if err != nil {
Expand All @@ -33,8 +33,8 @@ func (o Org) ToModel() (*org.Org, error) {
ID: identity.NewID(o.EventID),
Name: o.EventName,
},
Name: o.Name,
Members: members,
IsOpen: o.IsOpen,
Name: o.Name,
Users: users,
IsOpen: o.IsOpen,
}, nil
}
8 changes: 8 additions & 0 deletions svc/pkg/infra/entity/user/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package entity

type (
Admin struct {
IsSuperAdmin bool `firestore:"admin-super_admin"`
GrantedTime int64 `firestore:"admin-granted_time"`
}
)
12 changes: 12 additions & 0 deletions svc/pkg/infra/entity/user/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package entity

type (
Agent struct {
Roles []Role `firestore:"agent-roles"`
}
Role struct {
ID int64 `firestore:"id"`
Level int `firestore:"level"`
GrantedTime int64 `firestore:"granted_time"`
}
)
Loading