controller

package
v0.0.0-...-09d08ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDuplicate

func IsDuplicate(value string) string

Types

type Auth

type Auth struct {
	UserName string `json:"username" db:"username"`
	Password string `json:"passwd" db:"passwd"`
}

func (*Auth) Authenticate

func (auth *Auth) Authenticate() http.HandlerFunc

A fake function that returns the entered data in the req.Body and a token that is also fake

func (*Auth) AuthenticateSSO

func (auth *Auth) AuthenticateSSO() http.HandlerFunc

Just like the previous function, this one is no different, it will return the entered data in the req.Body and a token that is also fake

type User

type User struct {
	ID uint `json:"user_id" gorm:"autoIncrement"`

	// this is full name of people
	// not is used for get in
	FullName string `json:"full_name"`
	// also used for get in user account
	Email    string `json:"email" gorm:"type: varchar(100); unique; not null"`
	Password []byte `json:"password" gorm:"not null"`

	// the timestamp
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

The User struct is responsible for getting the req.Body and inserting it into the database and the same is responsible for "porpulating" the JSON that returns from the database

Please you from the frontend, redirect the user to the route

/api/v{n}/authenticate

Here I just create the user, I don't have any JWT authenticate here

func (User) CreateUser

func (user User) CreateUser() http.HandlerFunc

func (*User) DeleteUser

func (user *User) DeleteUser() http.HandlerFunc

Will delete a user by id

func (User) ShowUser

func (user User) ShowUser() http.HandlerFunc

ShowUser Wil list a single user by id of url

/api/v{1}/user/{id:[0-9]+}

If there is no error it will return a JSON with the referring user to the id of the url

func (*User) UpdateUser

func (user *User) UpdateUser() http.HandlerFunc

This function will update the user data I was using insomnia and when I updated user data 1 it was no longer listed at the beginning of the function

The last user to be modified goes to the end of ListAll()
At least that is how it was for me using *Insomnia*

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL