add new endpoints
This commit is contained in:
14
main.go
14
main.go
@@ -69,9 +69,23 @@ func main() {
|
||||
|
||||
// Persons
|
||||
mainGroup.GET("/persons", personal_information.GetPDList)
|
||||
mainGroup.GET("/persons/docs", personal_information.GetPDDocs)
|
||||
mainGroup.GET("/persons/:id", personal_information.GetPD)
|
||||
mainGroup.POST("/persons", personal_information.CreatePD)
|
||||
|
||||
// Contacts
|
||||
mainGroup.POST("/contacts", personal_information.CreateContacts)
|
||||
mainGroup.PATCH("/contacts/:id", personal_information.UpdateContacts)
|
||||
mainGroup.DELETE("/contacts/:id", personal_information.DeleteContacts)
|
||||
// Address
|
||||
mainGroup.POST("/address", personal_information.CreateAddress)
|
||||
mainGroup.PATCH("/address/:id", personal_information.UpdateAddress)
|
||||
mainGroup.DELETE("/address/:id", personal_information.DeleteAddress)
|
||||
// Documents
|
||||
mainGroup.POST("/documents", personal_information.CreateDocuments)
|
||||
mainGroup.PATCH("/documents/:id", personal_information.UpdateDocuments)
|
||||
mainGroup.DELETE("/documents/:id", personal_information.DeleteDocuments)
|
||||
|
||||
// Checkups
|
||||
mainGroup.GET("/checkups", medical_information.GetCheckupList)
|
||||
mainGroup.GET("/checkups/:id", medical_information.GetCheckup)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
@@ -50,31 +48,24 @@ func GetRequest(url string, header http.Header, args ...string) ([]byte, error,
|
||||
return data, nil, resp
|
||||
}
|
||||
|
||||
func PatchRequest(url string, model any, header http.Header) ([]byte, error) {
|
||||
uJson, err := json.Marshal(model)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func PatchRequest(url string, body io.Reader, header http.Header) ([]byte, error, *http.Response) {
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest("PATCH", url, bytes.NewReader(uJson))
|
||||
req, err := http.NewRequest("POST", url, body)
|
||||
req.Header = header
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, err, resp
|
||||
}
|
||||
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, err, resp
|
||||
}
|
||||
|
||||
return data, nil
|
||||
return data, nil, resp
|
||||
}
|
||||
|
||||
func DeleteRequest(url string, header http.Header) ([]byte, error, *http.Response) {
|
||||
|
||||
@@ -7,6 +7,17 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetPDDocs(c echo.Context) error {
|
||||
data, err, resp := api.GetRequest(
|
||||
config.Env.MSHosts.PersonsHost+"/docs",
|
||||
c.Request().Header, c.Request().URL.RawQuery)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func GetPDList(c echo.Context) error {
|
||||
data, err, resp := api.GetRequest(
|
||||
config.Env.MSHosts.PersonsHost+"/persons/",
|
||||
@@ -45,3 +56,120 @@ func CreatePD(c echo.Context) error {
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func CreateDocuments(c echo.Context) error {
|
||||
data, err, resp := api.PostRequest(
|
||||
config.Env.MSHosts.EventsHost+"/documents/",
|
||||
c.Request().Body,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func CreateContacts(c echo.Context) error {
|
||||
data, err, resp := api.PostRequest(
|
||||
config.Env.MSHosts.EventsHost+"/contacts/",
|
||||
c.Request().Body,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func CreateAddress(c echo.Context) error {
|
||||
data, err, resp := api.PostRequest(
|
||||
config.Env.MSHosts.EventsHost+"/address/",
|
||||
c.Request().Body,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func UpdateDocuments(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
data, err, resp := api.PatchRequest(
|
||||
config.Env.MSHosts.EventsHost+"/documents/"+id,
|
||||
c.Request().Body,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func UpdateContacts(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
data, err, resp := api.PatchRequest(
|
||||
config.Env.MSHosts.EventsHost+"/contacts/"+id,
|
||||
c.Request().Body,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func UpdateAddress(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
data, err, resp := api.PatchRequest(
|
||||
config.Env.MSHosts.EventsHost+"/address/"+id,
|
||||
c.Request().Body,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func DeleteDocuments(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
data, err, resp := api.DeleteRequest(
|
||||
config.Env.MSHosts.EventsHost+"/documents/"+id,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func DeleteContacts(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
data, err, resp := api.DeleteRequest(
|
||||
config.Env.MSHosts.EventsHost+"/contacts/"+id,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
func DeleteAddress(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
|
||||
data, err, resp := api.DeleteRequest(
|
||||
config.Env.MSHosts.EventsHost+"/address/"+id,
|
||||
c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
}
|
||||
|
||||
return c.Blob(resp.StatusCode, resp.Header.Get("Content-Type"), data)
|
||||
}
|
||||
|
||||
@@ -107,13 +107,7 @@ func DeleteUser(c echo.Context) error {
|
||||
func UpdateUser(c echo.Context) (err error) {
|
||||
id := c.Param("id")
|
||||
|
||||
// Bind
|
||||
u := new(model.User)
|
||||
if err = c.Bind(u); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := api.PatchRequest(config.Env.MSHosts.UsersHost+"/"+id, u, c.Request().Header)
|
||||
data, err, _ := api.PatchRequest(config.Env.MSHosts.UsersHost+"/"+id, c.Request().Body, c.Request().Header)
|
||||
|
||||
if err != nil {
|
||||
return c.NoContent(http.StatusBadGateway)
|
||||
|
||||
Reference in New Issue
Block a user