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

Showcase #89

Merged
merged 8 commits into from
Dec 31, 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
29 changes: 21 additions & 8 deletions api/src/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ type PgController struct {
}

func (pg *PgController) CreateStripeCheckoutSession(c *gin.Context) {
// TODO add webhook for security
print(stripe.Key)
domain := "http://localhost:4242"
domain := "http://localhost:5173"
params := &stripe.CheckoutSessionParams{
ClientReferenceID: stripe.String("1"),
LineItems: []*stripe.CheckoutSessionLineItemParams{
{
// Provide the exact Price ID (for example, pr_1234) of the product you want to sell
Expand All @@ -34,12 +36,14 @@ func (pg *PgController) CreateStripeCheckoutSession(c *gin.Context) {
},
},
Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
SuccessURL: stripe.String(domain + "/success"),
CancelURL: stripe.String(domain + "/cancel"),
SuccessURL: stripe.String(domain + "/profile/?checkout=success"),
CancelURL: stripe.String(domain + "/profile"),
}
_, err := pg.UpdateCustomerAvailableRequests(int64(1), int64(1))
if err != nil {
panic("Checkout failed")
}

s, err := session.New(params)

if err != nil {
log.Printf("session.New: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
Expand All @@ -60,6 +64,16 @@ func (pg *PgController) Serve() *gin.Engine {
}
c.JSON(http.StatusOK, gifts)
})
r.GET("/customer/:id", func(c *gin.Context) {
id := c.Param("id")
intId, err := strconv.Atoi(id)
customer, err := pg.GetCustomer(int64(intId))
if err != nil {
fmt.Println(err)
c.JSON(http.StatusInternalServerError, err)
}
c.JSON(http.StatusOK, customer)
})
r.POST("/create-checkout-session", pg.CreateStripeCheckoutSession)

// Get complete gift requests
Expand Down Expand Up @@ -531,7 +545,7 @@ func (pg *PgController) Serve() *gin.Engine {
c.JSON(http.StatusNoContent, "Deleted Giftee")
})
// Update AvailableRequests based on Customer ID
r.PUT("customer/:id", func(c *gin.Context) {
r.PUT("/customer/:id/:requests", func(c *gin.Context) {

// Get Customer ID
customerID, err := strconv.Atoi(c.Param("id"))
Expand All @@ -540,8 +554,7 @@ func (pg *PgController) Serve() *gin.Engine {
}

// Get request amount
updatedRequests := c.Query("requests")
requests, err := strconv.Atoi(updatedRequests)
requests, err := strconv.Atoi(c.Param("requests"))
if err != nil {
panic(err)
}
Expand Down
92 changes: 77 additions & 15 deletions api/src/main.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions api/src/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Model interface {
CompleteRequests() ([]GiftRequest, error)
UpdateGiftRequest(GiftRequest) (GiftRequest, error)
GetGift(int64) (Gift, error)
GetCustomer(int64) (Customer, error)
GetAllGifts() ([]Gift, error)
AddGift(Gift) (Gift, error)
UpdateGift(int64, Gift) (Gift, error)
Expand All @@ -42,6 +43,14 @@ type Model interface {
UpdateCustomerAvailableRequests(int64, int64) (Customer, error)
}

func (m *PgModel) GetCustomer(id int64) (Customer, error) {
customerRetrieved, err := GetCustomerFromDb(m.Conn, id)
if err != nil {
return Customer{}, err
}

return customerRetrieved, nil
}
func (m *PgModel) AddRequest(inputRequest GiftRequest) (GiftRequest, error) {

createdRequest, err := WriteRequestToDb(m.Conn, inputRequest)
Expand Down
11 changes: 11 additions & 0 deletions api/src/model/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ func WriteRequestToDb(db *gorm.DB, inputRequest GiftRequest) (GiftRequest, error
}
return inputRequest, nil
}
func GetCustomerFromDb(db *gorm.DB, id int64) (Customer, error) {
var customerRetrieved Customer
if err := db.Where("id = ?", id).Preload("Giftees").Preload("GiftRequests").Preload("GiftCollections").First(&customerRetrieved).Error; err != nil {
return Customer{}, err
}
return customerRetrieved, nil
}

func UpdateGiftRequestToDb(db *gorm.DB, inputRequest GiftRequest) (GiftRequest, error) {
var updatedGiftRequest GiftRequest
if err := db.Where("id = ?", inputRequest.ID).First(&updatedGiftRequest).Error; err != nil {
Expand Down Expand Up @@ -112,6 +120,9 @@ func UpdateGiftToDb(db *gorm.DB, id int64, inputGift Gift) (Gift, error) {
if inputGift.Name != "" {
updates["Name"] = inputGift.Name
}
if inputGift.ImageLink != "" {
updates["ImageLink"] = inputGift.ImageLink
}
if inputGift.Price != 0 {
updates["Price"] = inputGift.Price
}
Expand Down
1 change: 1 addition & 0 deletions api/src/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Gift struct {
Category pq.StringArray `gorm:"type:text[]"`
Occasion string
GiftCollections []*GiftCollection `gorm:"many2many:gift_collection_gifts;"`
ImageLink string
}

type GiftRequest struct {
Expand Down
13 changes: 4 additions & 9 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import HomePage from "./pages/HomePage";
import RequestsPage from "./pages/RequestsPage";
import RequestsPage from "./pages/RequestsPage.tsx";
import CheckoutPage from "./pages/CheckoutPage.tsx";
import CollectionPage from "./pages/CollectionsPage";
import { AdminProvider } from "./Context/AdminContext.tsx";
import GiftManagementPage from "./pages/GiftManagementPage.tsx";
import LoginPage from "./pages/LoginPage.tsx";
import SignUpPage from "./pages/SignUpPage.tsx";
import RequestsPurchasingPage from "./pages/RequestPurchasingPage.tsx";
import RequestPurchaseSuccess from "./pages/RequestPurchaseSuccess.tsx";
import ReturnHomePage from "./pages/ReturnHomePage.tsx";
import GiftRequestsPage from "./pages/GiftRequestsPage.tsx";
import ProfilePage from "./pages/ProfilePage.tsx";

function App() {
return (
Expand Down Expand Up @@ -49,15 +48,11 @@ function App() {
</AdminProvider>
}
/>
<Route path="/home/" element={<ReturnHomePage />} />
<Route path="/about/" element={<ReturnHomePage />} />
<Route path="/signup/" element={<SignUpPage />} />
<Route
path="/purchase-requests/"
element={<RequestsPurchasingPage />}
/>
<Route path="/login/" element={<LoginPage />} />
<Route path="/success/" element={<RequestPurchaseSuccess />} />
<Route path="/profile/requests/" element={<GiftRequestsPage />} />
<Route path="/profile/" element={<ProfilePage />} />
</Routes>
</Router>
);
Expand Down
52 changes: 19 additions & 33 deletions client/src/components/AccountSideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useState } from 'react';
import { useState} from 'react';
type AccountSideBarProps = {
activeComponent: string;
setActiveComponent: React.Dispatch<React.SetStateAction<string>>;
};

const AccountSideBar = () => {
const AccountSideBar: React.FC<AccountSideBarProps> = ({ activeComponent, setActiveComponent }) => {
const [isGiftingOpen, setIsGiftingOpen] = useState(false);
const [isBudgetOpen, setIsBudgetOpen] = useState(false);
const [isCalendarOpen, setIsCalendarOpen] = useState(false);
const [isPurchaseGiftsClicked, setIsPurchaseGiftsClicked] = useState(false);
const [isGifteesClicked, setIsGifteesClicked] = useState(false);
const [isGiftRequestHistoryClicked, setIsGiftRequestHistoryClicked] = useState(false);

const toggleGifting = () => {
setIsGiftingOpen(!isGiftingOpen);
};
Expand All @@ -20,22 +20,8 @@ const AccountSideBar = () => {
setIsCalendarOpen(!isCalendarOpen);
};

const purchaseGifts = () => {
setIsPurchaseGiftsClicked(!isPurchaseGiftsClicked);
};


const giftRequestHistory = () => {
setIsGiftRequestHistoryClicked(!isGiftRequestHistoryClicked);;
};

const viewGiftees = () => {
setIsGifteesClicked(!isGifteesClicked);;
};


return (
<div className="flex flex-col bg-FBF2EB" style={{ width: '366px'}}>
<div className="flex flex-col bg-FBF2EB" style={{ width: '366px', height: "100vh"}}>
<div style={{ fontFamily: 'The Seasons', fontSize: '36px', marginLeft: '40px', marginTop: "50px" }}>
Account
<div className="flex flex-row items-center" style={{ fontFamily: 'The Seasons', fontSize: '24px', marginTop: '50px' }}>
Expand Down Expand Up @@ -74,36 +60,36 @@ const AccountSideBar = () => {
<div style={{marginTop: "10px"}}>
<button
style={{
background: isPurchaseGiftsClicked ? '#DFB2AA' : 'none',
background: activeComponent == "purchaseGifts" ? '#DFB2AA' : 'none',
width: "265px",
borderLeft: isPurchaseGiftsClicked ? '6px solid #A65A5A' : 'none',
fontWeight: isPurchaseGiftsClicked ? 'bold' : 'normal',
borderLeft: activeComponent == "purchaseGifts" ? '6px solid #A65A5A' : 'none',
fontWeight: activeComponent == "purchaseGifts" ? 'bold' : 'normal',
}}
onClick={purchaseGifts} >
onClick={() => setActiveComponent("purchaseGifts")} >
Purchase Gift Requests
</button>
</div>
<div style={{marginTop: "10px"}}><button
style={{
background: isGiftRequestHistoryClicked ? '#DFB2AA' : 'none',
background: activeComponent == "requestHistory" ? '#DFB2AA' : 'none',
width: "265px",
borderLeft: isGiftRequestHistoryClicked ? '6px solid #A65A5A' : 'none',
fontWeight: isGiftRequestHistoryClicked ? 'bold' : 'normal',
borderLeft: activeComponent == "requestHistory" ? '6px solid #A65A5A' : 'none',
fontWeight: activeComponent == "requestHistory" ? 'bold' : 'normal',
paddingRight: '20px',
}}
onClick={giftRequestHistory} >
onClick={() => setActiveComponent("requestHistory")} >
Gift Request History
</button></div>
<div style={{marginTop: "10px"}}>
<button
style={{
background: isGifteesClicked ? '#DFB2AA' : 'none',
background: activeComponent == "giftees" ? '#DFB2AA' : 'none',
width: "265px",
borderLeft: isGifteesClicked ? '6px solid #A65A5A' : 'none',
fontWeight: isGifteesClicked ? 'bold' : 'normal',
borderLeft: activeComponent == "giftees" ? '6px solid #A65A5A' : 'none',
fontWeight: activeComponent == "giftees" ? 'bold' : 'normal',
paddingRight: '105px',
}}
onClick={viewGiftees} >
onClick={() => setActiveComponent("giftees")} >
Giftees
</button>
</div>
Expand Down
15 changes: 15 additions & 0 deletions client/src/components/Admin/GiftForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const GiftForm: React.FC<Props> = ({ initialGift = defaultGift, mode, onGiftChan
<option value="New baby">New baby</option>
<option value="Thinking of you">Thinking of you</option>
<option value="Thank you">Thank you</option>
<option value="Christmas">Christmas</option>
</select>
</div>
<div className="mb-4">
Expand Down Expand Up @@ -156,6 +157,7 @@ const GiftForm: React.FC<Props> = ({ initialGift = defaultGift, mode, onGiftChan
<option value="Kitchen & bar">Kitchen & bar</option>
<option value="Warm and cozy">Warm and cozy</option>
<option value="Outdoors">Outdoors</option>

</select>
</div>
<div className="mb-4">
Expand Down Expand Up @@ -184,6 +186,19 @@ const GiftForm: React.FC<Props> = ({ initialGift = defaultGift, mode, onGiftChan
className="mt-1 p-2 w-full border-2 border-gray-300 rounded-md"
/>
</div>
<div className="mb-4">
<label htmlFor="imageLink" className="block text-sm font-medium text-gray-700">
Image link:
</label>
<input
type="text"
id="imageLink"
name="ImageLink"
value={gift.ImageLink}
onChange={handleInputChange}
className="mt-1 p-2 w-full border-2 border-gray-300 rounded-md"
/>
</div>
<button type="submit">{mode === 'add' ? 'Add' : 'Save'}</button>
</form>
);
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/Admin/GiftItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const GiftItem = (props: GiftProps) => {
{giftElements}
</div>
<p>Description: {props.gift.Description}</p>
<p>Description: {props.gift.Occasion}</p>
<p>Occasion: {props.gift.Occasion}</p>
<p>Image Link: <a href={props.gift.ImageLink}>link</a></p>
</div>

<div className='w-1/12 flex flex-row space-x-2'>
Expand Down
26 changes: 11 additions & 15 deletions client/src/components/Admin/RequestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@ const RequestCard: React.FC<GiftRequest> = ({
BudgetMax,
GiftResponse,
DateNeeded,
Comment
}: GiftRequest, { GifteeName,
Gender,
CustomerRelationship,
Age,
Colors,
Interests,} : Giftee) => {
Comment,
Giftee
}: GiftRequest) => {
const [showForm, setShowForm] = useState(false);
return (
<div className="flex flex-col w-full">
<h2 className="font-bold text-lg">
{GifteeName} ({new Date(DateNeeded).toLocaleDateString()})
{Giftee?.GifteeName} ({new Date(DateNeeded).toLocaleDateString()})
</h2>
<div key={GifteeName} className="px-4 py-2 bg-slate-100">
<p>Recipient: {GifteeName}</p>
<div key={Giftee?.GifteeName} className="px-4 py-2 bg-slate-100">
<p>Recipient: {Giftee?.GifteeName}</p>
{!GiftResponse && (
<div>
<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>Age: {Giftee?.Age}</p>
<p>Interests: {Giftee?.Interests.join(", ")}</p>
<p>Colors: {Giftee?.Colors.join(", ")}</p>
<p>Relationship: {Giftee?.CustomerRelationship}</p>
<p>Gender: {Giftee?.Gender}</p>
<p>
Budget: ${BudgetMin} - ${BudgetMax}
</p>
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Home/CollectionItemUpdated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function CollectionItem({ name, collectionIndex, selected }: CollectionItemProps
return (
<div className="flex flex-col items-center">
<img src={icon} className="h-40 w-40" />
<div className={`text-2xl font-seasons font-bold mt-3 ${selected ? "text-red" : "text-coffee"}`}>{name}</div>
<div className={`text-2xl font-seasons font-bold mt-3 ${selected ? "text-red" : "text-espresso"}`}>{name}</div>
</div>
);
}
Expand Down
Loading
Loading