📜  upapet (1)

📅  最后修改于: 2023-12-03 15:20:54.630000             🧑  作者: Mango

Upapet

Upapet is a web application that helps pet owners track their pets' health and schedule appointments with veterinarians. It allows users to create multiple pet profiles, add their pets' medical records, and set reminders for appointments and medication.

Features
  • Create and manage multiple pet profiles.
  • Add medical records to each pet profile.
  • Schedule appointments with veterinarians.
  • Set reminders for appointments and medication.
  • Receive notifications for upcoming appointments and medication.
Technology Stack

Upapet is built using the following technologies:

  • Node.js - server-side environment.
  • Express - web application framework.
  • MongoDB - NoSQL database.
  • React - front-end library.
  • Redux - state management library.
  • Bootstrap - CSS framework.
Code Sample

Here is a code snippet demonstrating how Upapet uses Redux to manage state:

import { createStore } from 'redux';

// Define initial state
const initialState = {
  pets: [],
  appointments: [],
  medications: [],
};

// Define reducer function
function reducer(state = initialState, action) {
  switch (action.type) {
    case 'ADD_PET':
      return {
        ...state,
        pets: [...state.pets, action.payload],
      };
    case 'ADD_APPOINTMENT':
      return {
        ...state,
        appointments: [...state.appointments, action.payload],
      };
    case 'ADD_MEDICATION':
      return {
        ...state,
        medications: [...state.medications, action.payload],
      };
    default:
      return state;
  }
}

// Create store
const store = createStore(reducer);

// Dispatch actions
store.dispatch({ type: 'ADD_PET', payload: { name: 'Fluffy', breed: 'Persian' } });
store.dispatch({ type: 'ADD_APPOINTMENT', payload: { date: '2022-01-01', pet: 'Fluffy' } });
store.dispatch({ type: 'ADD_MEDICATION', payload: { name: 'Vitamin C', pet: 'Fluffy' } });

// Get state
const state = store.getState();

console.log(state);
// Output: {
//   pets: [{ name: 'Fluffy', breed: 'Persian' }],
//   appointments: [{ date: '2022-01-01', pet: 'Fluffy' }],
//   medications: [{ name: 'Vitamin C', pet: 'Fluffy' }]
// }

This code creates a Redux store with an initial state containing empty arrays for pets, appointments, and medications. It then defines a reducer function that updates the state based on dispatched actions. Finally, it dispatches three actions to add a pet, appointment, and medication, and logs the resulting state to the console.