Skip to content

Commit

Permalink
Merge pull request #9 from OASIS-YOP/feat/api
Browse files Browse the repository at this point in the history
Feat/api
  • Loading branch information
urimJ authored Dec 11, 2023
2 parents f9ce06a + 1551a42 commit c1e01d8
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 174 deletions.
34 changes: 24 additions & 10 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- run: echo "내용...${{ github.repository }}"
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-node@v4
with:
node-version: 18

- name: .env setup
- run: |
run: |
echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
echo "DB_USER=${{ secrets.DB_USER }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
Expand All @@ -22,7 +29,8 @@ jobs:
echo "S3_PRIVATEKEY=${{ secrets.S3_PRIVATEKEY }}" >> .env
echo "S3_REGION=${{ secrets.S3_REGION }}" >> .env
echo "BUCKET_NAME=${{ secrets.BUCKET_NAME }}" >> .env
- name: Set up environment variables
echo "JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}" >> .env
env:
DB_HOST: ${{ secrets.DB_HOST }}
DB_USER: ${{ secrets.DB_USER }}
Expand All @@ -32,14 +40,20 @@ jobs:
S3_PRIVATEKEY: ${{ secrets.S3_PRIVATEKEY }}
S3_REGION: ${{ secrets.S3_REGION }}
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
- run: echo "내용...${{ github.repository }}"
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-node@v4
with:
node-version: 18
- run: npm install
- run: node main.js
JWT_SECRET_KEY: ${{ secrets.JWT_SECRET_KEY }}
# run: |
# echo "${{ secrets.DB_HOST }}"
# echo "${{ secrets.DB_USER }}"
# echo "${{ secrets.DB_PASSWORD }}"
# echo "${{ secrets.DB_DATABASE }}"
# echo "${{ secrets.S3_KEYID }}"
# echo "${{ secrets.S3_PRIVATEKEY }}"
# echo "${{ secrets.S3_REGION }}"
# echo "${{ secrets.BUCKET_NAME }}"
- name: Install dependencies and run script
run: |
npm install
node main.js
# 백엔드
# 업데이트 하는 과정을 명령어로 구성하기
Expand Down
2 changes: 1 addition & 1 deletion auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dotenv.config();

const JWTConfig = {
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET_KEY,
secretOrKey: process.env.JWT_SECRET_KEY
};

const JWTVerify = async (jwtPayload, done) => {
Expand Down
101 changes: 51 additions & 50 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ User.init(
timestamps: false
}
);
await sequelize.sync();
//await sequelize.sync();

//아티스트
class Artist extends Model {}
Expand All @@ -76,7 +76,7 @@ Artist.init(
timestamps: false
}
);
await sequelize.sync();
// await sequelize.sync();

//포토카드
class PhotoCard extends Model {
Expand Down Expand Up @@ -106,7 +106,7 @@ PhotoCard.init(
timestamps: false
}
);
await sequelize.sync();
// await sequelize.sync();

//컬렉션
class Collection extends Model {
Expand All @@ -119,7 +119,7 @@ Collection.init(
},
albumJacket: DataTypes.STRING,
photoCardQuant: DataTypes.INTEGER,
activeDateTime: DataTypes.DATE,
// DatactiveeTime: DataTypes.DATE,
activationCode: DataTypes.STRING
}
,
Expand All @@ -129,7 +129,7 @@ Collection.init(
timestamps: false
}
);
await sequelize.sync();
// await sequelize.sync();

//도안
class Polaroid extends Model {
Expand All @@ -152,7 +152,7 @@ Polaroid.init(
timestamps: false
}
);
await sequelize.sync();
// await sequelize.sync();

// 도안백업
class PolaroidBackup extends Model {
Expand All @@ -177,7 +177,7 @@ PolaroidBackup.init(
timestamps: false
}
);
await sequelize.sync();
// await sequelize.sync();

//포스트
class Post extends Model {
Expand Down Expand Up @@ -206,8 +206,8 @@ Post.init(
modelName: "Post",
timestamps: false
}
);
await sequelize.sync();
);
// await sequelize.sync();

