Skip to content
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
Binary file added .DS_Store
Binary file not shown.
2,150 changes: 1,160 additions & 990 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./src/index.js"
"start": "node && node dist/index.js",
"dev": "ts-node src/index.ts"
},
"repository": {
"type": "git",
Expand All @@ -18,9 +19,21 @@
},
"homepage": "https://github.com/DevKor-github/project3-back#readme",
"dependencies": {
"@googlemaps/google-maps-services-js": "^3.3.34",
"express": "^4.18.2",
"http": "^0.0.1-security",
"next-transpile-modules": "^10.0.0",
"node-geocoder": "^4.2.0",
"pg": "^8.11.1",
"typeorm": "^0.3.17"
"typeorm": "^0.3.17",
"wkx": "^0.5.0"
},
"type": "module"
"devDependencies": {
"@types/express": "^4.17.17",
"@types/googlemaps": "^3.43.3",
"@types/node-geocoder": "^4.2.1",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.9.5"
}
}
Binary file added src/.DS_Store
Binary file not shown.
23 changes: 0 additions & 23 deletions src/config/dataSource.js

This file was deleted.

31 changes: 31 additions & 0 deletions src/config/dataSource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { DataSource } from "typeorm";
import dotenv from "dotenv";
import { fileURLToPath } from "url";
import { dirname } from "path";
import { join } from "path";
import path from "path";

dotenv.config();
// const fileURL: string = import.meta.url;
// const filePath: string = fileURLToPath(fileURL);
// const dirPath: string = dirname(filePath);
// const dirPath = path.resolve();

const dataSource = new DataSource({
type: "postgres",
host: process.env.DB_HOST || "localhost",
port: Number(process.env.DB_PORT) || 5432,
username: process.env.DB_USER || "postgres",
password: process.env.DB_PASSWORD || "postgres",
database: process.env.DB_NAME || "naromaro",
synchronize: true,
//apiKey: process.env.googleMapAPI,
//entities: [join(__dirname, "/../entity/Post.ts")],

entities: [
join(__dirname, "/../entity/Post.ts"),
join(__dirname, "/../entity/Loation.ts"),
],
});

export default dataSource;
21 changes: 21 additions & 0 deletions src/controller/location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Request, Response, NextFunction } from "express";
//import * as locationService from "../service/locationService";
import { LocationSchema } from "../entity/Location";

import { geocodeAddress } from "../service/locationService";

export const getLocation = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
//const mylocation=await geocodeAddress;

const { address } = req.body.address;
const addtoCor = await geocodeAddress(address);
res.status(200).json(addtoCor);
} catch (error) {
next(error);
}
};
10 changes: 0 additions & 10 deletions src/controller/post.js

This file was deleted.

88 changes: 88 additions & 0 deletions src/controller/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { Request, Response, NextFunction } from "express";
import * as postService from "../service/postService";
import { PostSchema } from "../entity/Post";

//actual function implementation of CRUD Posts
export const getPostList = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const postList = await postService.getPostList();
res.status(200).json(postList);
res.send("my post");
} catch (err) {
next(err);
}
};

export const createPost = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const { content, author, title } = req.body;
const newPost = await postService.createPost(content, author, title);
res.status(201).json(newPost);
} catch (err) {
next(err);
}
};

export const getPostID = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const postID = parseInt(req.params.id, 10);
const post = await postService.getbyPostID(postID);
if (post) {
res.status(200).json(post);
} else {
res.status(404).json({ error: "Post not found" });
}
} catch (err) {
next(err);
}
};

export const updatePostID = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const postID = parseInt(req.params.id, 10);
const { content, title } = req.body;
const updatedPost = await postService.updatePostID(postID, content, title);
if (updatedPost) {
res.status(200).json(updatedPost);
} else {
res.status(404).json({ error: "Post not found" });
}
} catch (err) {
next(err);
}
};

export const deletePostID = async (
req: Request,
res: Response,
next: NextFunction
) => {
try {
const postID = parseInt(req.params.id, 10);
const deletionsuccess = await postService.deletePostID(postID);
if (deletionsuccess) {
//res.status(204).end();
res.status(204).json({ message: "Sucessufully deleted" });
} else {
res.status(404).json({ error: "Post not found" });
}
} catch (err) {
next(err);
}
};
36 changes: 36 additions & 0 deletions src/entity/Location.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
OneToMany,
BaseEntity,
JoinColumn,
} from "typeorm";
//import { Point, LineString } from "wkx";
import { Point } from "typeorm";
import { PostSchema } from "./Post";

//지오코딩 주소를 1600 Amphitheatre Parkway, Mountain View, CA
//->지리적 좌표 (위도 37.423021, 경도 -122.083739)로 변환

@Entity()
export class LocationSchema extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;

@Column({
type: "varchar",
length: 300,
})
address: string;

@Column({
type: "point",
nullable: true,
})
coordinate: Point;
//coordinate: "Point(-122.083 37.423021)"

/*@OneToMany(() => PostSchema, (postSchema) => postSchema.locationSchema)
postSchema: PostSchema[];*/
}
24 changes: 0 additions & 24 deletions src/entity/Post.js

This file was deleted.

51 changes: 51 additions & 0 deletions src/entity/Post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
ManyToOne,
JoinColumn,
} from "typeorm";

import { LocationSchema } from "./Location";

@Entity()
export class PostSchema {
@PrimaryGeneratedColumn()
id: number;

@Column({
type: "varchar",
length: 150,
unique: true,
})
title: string;

@Column({
type: "varchar",
length: 150,
})
author: string;

@Column({
type: "varchar",
length: 150,
})
content: string;

@Column({
type: "varchar",
length: 150,
nullable: true,
})
location: string;

//relationhip 설정 PostSchemea(MANY)to Location(ONE)
/*@ManyToOne(
() => LocationSchema,
(locationSchema) => locationSchema.postSchema
)
@JoinColumn({
name: "location",
})
locationSchema: LocationSchema;*/
}
Empty file removed src/entity/User.js
Empty file.
1 change: 1 addition & 0 deletions src/entity/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

55 changes: 0 additions & 55 deletions src/index.js

This file was deleted.

Loading