mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Remove redundant structs and methods:
UserSerializer, UsersSerializer, AuthResponse, UserResponse.
This commit is contained in:
parent
42f473cde0
commit
74b27f7525
3 changed files with 0 additions and 61 deletions
|
@ -2,13 +2,6 @@ package common
|
||||||
|
|
||||||
import "github.com/jinzhu/gorm/dialects/postgres"
|
import "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
|
|
||||||
type UserResponse struct {
|
|
||||||
Username string `json:"username"`
|
|
||||||
Role string `json:"role"`
|
|
||||||
Mail string `json:"mail"`
|
|
||||||
ID uint `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ScenarioResponse struct {
|
type ScenarioResponse struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
|
|
|
@ -4,53 +4,6 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// User/s Serializers
|
|
||||||
|
|
||||||
type UsersSerializer struct {
|
|
||||||
Ctx *gin.Context
|
|
||||||
Users []User
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *UsersSerializer) Response(assoc bool) []UserResponse {
|
|
||||||
response := []UserResponse{}
|
|
||||||
for _, user := range self.Users {
|
|
||||||
serializer := UserSerializer{self.Ctx, user}
|
|
||||||
response = append(response, serializer.Response(assoc))
|
|
||||||
}
|
|
||||||
return response
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserSerializer struct {
|
|
||||||
Ctx *gin.Context
|
|
||||||
User
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *UserSerializer) Response(assoc bool) UserResponse {
|
|
||||||
|
|
||||||
response := UserResponse{
|
|
||||||
Username: self.Username,
|
|
||||||
Role: self.Role,
|
|
||||||
Mail: self.Mail,
|
|
||||||
ID: self.ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Associated models MUST NOT called with assoc=true otherwise we
|
|
||||||
// will have an infinite loop due to the circular dependencies
|
|
||||||
if assoc {
|
|
||||||
|
|
||||||
// TODO: maybe all those should be made in one transaction
|
|
||||||
|
|
||||||
//scenarios, _, _ := scenario.FindUserScenarios(&self.User)
|
|
||||||
//scenariosSerializer :=
|
|
||||||
// ScenariosSerializer{self.Ctx, scenarios}
|
|
||||||
|
|
||||||
// Add the associated models to the response
|
|
||||||
//response.Scenarios = scenariosSerializer.Response()
|
|
||||||
}
|
|
||||||
|
|
||||||
return response
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scenario/s Serializers
|
// Scenario/s Serializers
|
||||||
|
|
||||||
type ScenariosSerializer struct {
|
type ScenariosSerializer struct {
|
||||||
|
|
|
@ -21,13 +21,6 @@ type tokenClaims struct {
|
||||||
jwt.StandardClaims
|
jwt.StandardClaims
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthResponse struct {
|
|
||||||
Success bool `json:"success"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
Token string `json:"token"`
|
|
||||||
User common.UserResponse `json:"user"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func VisitorAuthenticate(r *gin.RouterGroup) {
|
func VisitorAuthenticate(r *gin.RouterGroup) {
|
||||||
r.POST("", authenticate)
|
r.POST("", authenticate)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue