Skip to content

Commit

Permalink
refactor admin controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
ruislan committed Oct 18, 2023
1 parent 0b92af5 commit 7fdb5ce
Show file tree
Hide file tree
Showing 14 changed files with 326 additions and 201 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ KTap是一个时尚的游戏社区平台。
<tr>
<td><img src="./docs/screenshots/index.png"/></td>
<td><img src="./docs/screenshots/discover.png"/></td>
<td><img src="./docs/screenshots/rank.png"/></td>
<td><img src="./docs/screenshots/news.png"/></td>
<td><img src="./docs/screenshots/rank.png"/></td>
<td><img src="./docs/screenshots/discussions.png"/></td>
</tr>
<tr>
<td><img src="./docs/screenshots/app-detail.png"/></td>
<td><img src="./docs/screenshots/review.png"/></td>
<td><img src="./docs/screenshots/news-detail.png"/></td>
<td><img src="./docs/screenshots/user-center.png"/></td>
<td><img src="./docs/screenshots/user-achievements.png"/></td>
<td><img src="./docs/screenshots/discussion-posts.png"/></td>
</tr>
</table>
Expand Down Expand Up @@ -105,13 +105,14 @@ SQLite仅仅作为开发、演示和独立小规模运营是非常棒的,甚

## 接下来

* 增加专题专栏(例如节日专题,打折专题,新品专题等等)
接下来可能会研发的功能...

* 增加 App 活动事件(线上或者线下活动)
* 增加组织管理(组织所有人自己管理自己的组织)
* 增加专题专栏(例如节日专题,打折专题,新品专题等等)
* 增加商城和充值(余额购买虚拟或者实体商品)
* 增加搜索引擎,改进搜索、相关性算法
* 数据库支持MySQL或PG
* 持续重构和优化

## 致敬

Expand Down
4 changes: 2 additions & 2 deletions ktap-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
"@fastify/helmet": "^11.1.1",
"@fastify/jwt": "^7.2.2",
"@fastify/multipart": "^8.0.0",
"@fastify/sensible": "^5.3.0",
"@fastify/sensible": "^5.4.0",
"@fastify/static": "^6.11.2",
"@node-rs/jieba": "^1.7.2",
"@prisma/client": "^5.4.2",
"ajv-errors": "^3.0.0",
"bcrypt": "^5.1.0",
"cheerio": "^1.0.0-rc.12",
"dotenv": "^16.0.3",
"fastify": "^4.24.0",
"fastify": "^4.24.2",
"ms": "^2.1.3",
"node-cron": "^3.0.2",
"nodemailer": "^6.9.1",
Expand Down
118 changes: 117 additions & 1 deletion ktap-server/src/models/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { AppMedia } from '../constants.js';
import { AppMedia, TagCategory } from '../constants.js';

