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

Dev/asadaaaaa #91

Merged
merged 2 commits into from
Nov 3, 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
5 changes: 4 additions & 1 deletion src/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ class Server {

run() {
this.API = Express();
const middlewareHandler = new MiddlewareHandler(this);

new MiddlewareHandler(this);
middlewareHandler.global();
new RouteHandler(this);
middlewareHandler.missingRoute();


this.API.listen(this.env.PORT, this.env.IP, () => this.sendLogs('Server Started, Listening PORT ' + this.env.PORT));
}
Expand Down
10 changes: 10 additions & 0 deletions src/controller/primary/Project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,16 @@ class ProjectController {
));
}

// --- Get Project Featured
async getProjectFeatured(req, res) {
const getProjectTrendsSrv = await this.ProjectService.getProjectFeatured();

return res.status(200).json(this.ResponsePreset.resOK(
'OK',
getProjectTrendsSrv
));
}

async searchProject(req, res) {
const { text, category } = req.query;
const { userId } = req.middlewares.authorization;
Expand Down
9 changes: 7 additions & 2 deletions src/middlewares/Handler.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Handler {
this.API = this.server.API;

this.ResponsePreset = new ResponsePreset();

this.global();
}

global() {
Expand Down Expand Up @@ -107,6 +105,13 @@ class Handler {
}));
}
}

missingRoute() {
this.API.get('*', (req, res) => {
// Redirect to the desired URL
res.redirect(`${this.server.env.WEB_HOST}/not-found`);
});
}
}

export default Handler;
26 changes: 26 additions & 0 deletions src/models/ProjectFeatured.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Library
import { DataTypes } from "sequelize";

class ProjectFeatured {
constructor(server) {
const table = server.model.db.define('project_featured', {
project_rank: DataTypes.STRING(17.10),
project_id: DataTypes.STRING(36),
user_id: DataTypes.STRING(36),
title: DataTypes.STRING(25),
description: DataTypes.STRING(700),
logo_path: DataTypes.TEXT,
published_datetime: DataTypes.DATE,
total_likes: DataTypes.BIGINT(21),
total_comments: DataTypes.BIGINT(21)
}, {
tableName: 'project_featured',
timestamps: false
});
table.removeAttribute('id');

this.table = table;
}
}

export default ProjectFeatured;
1 change: 1 addition & 0 deletions src/routes/primary/Project.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ProjectRoute extends Primary {
// Get List Projects
this.API.get(this.endpointPrefix + '/get/foryou', this.AuthorizationMiddleware.check(), (req, res) => this.ProjectController.getForYou(req, res));
this.API.get(this.endpointPrefix + '/trends/project', this.AuthorizationMiddleware.check(), (req, res) => this.ProjectController.getProjectTrends(req, res));
this.API.get(this.endpointPrefix + '/featured/project', (req, res) => this.ProjectController.getProjectFeatured(req, res));

// Get Project Searching
this.API.get(this.endpointPrefix + '/search', this.AuthorizationMiddleware.check(), (req, res) => this.ProjectController.searchProject(req, res));
Expand Down
16 changes: 16 additions & 0 deletions src/services/primary/Project.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ProjectThumbnailModel from "../../models/ProjectThumbnail.model.js";
import ProjectPreviewModel from "../../models/ProjectPreview.model.js";
import ProjectFilesModel from "../../models/ProjectFiles.model.js";
import ProjectRankModel from "../../models/ProjectRank.model.js";
import ProjectFeaturedModel from "../../models/ProjectFeatured.model.js";
import ProjectLikesModel from "../../models/ProjectLikes.model.js";
import ProjectCommentsModel from "../../models/ProjectComments.model.js";
import FollowingModel from "../../models/Following.model.js";
Expand All @@ -34,6 +35,7 @@ class ProjectService {
this.ProjectPreviewModel = new ProjectPreviewModel(this.server).table;
this.ProjectFilesModel = new ProjectFilesModel(this.server).table;
this.ProjectRankModel = new ProjectRankModel(this.server).table;
this.ProjectFeaturedModel = new ProjectFeaturedModel(this.server).table;
this.ProjectLikesModel = new ProjectLikesModel(this.server).table;
this.ProjectCommentsModel = new ProjectCommentsModel(this.server).table;
this.FollowingModel = new FollowingModel(this.server).table;
Expand Down Expand Up @@ -1083,6 +1085,20 @@ class ProjectService {
return await this.getListPreviewProjects(getDataProjectRankModel, userId);
}

async getProjectFeatured() {
const getDataProjectFeaturedModel = await this.ProjectFeaturedModel.findAll({
attributes: [
['project_id', 'id'],
'user_id',
'title',
'description',
['logo_path', 'logo']
]
});

return await this.getListPreviewProjects(getDataProjectFeaturedModel, null);
}

async getCategoryProject() {
const getDataCategoryModel = await this.CategoryModel.findAll({
order: [
Expand Down