// 릴레이션
// 회원 : 도안 = 일대다
Expand All @@ -221,7 +221,7 @@ User.hasMany(Post, {
Post.belongsTo(User,{
foreignKey: 'userId'
});
await sequelize.sync();
// await sequelize.sync();

// 좋아요 ( 회원: 포스트 = 다대다)
class Like extends Model {
Expand All @@ -241,7 +241,7 @@ Like.init(
timestamps: false
}
);
await sequelize.sync();
// await sequelize.sync();
User.belongsToMany(Post, {
through: 'Like',
foreignKey: 'userId',
Expand All @@ -251,7 +251,7 @@ Post.belongsToMany(User, {
through: 'Like',
foreignKey: 'postId',
});
await sequelize.sync();
// await sequelize.sync();

// 즐겨찾기 (회원: 아티스트 = 다대다)
class Favorite extends Model {
Expand Down Expand Up @@ -281,7 +281,7 @@ Artist.belongsToMany(User, {
through: 'Favorite',
foreignKey: 'artistId',
});
await sequelize.sync();
// await sequelize.sync();


// 컬렉션
Expand Down Expand Up @@ -320,7 +320,7 @@ PhotoCard.belongsTo(Collection,{
foreignKey: 'albumName'
});

await sequelize.sync();
// await sequelize.sync();

// 회원: 컬렉션 = 다대다
class UserCollection extends Model {
Expand All @@ -332,7 +332,8 @@ UserCollection.init(
autoIncrement: true,
primaryKey: true,
allowNull: true
}
},
activeDateTime: DataTypes.DATE
},
{
sequelize,
Expand All @@ -349,7 +350,7 @@ Collection.belongsToMany(User, {
through: 'UserCollection',
foreignKey: 'albumName',
});
await sequelize.sync();
// await sequelize.sync();

// 회원: 포토카드 = 다대다
class UserPhotoCard extends Model {
Expand Down Expand Up @@ -382,7 +383,7 @@ PhotoCard.belongsToMany(User, {
through: 'UserPhotoCard',
foreignKey: 'photocardId',
});
await sequelize.sync();
// await sequelize.sync();

// //----일대일----
// Polaroid.sync();
Expand Down Expand Up @@ -604,41 +605,41 @@ const newJeans = Artist.build(
// })

//-------user----------
const userTemp = User.build(
{
// userId: 1,
email: 'ohnpol1004@naver.com',
nickname: 'ohnpol1004',
password: '1111',
avatar: 'https://ohnpol.s3.ap-northeast-2.amazonaws.com/users/avatar.png',
biography: '자기소개'
})

const userTemp2 = User.build(
{
// userId: 1,
email: 'user2@naver.com',
nickname: 'user2',
password: '2222',
avatar: 'https://ohnpol.s3.ap-northeast-2.amazonaws.com/users/avatar.png',
biography: 'user2입니다'
})
// const userTemp = User.build(
// {
// // userId: 1,
// email: 'ohnpol1004@naver.com',
// nickname: 'ohnpol1004',
// password: '1111',
// avatar: 'https://ohnpol.s3.ap-northeast-2.amazonaws.com/users/avatar.png',
// biography: '자기소개'
// })

//-------favorite----------
// const userTemp2 = User.build(
// {
// // userId: 1,
// email: 'user2@naver.com',
// nickname: 'user2',
// password: '2222',
// avatar: 'https://ohnpol.s3.ap-northeast-2.amazonaws.com/users/avatar.png',
// biography: 'user2입니다'
// })

const fav1 = Favorite.build(
{
favoriteQuant: 1,
userId: 1,
artistId: 1
}
)
//------like---------------
const like1 = Like.build({
likeQuant: 1,
userId:1,
postId:1
})
// //-------favorite----------

// const fav1 = Favorite.build(
// {
// favoriteQuant: 1,
// userId: 1,
// artistId: 1
// }
// )
// //------like---------------
// const like1 = Like.build({
// likeQuant: 1,
// userId:1,
// postId:1
// })

//----------------------saved---------------------------------
// await BTS.save();
Expand Down
24 changes: 24 additions & 0 deletions jwt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import jwt from 'jsonwebtoken';

export const verifyToken = (req, res, next) => {
// 인증 완료
try {
req.decoded = jwt.verify(req.headers.authorization, process.env.JWT_SECRET_KEY);
console.log(req.decoded);
return next();
}

// 인증 실패
catch (error) {
if (error.name === 'TokenExpireError') {
return res.status(419).json({
code: 419,
message: '토큰이 만료되었습니다.'
});
}
return res.status(401).json({
code: 401,
message: '유효하지 않은 토큰입니다.'
});
}
};
Loading

0 comments on commit c1e01d8

Please sign in to comment.