initial commit

This commit is contained in:
2024-01-18 00:02:55 -06:00
commit 8b850f83ee
15 changed files with 952 additions and 0 deletions

44
internal/types/api.go Normal file
View File

@@ -0,0 +1,44 @@
package types
import (
"net/http"
"github.com/go-chi/render"
)
type Response struct {
HTTPStatusCode int `json:"status"`
}
func (r *Response) Render(w http.ResponseWriter, req *http.Request) error {
render.Status(req, r.HTTPStatusCode)
return nil
}
type APIVersion struct {
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
}
type IndexResponse struct {
*Response
Version APIVersion `json:"version"`
}
type APIError struct {
*Response
Err error `json:"-"`
Messages []string `json:"messages"`
}
func NewAPIError(status int, messages ...string) *APIError {
return &APIError{
Response: &Response{
HTTPStatusCode: status,
},
Err: nil,
Messages: messages,
}
}

63
internal/types/assets.go Normal file
View File

@@ -0,0 +1,63 @@
package types
import (
"net/http"
"time"
"gorm.io/gorm"
)
/*
Base Model
*/
type Asset struct {
ID uint64 `gorm:"primarykey" json:"id"`
Name string `json:"name"`
Quantity int `json:"quantity"`
Length string `json:"length,omitempty"`
Manufacturer string `json:"manufacturer,omitempty"`
ModelName string `json:"model_name,omitempty"`
Price float64 `json:"price,omitempty"`
Comments string `json:"comments,omitempty"`
ShelfLocationID *uint64 `json:"-"`
ShelfLocation *ShelfLocation `json:"shelf_location,omitempty"`
CategoryID *uint64 `json:"-"`
Category *Category `json:"category,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
/*
Requests
*/
type CreateAssetRequest struct {
Name string `json:"name"`
Quantity int `json:"quantity"`
Length string `json:"length,omitempty"`
Manufacturer string `json:"manufacturer,omitempty"`
ModelName string `json:"model_name,omitempty"`
Price float64 `json:"price,omitempty"`
Comments string `json:"comments,omitempty"`
ShelfLocationID *uint64 `json:"shelf_location_id,omitempty"`
CategoryID *uint64 `json:"category_id,omitempty"`
}
func (c CreateAssetRequest) Bind(r *http.Request) error { return nil }
/*
Responses
*/
type AssetResponse struct {
*Response
Asset *Asset `json:"asset"`
}
type MultipleAssetsResponse struct {
*Response
Assets []*Asset `json:"assets"`
Total int64 `json:"total"`
}

View File

@@ -0,0 +1,28 @@
package types
import (
"time"
"gorm.io/gorm"
)
/*
Base Model
*/
type Building struct {
ID uint64 `gorm:"primarykey" json:"id"`
Name string `json:"name"`
ShelfLocations []ShelfLocation `json:"shelves"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
/*
Requests
*/
/*
Responses
*/

View File

@@ -0,0 +1,28 @@
package types
import (
"time"
"gorm.io/gorm"
)
/*
Base Model
*/
type Category struct {
ID uint64 `gorm:"primarykey" json:"id"`
Name string `json:"name"`
Assets []Asset `json:"assets,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
/*
Requests
*/
/*
Responses
*/

43
internal/types/shelves.go Normal file
View File

@@ -0,0 +1,43 @@
package types
import (
"time"
"gorm.io/gorm"
)
/*
Base Model
*/
type ShelfLocation struct {
ID uint64 `gorm:"primarykey" json:"id"`
Name string `json:"name"`
RoomNumber string `json:"room_number,omitempty"`
Description string `json:"description,omitempty"`
BuildingID uint64 `json:"-"`
Building Building `json:"building"`
Assets []Asset `json:"assets,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
/*
Requests
*/
/*
Responses
*/
type ShelfResponse struct {
*Response
ShelfLocation *ShelfLocation `json:"shelf"`
}
type MultipleShelfResponse struct {
*Response
ShelfLocations []*ShelfLocation `json:"shelves"`
Total int64 `json:"total"`
}