created_at to api
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

This commit is contained in:
2024-04-21 19:04:41 +03:00
parent b2511d9c1e
commit 8fb0c0f056
6 changed files with 71 additions and 4 deletions

View File

@@ -77,3 +77,6 @@ definitions:
- support
text:
type: string
created_at:
type: string
format: date-time

View File

@@ -6,6 +6,7 @@ import (
dmodels "gerald/internal/models"
"gerald/internal/services"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
)
type FeedbackHandler struct {
@@ -39,8 +40,8 @@ func (h *FeedbackHandler) GetFeedbacks(params feedback.GetFeedbacksParams) middl
func feedbacksToAPI(feedbacks []*dmodels.Feedback) []*models.Feedback {
apiFeedbacks := make([]*models.Feedback, 0, len(feedbacks))
for _, feedback := range feedbacks {
apiFeedbacks = append(apiFeedbacks, feedbackToAPI(feedback))
for _, f := range feedbacks {
apiFeedbacks = append(apiFeedbacks, feedbackToAPI(f))
}
return apiFeedbacks
@@ -52,5 +53,6 @@ func feedbackToAPI(feedback *dmodels.Feedback) *models.Feedback {
Text: feedback.Text,
Type: feedback.Type,
UserID: feedback.UserID,
CreatedAt: strfmt.DateTime(feedback.CreatedAt),
}
}

View File

@@ -20,6 +20,10 @@ import (
// swagger:model Feedback
type Feedback struct {
// created at
// Format: date-time
CreatedAt strfmt.DateTime `json:"created_at,omitempty"`
// to have more context about the project
ProjectID string `json:"project_id,omitempty"`
@@ -38,6 +42,10 @@ type Feedback struct {
func (m *Feedback) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCreatedAt(formats); err != nil {
res = append(res, err)
}
if err := m.validateType(formats); err != nil {
res = append(res, err)
}
@@ -48,6 +56,18 @@ func (m *Feedback) Validate(formats strfmt.Registry) error {
return nil
}
func (m *Feedback) validateCreatedAt(formats strfmt.Registry) error {
if swag.IsZero(m.CreatedAt) { // not required
return nil
}
if err := validate.FormatOf("created_at", "body", "date-time", m.CreatedAt.String(), formats); err != nil {
return err
}
return nil
}
var feedbackTypeTypePropEnum []interface{}
func init() {

View File

@@ -106,6 +106,10 @@ func init() {
"Feedback": {
"type": "object",
"properties": {
"created_at": {
"type": "string",
"format": "date-time"
},
"project_id": {
"description": "to have more context about the project",
"type": "string"
@@ -218,6 +222,10 @@ func init() {
"Feedback": {
"type": "object",
"properties": {
"created_at": {
"type": "string",
"format": "date-time"
},
"project_id": {
"description": "to have more context about the project",
"type": "string"

View File

@@ -1,6 +1,9 @@
package models
import "github.com/google/uuid"
import (
"github.com/google/uuid"
"time"
)
type Feedback struct {
UUID string `gorm:"primaryKey"`
@@ -8,9 +11,13 @@ type Feedback struct {
ProjectID string `gorm:"type:varchar(255)"`
SessionUUID string `gorm:"type:varchar(255)"`
SessionName string `gorm:"type:varchar(255)"`
Type string `gorm:"type:varchar(255)"`
Text string `gorm:"type:varchar(300)"`
CreatedAt time.Time `gorm:"type:timestamp"`
UpdatedAt time.Time `gorm:"type:timestamp"`
}
func NewFeedback(userUUID, sessionUUID, ticketType, text, projectID string) *Feedback {

27
internal/utils/names.go Normal file
View File

@@ -0,0 +1,27 @@
package utils
import "hash/fnv"
var names = []string{
"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet",
"Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango",
"Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", "Jellybean", "Cupcake", "Donut", "Eclair", "Froyo",
"Gingerbread", "Honeycomb", "IceCreamSandwich", "JellyBean", "KitKat", "Lollipop", "Marshmallow", "Nougat", "Oreo",
"Pie", "Quince", "Raspberry", "Strawberry", "Tangerine", "UgliFruit", "Vanilla", "Watermelon", "Xigua",
"YellowPassionfruit", "Zucchini", "ApplePie", "BananaBread", "CinnamonRoll", "Doughnut", "Eggnog",
"Fruitcake", "Gingerbread", "HotChocolate", "IceCream", "Jelly", "KettleCorn", "Lemonade", "Muffin", "Nectar",
"OrangeJuice", "Pancake", "Quiche", "Raspberry", "Smoothie", "Taffy", "UpsideDownCake", "VanillaWafer", "Waffle",
"XmasCookies", "Yogurt", "ZebraCake",
}
func hash(s string) uint32 {
h := fnv.New32a()
h.Write([]byte(s))
return h.Sum32()
}
func GenerateName(sessionUUID string) string {
h := hash(sessionUUID)
index := h % uint32(len(names))
return names[index]
}