const app = async (fastify, opts, next) => {
fastify.decorate('app', {
Expand Down Expand Up @@ -86,6 +86,122 @@ const app = async (fastify, opts, next) => {
// 用户可能输入了类型或者功能相同的词,要排除掉,这些词是不需要标记的
if (theTag.category === TagCategory.normal) await fastify.db.appUserTagRef.upsert({ create: { appId, userId, tagId: theTag.id }, update: {}, where: { appId_userId_tagId: { userId, appId, tagId: theTag.id } } });
},

// these actions for admin
async createApp({ name }) {
const newApp = await fastify.db.app.create({
data: {
name,
isVisible: false, // 初始为不可见,操作完成之后再可见
media: {
create: [
{ type: AppMedia.type.image, usage: AppMedia.usage.head, image: 'https://placehold.co/460x215/png', thumbnail: 'https://placehold.co/292x136/png' },
{ type: AppMedia.type.image, usage: AppMedia.usage.landscape, image: 'https://placehold.co/2560x1440/png', thumbnail: 'https://placehold.co/616x353/png' },
{ type: AppMedia.type.image, usage: AppMedia.usage.portrait, image: 'https://placehold.co/1200x1600/png', thumbnail: 'https://placehold.co/374x448/png' },
{ type: AppMedia.type.image, usage: AppMedia.usage.logo, image: 'https://placehold.co/400x400/png', thumbnail: 'https://placehold.co/128x128/png' }
]
}
},
});
return newApp;
},
async updateAppBasis({ appId, isVisible, score }) {
await fastify.db.app.update({
where: { id: appId },
data: { isVisible, score }
});
},
async updateApp({ appId, name, slogan, summary, description, score, releasedAt, downloadUrl, legalText, legalUrl }) {
await fastify.db.app.update({
where: { id: appId },
data: { name, slogan, summary, description, score, releasedAt, downloadUrl, legalText, legalUrl }
});
},
async updateAppMediaExcludeGallery({ appId, usage, image, thumbnail }) {
await fastify.db.appMedia.updateMany({ where: { appId, usage, type: AppMedia.type.image }, data: { image, thumbnail } });
},
async updateAppMediaGallery({ appId, video, images }) {
const deleteOld = fastify.db.appMedia.deleteMany({ where: { appId, usage: AppMedia.usage.gallery } });
const createNewVideo = video.map(item =>
fastify.db.appMedia.create({
data: {
appId, image: item.image, thumbnail: item.thumbnail, video: item.video, usage: AppMedia.usage.gallery, type: AppMedia.type.video
}
})
);
const createNewImages = images.map(item =>
fastify.db.appMedia.create({
data: {
appId, image: item.image, thumbnail: item.thumbnail, usage: AppMedia.usage.gallery, type: AppMedia.type.image,
}
})
);
await fastify.db.$transaction([deleteOld, ...createNewVideo, ...createNewImages]);
},
async createAppSocialLink({ appId, name, brand, url }) {
const data = await fastify.db.appSocialLink.create({ data: { appId, name, brand, url } });
return data;
},
async deleteAppSocialLink({ socialLinkId }) {
await fastify.db.appSocialLink.delete({ where: { id: socialLinkId } });
},
async updateAppPublishers({ appId, publishers }) {
if (!publishers || publishers.length === 0) return;
const deleteOld = fastify.db.appPublisherRef.deleteMany({ where: { appId } });
const createNew = publishers.map(organizationId => fastify.db.appPublisherRef.create({ data: { appId, organizationId } }));
await fastify.db.$transaction([deleteOld, ...createNew]);
},
async updateAppDevelopers({ appId, developers }) {
if (!developers || developers.length === 0) return;
const deleteOld = fastify.db.appDeveloperRef.deleteMany({ where: { appId } });
const createNew = developers.map(organizationId => fastify.db.appDeveloperRef.create({ data: { appId, organizationId } }));
await fastify.db.$transaction([deleteOld, ...createNew]);
},
async updateAppFeatures({ appId, features }) {
if (!features || features.length === 0) return;
const createNewRefs = features.map(featureId => fastify.db.appFeatureRef.create({ data: { appId, tagId: featureId } }));
await fastify.db.$transaction(createNewRefs);
},
async deleteAppFeature({ appId, featureId }) {
await fastify.db.appFeatureRef.deleteMany({ where: { appId, tagId: featureId } });
},
async updateAppGenres({ appId, genres }) {
if (!genres || genres.length === 0) return;
const createNewRefs = genres.map(genreId => fastify.db.appGenreRef.create({ data: { appId, tagId: genreId } }));
await fastify.db.$transaction(createNewRefs);
},
async deleteAppGenre({ appId, genreId }) {
await fastify.db.appGenreRef.deleteMany({ where: { appId, tagId: genreId } });
},
async deleteAppTag({ appId, tagId }) {
await fastify.db.appUserTagRef.deleteMany({ where: { appId, tagId } }); // all users' tag relationships will be deleted
},
async updateAppPlatforms({ appId, platforms }) {
if (!platforms || platforms.length === 0) return;
const deleteOld = fastify.db.appPlatform.deleteMany({ where: { appId } });
const createNewPlatforms = platforms.map(platform =>
fastify.db.appPlatform.create({
data: {
appId,
os: platform.os,
requirements: JSON.stringify(platform.requirements),
}
})
);
await fastify.db.$transaction([deleteOld, ...createNewPlatforms]);
},
async createAppAward({ appId, image, url }) {
const data = await fastify.db.appAward.create({
data: { appId, image, url }
});
return data;
},
async deleteAppAward({ appId, awardId }) {
await fastify.db.appAward.delete({ where: { id: awardId, appId, } });
},
async updateAppLanguages({ appId, text, audio, caption }) {
await fastify.db.appLanguages.upsert({ where: { appId }, create: { text, audio, caption, appId }, update: { text, audio, caption } });
}
});
next();
};
Expand Down
9 changes: 9 additions & 0 deletions ktap-server/src/models/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ const review = async (fastify, opts, next) => {
(SELECT count(*) FROM ReviewThumb WHERE direction = 'down' AND review_id = ${id}) AS downs
`)[0];
},
async createProReview({ appId, name, url, summary, score }) {
const data = await fastify.db.proReview.create({
data: { appId, name, url, summary, score }
});
return data;
},
async deleteProReview({ proReviewId }) {
await fastify.db.proReview.delete({ where: { id: proReviewId } });
},
});
next();
};
Expand Down
Loading

0 comments on commit 7fdb5ce

Please sign in to comment.