Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated gifteee/request #85

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/src/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func (pg *PgController) Serve() *gin.Engine {
r.GET("/requests/incomplete", func(c *gin.Context) {
gifts, err := pg.IncompleteRequests()
if err != nil {
c.JSON(http.StatusInternalServerError, "Oops")
fmt.Println(err)
c.JSON(http.StatusInternalServerError, err)
}
c.JSON(http.StatusOK, gifts)
})
Expand Down
89 changes: 37 additions & 52 deletions api/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,59 +38,44 @@ func main() {
os.Exit(1)
}
// Auto migrate tables
err = db.AutoMigrate(model.User{}, model.Customer{}, model.GiftRequest{}, model.GiftCollection{}, model.GiftResponse{}, model.Admin{})
err = db.AutoMigrate(model.User{}, model.Customer{}, model.GiftRequest{}, model.GiftCollection{}, model.GiftResponse{}, model.Admin{}, model.Giftee{})

// Create GiftRequest
giftRequestTimmy := model.GiftRequest{
RecipientName: "Timmy White",
RecipientAge: 15,
Occasion: pq.StringArray{"Birthday"},
RecipientInterests: pq.StringArray{"Toys", "Halloween"},
BudgetMax: 60,
BudgetMin: 20,
DateNeeded: time.Date(2023, time.November, 10, 0, 0, 0, 0, time.UTC),
}
giftRequestJoanne := model.GiftRequest{
RecipientName: "Joanne Burgenson",
RecipientAge: 27,
Occasion: pq.StringArray{"Housewarming Gift"},
RecipientInterests: pq.StringArray{"Decor", "Fall"},
BudgetMax: 120,
BudgetMin: 40,
DateNeeded: time.Date(2023, time.November, 16, 0, 0, 0, 0, time.UTC),
}
giftRequestDaniel := model.GiftRequest{
RecipientName: "Daniel Danielson",
RecipientAge: 60,
Occasion: pq.StringArray{"Anniversary"},
RecipientInterests: pq.StringArray{"Animals", "Golf"},
BudgetMax: 180,
BudgetMin: 60,
DateNeeded: time.Date(2023, time.December, 16, 0, 0, 0, 0, time.UTC),
}
giftRequestChrista := model.GiftRequest{
RecipientName: "Christa Blue",
RecipientAge: 22,
Occasion: pq.StringArray{"Graduating College"},
RecipientInterests: pq.StringArray{"Robots", "Jewelery", "Surfing"},
BudgetMax: 500,
BudgetMin: 200,
DateNeeded: time.Date(2023, time.November, 1, 0, 0, 0, 0, time.UTC),
gifteeTimmy := model.Giftee{
Model: gorm.Model{},
GifteeName: "Timmy",
CustomerID: 1,
Gender: "Male",
CustomerRelationship: "Son",
Age: 17,
Colors: pq.StringArray{"Red", "Blue"},
Interests: pq.StringArray{"Toys", "Monkey"},
}
a := model.User{Email: "[email protected]", FirstName: "Tommy", LastName: "White", Password: "xxxxx"}
b := model.User{Email: "[email protected]", FirstName: "David", LastName: "Davidson", Password: "xxxxx"}
e := model.User{Email: "[email protected]", FirstName: "Jordan", LastName: "Daniels", Password: "xxxxx"}
d := model.User{Email: "[email protected]", FirstName: "Lisa", LastName: "Blue", Password: "xxxxx"}

customer1 := model.Customer{GiftRequests: []*model.GiftRequest{&giftRequestTimmy}, User: a}
customer2 := model.Customer{GiftRequests: []*model.GiftRequest{&giftRequestJoanne}, User: b}
customer3 := model.Customer{GiftRequests: []*model.GiftRequest{&giftRequestDaniel}, User: e}
customer4 := model.Customer{GiftRequests: []*model.GiftRequest{&giftRequestChrista}, User: d}
a := model.User{Email: "[email protected]", FirstName: "Tommy", LastName: "White", Password: "xxxxx"}
customer1 := model.Customer{User: a}

err = db.Create(&customer1).Error
err = db.Create(&customer2).Error
err = db.Create(&customer3).Error
err = db.Create(&customer4).Error
if err != nil {
panic(err)
}
err = db.Create(&gifteeTimmy).Error
if err != nil {
panic(err)
}
giftRequestTimmy := model.GiftRequest{
Occasion: pq.StringArray{"Birthday"},
GifteeID: gifteeTimmy.ID,
CustomerID: customer1.ID,
BudgetMax: 60,
BudgetMin: 20,
DateNeeded: time.Date(2023, time.December, 20, 0, 0, 0, 0, time.UTC),
}

err = db.Create(&giftRequestTimmy).Error
if err != nil {
panic(err)
}

toyGift1 := model.Gift{
Name: "Robot Extreme",
Expand All @@ -99,8 +84,8 @@ func main() {
Description: "Robot Toy With Laser Eyes",
Demographic: "For kids",
GiftCollections: nil,
Occasion: "Birthday",
Category: pq.StringArray{"Fun"},
Occasion: "Birthday",
Category: pq.StringArray{"Fun"},
}
toyGift2 := model.Gift{
Name: "Angry Teddy Bear",
Expand All @@ -109,8 +94,8 @@ func main() {
Description: "A Teddy Bear Toy but Evil!",
Demographic: "For kids",
GiftCollections: nil,
Occasion: "New baby",
Category: pq.StringArray{"Cooking", "Warm and cozy"},
Occasion: "New baby",
Category: pq.StringArray{"Cooking", "Warm and cozy"},
}
fallGift1 := model.Gift{
Name: "Pumpkin Sweater",
Expand All @@ -135,7 +120,7 @@ func main() {
Link: "link.Burger.com",
Description: "Great for grill masters looking to up their game",
Demographic: "For dad",
Category: pq.StringArray{"Home", "Cooking"},
Category: pq.StringArray{"Home", "Cooking"},
GiftCollections: nil,
}
randomGift2 := model.Gift{
Expand Down
15 changes: 4 additions & 11 deletions api/src/model/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,9 @@ func UpdateGiftRequestToDb(db *gorm.DB, inputRequest GiftRequest) (GiftRequest,
}

updates := make(map[string]interface{})

if inputRequest.RecipientName != "" {
updates["RecipientName"] = inputRequest.RecipientName
}
if inputRequest.RecipientAge != 0 {
updates["RecipientAge"] = inputRequest.RecipientAge
}
if len(inputRequest.Occasion) > 0 {
updates["Occasion"] = inputRequest.Occasion
}
if len(inputRequest.RecipientInterests) > 0 {
updates["RecipientInterests"] = inputRequest.RecipientInterests
}
if inputRequest.BudgetMax != 0 {
updates["BudgetMax"] = inputRequest.BudgetMax
}
Expand All @@ -46,6 +36,9 @@ func UpdateGiftRequestToDb(db *gorm.DB, inputRequest GiftRequest) (GiftRequest,
if inputRequest.GifteeID != 0 {
updates["GifteeID"] = inputRequest.GifteeID
}
if inputRequest.Comment != "" {
updates["Commnet"] = inputRequest.Comment
}

if err := db.Model(&updatedGiftRequest).Updates(updates).Error; err != nil {
return GiftRequest{}, err
Expand Down Expand Up @@ -275,7 +268,7 @@ func GetAllCustomerCollectionsFromDB(db *gorm.DB, id int64) ([]GiftCollection, e

func GetAllCustomerRequestsFromDB(db *gorm.DB, id int64) ([]GiftRequest, error) {
var requests []GiftRequest
if err := db.Preload("GiftResponse").Preload("GiftResponse.GiftCollection").Preload("GiftResponse.GiftCollection.Gifts").Where("customer_id = ?", id).Find(&requests).Error; err != nil {
if err := db.Preload("GiftResponse").Preload("Giftee").Preload("GiftResponse.GiftCollection").Preload("GiftResponse.GiftCollection.Gifts").Where("customer_id = ?", id).Find(&requests).Error; err != nil {
return nil, err
}
return requests, nil
Expand Down
46 changes: 22 additions & 24 deletions api/src/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ type Gift struct {

type GiftRequest struct {
gorm.Model
CustomerID uint
GiftResponseID *uint
GifteeID uint
RecipientName string
RecipientAge uint
Occasion pq.StringArray `gorm:"type:text[]"`
RecipientInterests pq.StringArray `gorm:"type:text[]"`
BudgetMax uint
BudgetMin uint
GiftResponse *GiftResponse
DateNeeded time.Time
CustomerID uint
GiftResponseID *uint
GifteeID uint
Giftee Giftee
Occasion pq.StringArray `gorm:"type:text[]"`
BudgetMax uint
BudgetMin uint
Comment string
GiftResponse *GiftResponse
DateNeeded time.Time
}

type GiftCollection struct {
Expand Down Expand Up @@ -59,24 +58,23 @@ type User struct {

type Customer struct {
gorm.Model
UserID uint
User User
UserID uint
User User
AvailableRequests uint
GiftCollections []*GiftCollection
GiftRequests []*GiftRequest
Giftees []*Giftee
GiftCollections []*GiftCollection
GiftRequests []*GiftRequest
Giftees []*Giftee
}

type Giftee struct {
gorm.Model
GifteeName string
CustomerID uint
Gender string
CustomerRelationship string
Age uint
Colors pq.StringArray `gorm:"type:text[]"`
Interests pq.StringArray `gorm:"type:text[]"`
GiftRequests []*GiftRequest
GifteeName string
CustomerID uint
Gender string
CustomerRelationship string
Age uint
Colors pq.StringArray `gorm:"type:text[]"`
Interests pq.StringArray `gorm:"type:text[]"`
}

type Admin struct {
Expand Down
32 changes: 13 additions & 19 deletions api/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,21 @@ func TestGetCustomerGiftRequests(t *testing.T) {
var retrievedCustomer model.Customer
err = tx.First(&retrievedCustomer).Error
request := model.GiftRequest{
CustomerID: retrievedCustomer.ID,
GiftResponse: &giftResponse,
RecipientName: "Friend",
RecipientAge: 25,
Occasion: pq.StringArray{"Birthday", "Anniversary"},
RecipientInterests: pq.StringArray{"Reading", "Gaming"},
BudgetMax: 50,
BudgetMin: 15,
GifteeID: testGiftee.ID,
DateNeeded: time.Now(),
CustomerID: retrievedCustomer.ID,
GiftResponse: &giftResponse,
Occasion: pq.StringArray{"Birthday", "Anniversary"},
BudgetMax: 50,
BudgetMin: 15,
GifteeID: testGiftee.ID,
DateNeeded: time.Now(),
}
request2 := model.GiftRequest{
CustomerID: retrievedCustomer.ID,
RecipientName: "Timmy",
RecipientAge: 25,
Occasion: pq.StringArray{"Birthday", "Anniversary"},
RecipientInterests: pq.StringArray{"Reading", "Gaming"},
BudgetMax: 50,
GifteeID: testGiftee.ID,
BudgetMin: 15,
DateNeeded: time.Now(),
CustomerID: retrievedCustomer.ID,
Occasion: pq.StringArray{"Birthday", "Anniversary"},
BudgetMax: 50,
GifteeID: testGiftee.ID,
BudgetMin: 15,
DateNeeded: time.Now(),
}
// Create the GiftRequest and call the endpoint
err = tx.Create(&request).Error
Expand Down
27 changes: 17 additions & 10 deletions client/src/components/Admin/RequestCard.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
import React, { useState } from "react";
import ResponseCard from "./ResponseCard.tsx";
import ResponseForm from "./ResponseForm.tsx";
import { GiftRequest } from "../../types.tsx";
import {Giftee, GiftRequest} from "../../types.tsx";

const RequestCard: React.FC<GiftRequest> = ({
ID,
RecipientName,
RecipientAge,
RecipientInterests,
BudgetMin,
BudgetMax,
GiftResponse,
DateNeeded,
}: GiftRequest) => {
Comment
}: GiftRequest, { GifteeName,
Gender,
CustomerRelationship,
Age,
Colors,
Interests,} : Giftee) => {
const [showForm, setShowForm] = useState(false);
return (
<div className="flex flex-col w-full">
<h2 className="font-bold text-lg">
{RecipientName} ({new Date(DateNeeded).toLocaleDateString()})
{GifteeName} ({new Date(DateNeeded).toLocaleDateString()})
</h2>
<div key={RecipientName} className="px-4 py-2 bg-slate-100">
<p>Recipient: {RecipientName}</p>
<div key={GifteeName} className="px-4 py-2 bg-slate-100">
<p>Recipient: {GifteeName}</p>
{!GiftResponse && (
<div>
<p>Recipient age: {RecipientAge}</p>
<p>Recipient interests: {RecipientInterests.join(", ")}</p>
<p>Recipient age: {Age}</p>
<p>Recipient interests: {Interests.join(", ")}</p>
<p>Recipient colors: {Colors.join(", ")}</p>
<p>Recipient relationship: {CustomerRelationship}</p>
<p>Recipient gender: {Gender}</p>
<p>
Budget: ${BudgetMin} - ${BudgetMax}
</p>
<p> Comment: {Comment}</p>
<p>Needed by: ({new Date(DateNeeded).toLocaleDateString()})</p>
</div>
)}
Expand Down
16 changes: 13 additions & 3 deletions client/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export interface Gift {
export interface GiftRequest {
ID: number;
CustomerID: number;
GifteeID: number;
Giftee: Giftee;
GiftResponseId: number | null;
RecipientName: string;
RecipientAge: number;
Occasion: string[];
RecipientInterests: string[];
BudgetMax: number;
BudgetMin: number;
GiftResponse: GiftResponse | null;
DateNeeded: string;
Comment: string;
}

export interface GiftCollection {
Expand Down Expand Up @@ -52,6 +52,16 @@ export interface Customer {
UserId: number;
}

export interface Giftee {
GifteeName: string;
CustomerID: number;
Gender: string;
CustomerRelationship: string;
Age: number;
Colors: string[];
Interests: string[];
GiftRequests: GiftRequest[];
}
export interface Admin {
ID: number;
UserId: number;
Expand Down
12 changes: 0 additions & 12 deletions node_modules/.bin/loose-envify

This file was deleted.

17 changes: 0 additions & 17 deletions node_modules/.bin/loose-envify.cmd

This file was deleted.

Loading
Loading