save get done
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"api/src/models"
|
||||||
|
"api/src/storages/psql"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetAllUser(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var users []models.User
|
||||||
|
|
||||||
|
qr := psql.PSQL_GORM_DB.Find(&users)
|
||||||
|
if qr.Error != nil {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
jsData, err := json.Marshal(users)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusNotAcceptable)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write([]byte(jsData))
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package initializers
|
package initializers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"api/src/admin"
|
||||||
"api/src/auth"
|
"api/src/auth"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
@@ -32,9 +33,12 @@ func InitChiRouting() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
r.Post("/signin", auth.Register)
|
r.Post("/signin", auth.Register)
|
||||||
|
r.Get("/allusers", admin.GetAllUser)
|
||||||
|
|
||||||
r.Route("/auth", func(r chi.Router) {
|
r.Route("/auth", func(r chi.Router) {
|
||||||
r.Post("/register", auth.Register)
|
r.Route("/admin", func(r chi.Router) {
|
||||||
|
r.Get("/allUsers", admin.GetAllUser)
|
||||||
|
})
|
||||||
r.Post("/login", auth.Login)
|
r.Post("/login", auth.Login)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package models
|
|||||||
import "github.com/google/uuid"
|
import "github.com/google/uuid"
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id uuid.UUID `json:"id" gorm:"type:uuid;default:uuid_generate_v4();primaryKey;unique;AutoIncrement:false"`
|
Id uuid.UUID `json:"id" gorm:"type:uuid;primaryKey;unique;AutoIncrement:false"`
|
||||||
Name string `json:"name" gorm:"type:string"`
|
Name string `json:"name" gorm:"type:string"`
|
||||||
Email string `json:"email" gorm:"type:string;index"`
|
Email string `json:"email" gorm:"type:string;index"`
|
||||||
Password string `json:"password" gorm:"type:string;index"`
|
Password string `json:"password" gorm:"type:string;index"`
|
||||||
|
|||||||
Reference in New Issue
Block a user