-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ryo Arima
committed
Sep 17, 2024
1 parent
eb18f94
commit 2769514
Showing
1 changed file
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,73 @@ | ||
package controller | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/ryo-arima/mark1/pkg/entity/model" | ||
"github.com/ryo-arima/mark1/pkg/entity/request" | ||
"github.com/ryo-arima/mark1/pkg/entity/response" | ||
"github.com/ryo-arima/mark1/pkg/server/repository" | ||
) | ||
|
||
type GroupControllerForInternal interface { | ||
GetGroups(c *gin.Context) | ||
CreateGroup(c *gin.Context) | ||
UpdateGroup(c *gin.Context) | ||
DeleteGroup(c *gin.Context) | ||
} | ||
|
||
type groupControllerForInternal struct { | ||
GroupRepository repository.GroupRepository | ||
} | ||
|
||
func (groupController groupControllerForInternal) GetGroups(c *gin.Context) { | ||
var groupRequest request.GroupRequest | ||
if err := c.Bind(&groupRequest); err != nil { | ||
c.JSON(http.StatusBadRequest, &response.GroupResponse{Code: "SERVER_CONTROLLER_GET__FOR__001", Message: err.Error(), Groups: []response.Group{}}) | ||
return | ||
} | ||
res := groupController.GroupRepository.GetGroups() | ||
c.JSON(http.StatusOK, res) | ||
return | ||
} | ||
|
||
func (groupController groupControllerForInternal) CreateGroup(c *gin.Context) { | ||
var groupRequest request.GroupRequest | ||
if err := c.Bind(&groupRequest); err != nil { | ||
c.JSON(http.StatusBadRequest, &response.GroupResponse{Code: "SERVER_CONTROLLER_CREATE__FOR__001", Message: err.Error(), Groups: []response.Group{}}) | ||
return | ||
} | ||
var groupModel model.Groups | ||
res := groupController.GroupRepository.CreateGroup(groupModel) | ||
c.JSON(http.StatusOK, res) | ||
return | ||
} | ||
|
||
func (groupController groupControllerForInternal) UpdateGroup(c *gin.Context) { | ||
var groupRequest request.GroupRequest | ||
if err := c.Bind(&groupRequest); err != nil { | ||
c.JSON(http.StatusBadRequest, &response.GroupResponse{Code: "SERVER_CONTROLLER_UPDATE__FOR__001", Message: err.Error(), Groups: []response.Group{}}) | ||
return | ||
} | ||
var groupModel model.Groups | ||
res := groupController.GroupRepository.UpdateGroup(groupModel) | ||
c.JSON(http.StatusOK, res) | ||
return | ||
} | ||
|
||
func (groupController groupControllerForInternal) DeleteGroup(c *gin.Context) { | ||
var groupRequest request.GroupRequest | ||
if err := c.Bind(&groupRequest); err != nil { | ||
c.JSON(http.StatusBadRequest, &response.GroupResponse{Code: "SERVER_CONTROLLER_DELETE__FOR__001", Message: err.Error(), Groups: []response.Group{}}) | ||
return | ||
} | ||
var uuid string | ||
res := groupController.GroupRepository.DeleteGroup(uuid) | ||
c.JSON(http.StatusOK, res) | ||
return | ||
} | ||
|
||
func NewGroupControllerForInternal(groupRepository repository.GroupRepository) GroupControllerForInternal { | ||
return &groupControllerForInternal{GroupRepository: groupRepository} | ||
} |