Skip to content

Commit

Permalink
[fix] #152
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Aug 12, 2022
1 parent 1c5c0f6 commit ae47db7
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 28 deletions.
1 change: 1 addition & 0 deletions pkg/api/core/group/connection/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
type Input struct {
ConnectionType string `json:"connection_type"`
ConnectionComment string `json:"connection_comment"` // ServiceがETCの時や補足説明で必要
PreferredAP string `json:"preferred_ap"`
NTT string `json:"ntt"`
Address string `json:"address"`
IPv4Route string `json:"ipv4_route"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/core/group/connection/v0/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func AddByAdmin(c *gin.Context) {
return
}

// check preferredAP
err = config.CheckIncludePreferredAPTemplate(input.PreferredAP)
if err != nil {
c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()})
return
}

resultNOC := dbNOC.Get(noc.ID, &core.NOC{Model: gorm.Model{ID: input.NOCID}})
if resultNOC.Err != nil {
c.JSON(http.StatusBadRequest, common.Error{Error: resultNOC.Err.Error()})
Expand Down Expand Up @@ -125,6 +132,7 @@ func AddByAdmin(c *gin.Context) {
IPv4Route: input.IPv4Route,
IPv6Route: input.IPv6Route,
NTT: input.NTT,
PreferredAP: input.PreferredAP,
NOCID: &[]uint{input.NOCID}[0],
TermIP: input.TermIP,
Address: input.Address,
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/core/group/connection/v0/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ func Add(c *gin.Context) {
return
}

// check preferredAP
err = config.CheckIncludePreferredAPTemplate(input.PreferredAP)
if err != nil {
c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()})
return
}

// check NTT (internet)
if connectionTemplate.NeedInternet {
err = config.CheckIncludeNTTTemplate(input.NTT)
if err != nil {
Expand Down Expand Up @@ -196,6 +204,7 @@ func Add(c *gin.Context) {
IPv4Route: input.IPv4Route,
IPv6Route: input.IPv6Route,
NTT: input.NTT,
PreferredAP: input.PreferredAP,
NOCID: NOCID,
BGPRouterID: nil,
TunnelEndPointRouterIPID: nil,
Expand Down
1 change: 1 addition & 0 deletions pkg/api/core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type Connection struct {
IPv6Route string `json:"ipv6_route"`
NTT string `json:"ntt"`
NOCID *uint `json:"noc_id"`
PreferredAP string `json:"preferred_ap"`
TermIP string `json:"term_ip"`
Monitor *bool `json:"monitor"`
Address string `json:"address"` //都道府県 市町村
Expand Down
22 changes: 10 additions & 12 deletions pkg/api/core/template/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ type Input struct {
}

type Result struct {
Services []config.ServiceTemplate `json:"services"`
Connections []config.ConnectionTemplate `json:"connections"`
NTTs []string `json:"ntts"`
NOC []core.NOC `json:"nocs"`
BGPRouter []core.BGPRouter `json:"bgp_router"`
TunnelEndPointRouter []core.TunnelEndPointRouter `json:"tunnel_endpoint_router"`
TunnelEndPointRouterIP []core.TunnelEndPointRouterIP `json:"tunnel_endpoint_router_ip"`
IPv4 []string `json:"ipv4"`
IPv6 []string `json:"ipv6"`
IPv4Route []string `json:"ipv4_route"`
IPv6Route []string `json:"ipv6_route"`
PaymentMembershipTemplate []config.MembershipTemplate `json:"payment_membership_template"`
Services []config.ServiceTemplate `json:"services"`
Connections []config.ConnectionTemplate `json:"connections"`
NTTs []string `json:"ntts"`
IPv4 []string `json:"ipv4"`
IPv6 []string `json:"ipv6"`
IPv4Route []string `json:"ipv4_route"`
IPv6Route []string `json:"ipv6_route"`
PreferredAP []string `json:"preferred_ap"`
PaymentMembershipTemplate []config.MembershipTemplate `json:"payment_membership_template"`
}

type ResultAdmin struct {
Expand All @@ -43,6 +40,7 @@ type ResultAdmin struct {
IPv6 []string `json:"ipv6"`
IPv4Route []string `json:"ipv4_route"`
IPv6Route []string `json:"ipv6_route"`
PreferredAP []string `json:"preferred_ap"`
User []core.User `json:"user"`
Group []core.Group `json:"group"`
PaymentMembershipTemplate []config.MembershipTemplate `json:"payment_membership_template"`
Expand Down
1 change: 1 addition & 0 deletions pkg/api/core/template/v0/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func GetByAdmin(c *gin.Context) {
Group: resultGroup.Group,
PaymentMembershipTemplate: config.Conf.Template.Membership,
MailTemplate: config.Conf.Template.Mail,
PreferredAP: config.Conf.Template.PreferredAP,
MemberType: []core.ConstantMembership{
core.MemberTypeStandard,
core.MemberTypeStudent,
Expand Down
8 changes: 1 addition & 7 deletions pkg/api/core/template/v0/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/homenoc/dsbd-backend/pkg/api/core/common"
template "github.com/homenoc/dsbd-backend/pkg/api/core/template"
"github.com/homenoc/dsbd-backend/pkg/api/core/tool/config"
dbNOC "github.com/homenoc/dsbd-backend/pkg/api/store/noc/v0"
"net/http"
)

Expand All @@ -27,21 +26,16 @@ func Get(c *gin.Context) {
resultService = append(resultService, serviceTemplate)
}
}
resultNOC := dbNOC.GetAll()
if resultNOC.Err != nil {
c.JSON(http.StatusInternalServerError, common.Error{Error: resultNOC.Err.Error()})
return
}

c.JSON(http.StatusOK, template.Result{
Services: resultService,
Connections: config.Conf.Template.Connection,
NTTs: config.Conf.Template.NTT,
NOC: resultNOC.NOC,
IPv4: config.Conf.Template.V4,
IPv6: config.Conf.Template.V6,
IPv4Route: config.Conf.Template.V4Route,
IPv6Route: config.Conf.Template.V6Route,
PreferredAP: config.Conf.Template.PreferredAP,
PaymentMembershipTemplate: config.Conf.Template.Membership,
})
}
10 changes: 10 additions & 0 deletions pkg/api/core/tool/config/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ func CheckIncludeV6Template(data string) error {

return fmt.Errorf("v6 template is not found")
}

func CheckIncludePreferredAPTemplate(data string) error {
for _, preferredAP := range Conf.Template.PreferredAP {
if preferredAP == data {
return nil
}
}

return fmt.Errorf("preferredAP template is not found")
}
19 changes: 10 additions & 9 deletions pkg/api/core/tool/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@ type SlackChannels struct {
}

type Template struct {
Service []ServiceTemplate `json:"service"`
Connection []ConnectionTemplate `json:"connection"`
Membership []MembershipTemplate `json:"membership"`
NTT []string `json:"NTT"`
V4 []string `json:"v4"`
V6 []string `json:"v6"`
V4Route []string `json:"v4_route"`
V6Route []string `json:"v6_route"`
Mail []MailTemplate `json:"mail"`
Service []ServiceTemplate `json:"service"`
Connection []ConnectionTemplate `json:"connection"`
Membership []MembershipTemplate `json:"membership"`
NTT []string `json:"NTT"`
V4 []string `json:"v4"`
V6 []string `json:"v6"`
V4Route []string `json:"v4_route"`
V6Route []string `json:"v6_route"`
PreferredAP []string `json:"preferred_ap"`
Mail []MailTemplate `json:"mail"`
}

type MembershipTemplate struct {
Expand Down

0 comments on commit ae47db7

Please sign in to comment.