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

Development #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ dist

# TernJS port file
.tern-port
.idea
2 changes: 1 addition & 1 deletion dto/CreatePostDTO.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//Plain Javascript and Node.js is supported
// html/css is not supported here

const Visible = require('./Visible');
const Visible = require('../model/Visible');

class CreatePostDTO {
constructor(visible, country, tag, type, rating, postText, isExperience) {
Expand Down
2 changes: 1 addition & 1 deletion dto/UserDTO.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Role = require('./Role');
const Role = require('../model/Role');

class UserDTO {
constructor(userName, password, email) {
Expand Down
38 changes: 19 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Country = require('./model/Country');
const IPLog = require('./model/IPLog');
const LomyVerified = require('./model/LomyVerified');
const Media = require('./model/Media');
//const Post = require('./model/Post');
const Post = require('./model/Post');
const Reaction = require('./model/Reaction');
const Role = require('./model/Role');
const Tag = require('./model/Tag');
Expand All @@ -20,34 +20,34 @@ const User = require('./model/User');
const UserRole = require('./model/UserRole');
const Visible = require('./model/Visible');
const Verified = require('./model/Verified');
//const UserDTO = require('./dto/UserDTO');
//const CreatPostDTO = require('./dto/CreatPostDTO');
//const LoginDTO = require('./dto/LoginDTO');
//const TagDTO = require('./dto/TagDTO');
//const TypeDTO = require('./dto/TypeDTO');
const UserDTO = require('./dto/UserDTO');
const CreatPostDTO = require('./dto/CreatePostDTO');
const LoginDTO = require('./dto/LoginDTO');
const TagDTO = require('./dto/TagDTO');
const TypeDTO = require('./dto/TypDTO');
const SwearWord = require('./languageUtils/SwearWord');
const TypeController = require('./web/TypeController');
const TagController = require('./web/TagController');
//const CountryDTO = require('./dto/CountryDTO');
const CountryDTO = require('./dto/ContraryDTO');
const JwtProvider = require('./security/JwtProvider');
const JwtTokenFilter = require('./security/JwtTokenFilter');
const LomyUserDetailsService = require('./security/LomyUserDetailsService');
//const RequestService = require('./security/RequestService');
//const RequestServiceImpl = require('./security/RequestServiceImpl');
const RequestService = require('./security/RequestService');
const RequestServiceImpl = require('./security/RequestServiceImpl');
const WebSecurityConfiguration = require('./security/WebSecurityConfiguration');
//const AddService = require('./service/AddService');
//const CountryService = require('./service/CountryService');
const uploadFile = require('./uploadFile');
//const TagService = require('./service/TagService');
//const TypeService = require('./service/TypeService');
//const UserService = require('./service/UserService');
const AddService = require('./service/AddService');
const CountryService = require('./service/CountryService');
const uploadFile = require('./service/FileService');
const TagService = require('./service/TagService');
const TypeService = require('./service/TypeService');
const UserService = require('./service/UserService');
//const PostService = require('./service/PostService');
//const FileService = require('./service/FileService');
//const FileStorageException = require('./service/FileStorageException');
const AdMediaController = require('./web/AdMediaController');
const CountryController = require('./web/CountryController');
const PostController = require('./web/PostController');
const UserController = require('./web/UserController');
// const AdMediaController = require('./web/AdMediaController');
// const CountryController = require('./web/CountryController');
// const PostController = require('./web/PostController');
// const UserController = require('./web/UserController');

// Initialize express app
const app = express();
Expand Down
167 changes: 68 additions & 99 deletions model/Post.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
// node.js module that exports a class called Post
class Post {
constructor(
id,
postText,
isExperience,
likes,
dislikes,
visible,
verified,
tag,
user,
country,
type,
numberOfReports,
postRating,
postDate,
postStatus,
media
) {
this.id = id;
this.postText = postText;
this.isExperience = isExperience;
this.likes = likes;
this.dislikes = dislikes;
this.visible = visible;
this.verified = verified;
this.tag = tag;
this.user = user;
this.country = country;
this.type = type;
this.numberOfReports = numberOfReports;
this.postRating = postRating;
this.postDate = postDate;
this.postStatus = postStatus;
this.media = media;
// transient properties
this.isAuthor = false;
this.isLiked = false;
this.isDisliked = false;
}
// getters and setters for transient properties
getAuthor() {
return this.isAuthor;
}
setAuthor(author) {
this.isAuthor = author;
}
getLiked() {
return this.isLiked;
}
setLiked(liked) {
this.isLiked = liked;
}
getDisliked() {
return this.isDisliked;
}
setDisliked(disliked) {
this.isDisliked = disliked;
}
}
// class Post {
// constructor(
// id,
// postText,
// isExperience,
// likes,
// dislikes,
// visible,
// verified,
// tag,
// user,
// country,
// type,
// numberOfReports,
// postRating,
// postDate,
// postStatus,
// media
// ) {
// this.id = id;
// this.postText = postText;
// this.isExperience = isExperience;
// this.likes = likes;
// this.dislikes = dislikes;
// this.visible = visible;
// this.verified = verified;
// this.tag = tag;
// this.user = user;
// this.country = country;
// this.type = type;
// this.numberOfReports = numberOfReports;
// this.postRating = postRating;
// this.postDate = postDate;
// this.postStatus = postStatus;
// this.media = media;
//
// // transient properties
// this.isAuthor = false;
// this.isLiked = false;
// this.isDisliked = false;
//
// }
//
// // getters and setters for transient properties
// getAuthor() {
// return this.isAuthor;
// }
//
// setAuthor(author) {
// this.isAuthor = author;
// }
//
// getLiked() {
// return this.isLiked;
// }
//
// setLiked(liked) {
// this.isLiked = liked;
// }
//
// getDisliked() {
// return this.isDisliked;
// }
//
// setDisliked(disliked) {
// this.isDisliked = disliked;
// }
// }
//TODO Add createDate field
class Post {
constructor(
Expand Down Expand Up @@ -216,37 +216,6 @@ class Post {
setNumberOfReports(numberOfReports) {
this.numberOfReports = numberOfReports;
}
   getType() {
    return this.type;
}

setType(type) {
    this.type = type;
}

getTag() {
    return this.tag;
}

setTag(tag) {
    this.tag = tag;
}

toString() {
    return "Post{" +
            "id=" + this.id +
            ", postText='" + this.postText + '\'' +
            ", isExperience='" + this.isExperience + '\'' +
            ", likes=" + this.likes +
            ", dislikes=" + this.dislikes +
            ", visible='" + this.visible + '\'' +
            ", verified='" + this.verified + '\'' +
            ", user=" + this.user +
            ", country=" + this.country +
            ", type=" + this.type +
            ",tag=" + this.tag +
            ", postRating=" + this.postRating + "}";
}
}

module.exports = Post;
Expand Down
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "lomy-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/myarsk/Lomy-backend.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/myarsk/Lomy-backend/issues"
},
"homepage": "https://github.com/myarsk/Lomy-backend#readme",
"dependencies": {
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"enum": "^3.0.4",
"express": "^4.18.2",
"js-base64": "^3.7.5",
"jsonwebtoken": "^9.0.0",
"log4js": "^6.9.1",
"mongoose": "^7.0.3",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.2.0",
"sequelize": "^6.31.0"
}
}
4 changes: 2 additions & 2 deletions repository/CountryRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ async function deleteById(id) {
});
}

async function findByCountry(country) {
async function findByCountry(c) {
const country = await Country.findOne({
where: {
country
country: c
}
});
return country;
Expand Down
4 changes: 2 additions & 2 deletions repository/TagRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ async function findById(id) {
return tag;
}

async function findByTag(tag) {
async function findByTag(t) {
const tag = await Tag.findOne({
where: {
tag
tag: t
}
});
return tag;
Expand Down
4 changes: 2 additions & 2 deletions repository/TypeRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ async function findById(id) {
return type;
}

async function findByType(type) {
async function findByType(t) {
const type = await Type.findOne({
where: {
type
type: t
}
});
return type;
Expand Down
5 changes: 3 additions & 2 deletions security/JwtProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
//Plain Javascript and Node.js is supported
// html/css is not supported here

let roles = ['user'];
// Node.js version
const jwt = require('jsonwebtoken');
const { Base64 } = require('js-base64');
const { SimpleGrantedAuthority } = require('spring-security-core');
// const { SimpleGrantedAuthority } = require('spring-security-core');

class JwtProvider {
constructor(secretKey, validityInMilliseconds) {
Expand All @@ -17,7 +18,7 @@ class JwtProvider {
createToken(username, roles) {
const claims = {
sub: username,
roles: roles.map(role => new SimpleGrantedAuthority(role.authority))
roles: roles.map(role => role[0])
};
const now = new Date();
const expiresAt = new Date(now.getTime() + this.validityInMilliseconds);
Expand Down
2 changes: 1 addition & 1 deletion security/JwtTokenFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Node.js version
const logger = require('log4js').getLogger('JwtTokenFilter');
const LomyUserDetailsService = require('./LomyUserDetailsService');
const { SecurityContextHolder, PreAuthenticatedAuthenticationToken } = require('spring-security-core');
// const { SecurityContextHolder, PreAuthenticatedAuthenticationToken } = require('spring-security-core');

class JwtTokenFilter {
constructor(userDetailsService) {
Expand Down
6 changes: 3 additions & 3 deletions security/LomyUserDetailsService.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//Node.js 10.14.0
//Plain Javascript and Node.js is supported
// Node.js version
const UserRepository = require('./UserRepository');
// const UserRepository = require('./UserRepository');
const JwtProvider = require('./JwtProvider');
const { withUsername } = require('spring-security-core');
// const { withUsername } = require('spring-security-core');

class LomyUserDetailsService {
constructor() {
Expand All @@ -18,7 +18,7 @@ class LomyUserDetailsService {
throw new UsernameNotFoundException(`User with name ${s} doesn't exist`);
}

return withUsername(user.getUserName())
user.getUserName()
.password(user.getPassword())
.authorities(user.getRoles())
.accountExpired(false)
Expand Down
6 changes: 3 additions & 3 deletions security/WebSecurityConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//Plain Javascript and Node.js is supported
// html/css is not supported here

const UserRoleRepository = require('path/to/UserRoleRepository');
const LomyUserDetailsService = require('path/to/LomyUserDetailsService');
const JwtTokenFilter = require('path/to/JwtTokenFilter');
const UserRoleRepository = require('../repository/UserRoleRepository');
const LomyUserDetailsService = require('../security/LomyUserDetailsService');
const JwtTokenFilter = require('../security/JwtTokenFilter');
const BCryptPasswordEncoder = require('bcryptjs');

class WebSecurityConfiguration {
Expand Down
Loading