Skip to content

Commit

Permalink
feat: project featured
Browse files Browse the repository at this point in the history
  • Loading branch information
Asadaaaaa committed Nov 3, 2023
1 parent 71674ff commit fa9c872
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
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
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

0 comments on commit fa9c872

Please sign in to comment.