Skip to content

Commit

Permalink
[add] #34 IssueにてGroup周りの処理を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Feb 10, 2021
1 parent fd0e62b commit 119d8c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
10 changes: 9 additions & 1 deletion pkg/api/core/group/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ type AdminResult struct {
}

type ResultOne struct {
Group Group `json:"group"`
ID uint `json:"id"`
Agree *bool `json:"agree"`
Question string `json:"question"`
Org string `json:"org"`
Status uint `json:"status"`
Bandwidth string `json:"bandwidth"`
Contract string `json:"contract"`
Student *bool `json:"student"`
Open *bool `json:"open"`
}

type ResultAll struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/core/group/network/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
ID = 0
GID = 1
Org = 2
Type = 3
Open = 3
UpdateName = 100
UpdateDate = 102
UpdateRoute = 103
Expand Down
23 changes: 22 additions & 1 deletion pkg/api/core/group/v0/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,28 @@ func Get(c *gin.Context) {
return
}

c.JSON(http.StatusOK, group.ResultOne{Group: resultGroup.Group[0]})
resultNetwork := dbNetwork.Get(network.Open, &network.Network{GroupID: result.Group.ID})
if resultNetwork.Err != nil {
c.JSON(http.StatusInternalServerError, common.Error{Error: result.Err.Error()})
return
}

open := false
if len(resultNetwork.Network) > 0 {
open = true
}

c.JSON(http.StatusOK, group.ResultOne{
ID: resultGroup.Group[0].ID,
Agree: resultGroup.Group[0].Agree,
Question: resultGroup.Group[0].Question,
Org: resultGroup.Group[0].Org,
Status: resultGroup.Group[0].Status,
Bandwidth: resultGroup.Group[0].Bandwidth,
Contract: resultGroup.Group[0].Contract,
Student: resultGroup.Group[0].Student,
Open: &open,
})
}

func GetAll(c *gin.Context) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/api/store/group/network/v0/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v0

import (
"fmt"
network "github.com/homenoc/dsbd-backend/pkg/api/core/group/network"
"github.com/homenoc/dsbd-backend/pkg/api/core/group/network"
"github.com/homenoc/dsbd-backend/pkg/api/store"
"github.com/jinzhu/gorm"
"log"
Expand Down Expand Up @@ -85,6 +85,9 @@ func Get(base int, data *network.Network) network.ResultDatabase {
} else if base == network.GID {
err = db.Preload("IP").Preload("Connection").Preload("JPNICAdmin").Preload("JPNICTech").
Where("group_id = ?", data.GroupID).Find(&networkStruct).Error
} else if base == network.Open {
err = db.Preload("IP", "open = 1").Preload("Connection", "open = 1").Preload("JPNICAdmin").Preload("JPNICTech").
Where("group_id = ? AND open = ?", data.GroupID, true).Find(&networkStruct).Error
} else {
log.Println("base select error")
return network.ResultDatabase{Err: fmt.Errorf("(%s)error: base select\n", time.Now())}
Expand Down

0 comments on commit 119d8c6

Please sign in to comment.