Kirill255 / react-online-store-with-graphql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This project was bootstrapped with Create React App.

react-online-store-with-graphql

https://coursehunters.net/course/sozdayte-internet-magazin-s-react-i-graphql-za-90-minut

https://github.com/reedbarger/ecommerce-react-graphql-stripe

https://github.com/simotae14/EcommerceReactGraphqlStripe

https://github.com/mariobermudezjr/ecommerce-react-graphql-stripe

https://blog.strapi.io/building-a-static-website-using-gatsby-and-strapi/

https://habr.com/ru/company/ruvds/blog/348068/

https://blog.risingstack.com/stripe-payments-integration-tutorial-javascript

Related

https://strapi.io/ — The open source Headless CMS Front-End Developers love.

https://stripe.com/ — The new standard in online payments

Strapi

Install

  1. npm install strapi@alpha -g or npm install -g strapi@beta or try npm install -g strapi@beta --unsafe-perm strapi/strapi#3386, также возникли проблемы с установкой на node v12, в данный момент strapi работает только на node v10 strapi/strapi#3342, пришлось ставить node v10 и юзать strapi@alpha

  2. Then create project strapi new server and select custom -> It's a database connection setup:

// (for example: mongo connection string "mongodb://<dbuser>:<password>@ds062807.mlab.com:62807/react-online-store-with-graphql")

Choose your installation type Custom (manual settings):
- Choose your main database: MongoDB
- Database name: react-online-store-with-graphql
- Host: ds062807.mlab.com
- +srv connection: false
- Port (It will be ignored if you enable +srv): 62807
- Username: dbuser
- Password: password
- Authentication database (Maybe "admin" or blank): react-online-store-with-graphql
- Enable SSL connection: false
// (for example: mongo connection string "mongodb+srv://<dbuser>:<password>@testcluster-yemab.mongodb.net/test?retryWrites=true&w=majority")

Choose your installation type Custom (manual settings):
- Choose your main database: MongoDB
- Database name: (Default your_name_proj) press enter
- Host: testcluster-yemab.mongodb.net
- +srv connection: true
- Port (It will be ignored if you enable +srv): (Default 27017) press enter
- Username: dbuser
- Password: password
- Authentication database (Maybe "admin" or blank): press enter
- Enable SSL connection: true
  1. cd server and strapi start

  2. Go to Admin panel: http://localhost:1337/admin

  3. Create a root(admin) user

  4. Welcome on board! This will also create several collections in your database.

GraphQL

  1. Install GraphQL plugin on admin dashboard from "Marketplace" or strapi install graphql

gql

  1. Go to playground http://localhost:1337/graphql

  2. Create on dashboard new Content Types: Brand with 3 fields: name, description, image

type

  1. Add several new Brands

brand

brand

  1. Add on dashboard Roles & Permissions for Brand type in Public and Authenticated: find(brands) and findone(brand(id)) with ratelimit

roles

  1. Make requests
query {
  brands {
    _id
    name
    description
    image {
      _id
      name
      mime
      url
    }
  }
}
query {
  brand(id: "5d014f2d4eb948169c086fda") {
    _id
    name
    description
    image {
      _id
      name
      mime
      url
    }
  }
}
  1. Create on dashboard new Content Types: Brew with 5 fields: name, description, image, price and relation with Brand

brews

  1. Add several new Brews

brew

  1. Add on dashboard Roles & Permissions for Brew type in Public and Authenticated: find(brews) and findone(brew(id)) with ratelimit

permis

  1. Make requests
query {
  brews {
    _id
    createdAt
    updatedAt
    name
    description
    image {
      url
    }
    price
    brand {
      _id
      name
    }
  }
}
query {
  brew(id: "5d02566f82ac160bb8db835a") {
    _id
    createdAt
    name
    description
    image {
      url
    }
    price
  }
}
  1. Create on dashboard new Content Types: Order with 4 fields: address, postalCode, city, brews

ordertype

  1. Add on dashboard Roles & Permissions for Order type in Authenticated: create

permorder

Stripe

https://stripe.com/docs/development

https://stripe.com/docs/recipes/elements-react

  1. Modify create controller in server/api/order/controllers/Order.js
You may test your Stripe.js integration over HTTP. However, live Stripe.js integrations must use HTTPS.

Send emails

https://app.sendgrid.com/guide/integrate/langs/nodejs

  1. On server-side install provider npm install strapi-provider-email-sendgrid@alpha --save

  2. After installing provider, on dashboard in Email plugin settings, we can select sendgrid option, set Sendgrid API key and your emails

email

  1. Add on dashboard Roles & Permissions for Email plugin in Authenticated: send

emailperm

  1. Modify send controller in server/plugins/email/controllers/Email.js

Search with GraphQL

Ищем бренды где в имени есть подстрока "river":

query {
  brands(where: {
    name_contains: "river"
  }) {
    _id
    name
    description
  }
}

Ищем бренды где в описании есть подстрока "s":

query {
  brands(where: {
    description_contains: "s"
  }) {
    _id
    name
    description
  }
}

Поиск сразу по несольким полям (в данный момент strapi всё ещё не поддерживает операторы OR, AND, NOT) поэтому этот запрос не работает, но код должен быть примерно следующим:

query {
  brands(where: {
    OR: [
      { name_contains: "s" },
      { description_contains: "s" }
    ]
  }) {
    _id
    name
    description
  }
}

А также нужно изменить права доступа у Brand в Public и Authenticated: для find и findone с ratelimit на None, т.к. запросов теперь будет гораздо больше

brendperms

About


Languages

Language:JavaScript 87.1%Language:CSS 12.5%Language:HTML 0.4%