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
|
||||
|
||||
import (
|
||||
"api/src/admin"
|
||||
"api/src/auth"
|
||||
"log/slog"
|
||||
"os"
|
||||
@@ -32,9 +33,12 @@ func InitChiRouting() {
|
||||
})
|
||||
|
||||
r.Post("/signin", auth.Register)
|
||||
r.Get("/allusers", admin.GetAllUser)
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package models
|
||||
import "github.com/google/uuid"
|
||||
|
||||
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"`
|
||||
Email string `json:"email" gorm:"type:string;index"`
|
||||
Password string `json:"password" gorm:"type:string;index"`
|
||||
|
||||
@@ -6,4 +6,4 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP EXTENSION "uuid-ossp";
|
||||
-- +goose StatementEnd
|
||||
-- +goose StatementEnd
|
||||
Reference in New Issue
Block a user