Skip to content
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
1 change: 1 addition & 0 deletions @types/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ declare namespace NodeJS {
PASSPORT_KAKAO_CLIENT_ID: string;
PASSPORT_KAKAO_CLIENT_SECRET: string;
EXPRESS_SESSION_SECRET: string;
EC2IP: string;
}
}
4 changes: 4 additions & 0 deletions config/tsoa.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"validate": true,
"spec": {
"servers": [
{
"url": "http://18.208.62.86:3000",
"description": "Production Server"
},
{
"url": "http://localhost:3000",
"description": "local server"
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"@tsoa/runtime": "^6.6.0",
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"date-fns": "^4.1.0",
"date-fns-tz": "^3.2.0",
"dotenv": "^16.4.7",
"express": "^5.0.0-0",
"express-session": "^1.18.1",
Expand Down
17 changes: 13 additions & 4 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import passport from 'passport';
import session from 'express-session';
import {PrismaSessionStore} from '@quixo3/prisma-session-store';
import cookieParser from 'cookie-parser';
import {sessionAuthMiddleware} from './auth.config.js';
// import {sessionAuthMiddleware} from './auth.config.js';
import {prisma} from './db.config.js';
import {RegisterRoutes} from './routers/tsoaRoutes.js';
import {authRouter} from './routers/auth.router.js';
Expand All @@ -24,7 +24,13 @@ dotenv.config();
const app = express();
const port = process.env.PORT;

app.use(cors());
app.use(
// cors({
// origin: ['http://localhost:3000', 'http://18.208.62.86:3000'], // 프론트엔드 주소
// credentials: true,
// }),
cors(),
);
app.use(express.static('public'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
Expand Down Expand Up @@ -61,6 +67,9 @@ app.use(
saveUninitialized: false,
cookie: {
maxAge: 7 * 24 * 60 * 60 * 1000, // 일주일
// sameSite: 'lax',
// secure: false,
// httpOnly: true,
},
store: new PrismaSessionStore(prisma, {
checkPeriod: 2 * 60 * 1000,
Expand Down Expand Up @@ -88,7 +97,7 @@ app.use(passport.session());
app.use('/oauth2', authRouter);

// 인증 미들웨어
app.use(sessionAuthMiddleware);
// app.use(sessionAuthMiddleware);

// 로그인 후
RegisterRoutes(app);
Expand Down Expand Up @@ -127,6 +136,6 @@ const errorHandler: ErrorRequestHandler = (err, req, res, next) => {

app.use(errorHandler);

app.listen(port, () => {
app.listen(Number(port), '0.0.0.0', () => {
console.log(`Example app listening on port ${port}`);
});
7 changes: 5 additions & 2 deletions src/auth.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {UserModel} from './models/user.model.js';
import {SocialProfile} from './models/auth.model.js';
import {Request, Response, NextFunction} from 'express';
import {ServerError, AuthError, SessionError} from './error.js';
// import {publishUserId} from './mqtt-client.js';
dotenv.config();

const updateOrCreateSocialAccount = async (
Expand Down Expand Up @@ -50,7 +51,7 @@ export const kakaoStrategy = new KakaoStrategy(
{
clientID: process.env.PASSPORT_KAKAO_CLIENT_ID!,
clientSecret: process.env.PASSPORT_KAKAO_CLIENT_SECRET!, // Optional in Kakao
callbackURL: 'http://localhost:3000/oauth2/callback/kakao',
callbackURL: `http://${process.env.EC2IP}:3000/oauth2/callback/kakao`,
},
async (accessToken, refreshToken, profile, cb) => {
try {
Expand Down Expand Up @@ -84,7 +85,7 @@ const verifyUser = async (
// SocialAccount 데이터 추가 또는 업데이트
const {id, email, name} = user;
await updateOrCreateSocialAccount(id, profile, provider);

// publishUserId(user.id);
return {id, email, name};
}

Expand All @@ -107,6 +108,8 @@ const verifyUser = async (
],
});

// publishUserId(createdUser.id);

// SocialAccount 데이터 추가
const {id, email, name} = createdUser;
await updateOrCreateSocialAccount(id, profile, provider);
Expand Down
64 changes: 60 additions & 4 deletions src/controllers/tsoa.focus-target.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import {Request as ExpressRequest} from 'express';
import {StatusCodes} from 'http-status-codes';
import {
DailyStatisticsResponse,
FocusTargetListResponse,
FocusTargetResponse,
} from '../models/focus-target.model.js';
Expand All @@ -22,6 +23,7 @@ import {
TsoaSuccessResponse,
} from '../models/tsoa-response.js';
import {
DailyStatisticsGet,
FocusTargetListGet,
FocusTargetUpdateDisable,
FocusTargetUpdateEnable,
Expand Down Expand Up @@ -142,11 +144,10 @@ export class FocusTargetController extends Controller {
],
},
})
public async GetFocusTargetList(
@Request() req: ExpressRequest,
): Promise<ITsoaSuccessResponse<FocusTargetListResponse>> {
public async GetFocusTargetList() // @Request() req: ExpressRequest,
: Promise<ITsoaSuccessResponse<FocusTargetListResponse>> {
try {
const userId = BigInt(req.user!.id);
const userId = BigInt(11); //BigInt(req.user!.id);
const focusTargetList = await FocusTargetListGet(userId);
return new TsoaSuccessResponse(focusTargetList);
} catch (error) {
Expand All @@ -163,4 +164,59 @@ export class FocusTargetController extends Controller {
// throw error;
// }
// }

/**
* 집중 시간 일간 통계를 조회하는 API입니다.
*
* 0: 토, 1: 일, 2: 월, 3: 화, 4: 수, 5: 목, 6: 금
*
* @summary 일간 통계 조회 API
* @returns 일간 통계 조회 결과를 반환합니다.
*/
@Get('/statistics/daily')
@Tags('Focus-Target-Controller')
@SuccessResponse(StatusCodes.OK, '일간 통계 조회 성공 응답')
@Example({
resultType: 'SUCCESS',
error: null,
success: {
dailyTotalTime: {
'0': 60,
'1': 60,
'2': 60,
'3': 60,
'4': 60,
'5': 60,
'6': 60,
},
today: {
disabledTarget: [
{
target: '책/교재',
targetId: '1',
startTime: '2025-01-17T03:50:25',
endTime: '2025-01-17T04:50:25',
},
],
enabledTarget: [
{
target: '책/교재',
targetId: '1',
startTime: '2025-01-17T03:50:25',
endTime: '2025-01-17T04:50:25',
},
],
},
},
})
public async GetDailyStatistics() // @Request() req: ExpressRequest,
: Promise<ITsoaSuccessResponse<DailyStatisticsResponse>> {
try {
const userId = BigInt(11); //BigInt(req.user!.id);
const dailyStatistics = await DailyStatisticsGet(userId);
return new TsoaSuccessResponse(dailyStatistics);
} catch (error) {
throw error;
}
}
}
21 changes: 10 additions & 11 deletions src/controllers/tsoa.group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Controller,
Example,
Post,
Request,
// Request,
Route,
SuccessResponse,
Response,
Expand All @@ -17,7 +17,7 @@ import {
ITsoaSuccessResponse,
TsoaSuccessResponse,
} from '../models/tsoa-response.js';
import {Request as ExpressRequest} from 'express';
// import {Request as ExpressRequest} from 'express';
import {
BodyToGroup,
GroupListResponse,
Expand Down Expand Up @@ -68,11 +68,11 @@ export class GroupController extends Controller {
},
})
public async handleGroupAdd(
@Request() req: ExpressRequest,
// @Request() req: ExpressRequest,
@Body() body: BodyToGroup,
): Promise<ITsoaSuccessResponse<GroupResponse>> {
try {
const hostId = BigInt(req.user!.id);
const hostId = BigInt(11); //BigInt(req.user!.id);
const group = await groupCreate(hostId, bodyToGroup(body));
return new TsoaSuccessResponse(group);
} catch (error) {
Expand Down Expand Up @@ -114,7 +114,7 @@ export class GroupController extends Controller {
},
})
public async handleGroupGet(
@Request() req: ExpressRequest,
// @Request() req: ExpressRequest,
@Path('groupId') groupIdParam: string,
): Promise<ITsoaSuccessResponse<GroupResponse>> {
try {
Expand Down Expand Up @@ -143,11 +143,10 @@ export class GroupController extends Controller {
groups: [{id: '1', name: 'string', memberCount: 1}],
},
})
public async handleGroupListGet(
@Request() req: ExpressRequest,
): Promise<ITsoaSuccessResponse<GroupListResponse>> {
public async handleGroupListGet() // @Request() req: ExpressRequest,
: Promise<ITsoaSuccessResponse<GroupListResponse>> {
try {
const userId = BigInt(req.user!.id);
const userId = BigInt(11); //BigInt(req.user!.id);
const group = await groupListGet(userId);
return new TsoaSuccessResponse(group);
} catch (error) {
Expand Down Expand Up @@ -200,11 +199,11 @@ export class GroupController extends Controller {
},
})
public async handledGroupJoin(
@Request() req: ExpressRequest,
// @Request() req: ExpressRequest,
@Path('groupId') groupIdParam: string,
): Promise<ITsoaSuccessResponse<GroupUserResponse>> {
try {
const userId = BigInt(req.user!.id);
const userId = BigInt(11); //BigInt(req.user!.id);
const groupId = BigInt(groupIdParam);
const groupUser = await groupJoin(groupId, userId);
return new TsoaSuccessResponse(groupUser);
Expand Down
11 changes: 5 additions & 6 deletions src/controllers/tsoa.schedule.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ export class ScheduleController extends Controller {
},
})
public async handleScheduleAdd(
@Request() req: ExpressRequest,
// @Request() req: ExpressRequest,
@Body() body: BodyToSchedule,
): Promise<ITsoaSuccessResponse<ScheduleResponse>> {
try {
const userId = BigInt(req.user!.id);
const userId = BigInt(11); //BigInt(req.user!.id);
const schedule = await scheduleCreate(userId, bodyToSchedule(body));
return new TsoaSuccessResponse(schedule);
} catch (error) {
Expand Down Expand Up @@ -195,11 +195,10 @@ export class ScheduleController extends Controller {
},
},
})
public async handleWeekScheduleGet(
@Request() req: ExpressRequest,
): Promise<ITsoaSuccessResponse<WeeklyScheduleResponse>> {
public async handleWeekScheduleGet() // @Request() req: ExpressRequest,
: Promise<ITsoaSuccessResponse<WeeklyScheduleResponse>> {
try {
const userId = BigInt(req.user!.id);
const userId = BigInt(11); //BigInt(req.user!.id);

const weeklySchedule = await weeklyScheduleGet(userId);
console.log('최종 주간 일정:', weeklySchedule);
Expand Down
24 changes: 24 additions & 0 deletions src/dtos/focus-target.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DailyStatisticsResponse,
FocusTargetListResponse,
FocusTargetResponse,
} from 'src/models/focus-target.model.js';
Expand Down Expand Up @@ -29,3 +30,26 @@ export const responseFromFocusTargetList = ({
})),
};
};

export const responseFromDailyStatistics = ({
dailyTotalTime,
today,
}: DailyStatisticsResponse): DailyStatisticsResponse => {
return {
dailyTotalTime: dailyTotalTime,
today: {
disabledTarget: today.disabledTarget.map(target => ({
targetId: target.targetId,
startTime: target.startTime,
endTime: target.endTime,
target: target.target,
})),
enabledTarget: today.enabledTarget.map(target => ({
targetId: target.targetId,
startTime: target.startTime,
endTime: target.endTime,
target: target.target,
})),
},
};
};
28 changes: 27 additions & 1 deletion src/models/focus-target.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface FocusTargetResponse {

export interface FocusTargetState {
targetId: string;
userId: string;
groupId: string[];
timestamp: Date;
isInitial: Date;
}
Expand All @@ -20,3 +20,29 @@ export interface FocusTargetListResponse {
status: number;
}[];
}

export interface DailyStatisticsResponse {
dailyTotalTime: {
'0': number;
'1': number;
'2': number;
'3': number;
'4': number;
'5': number;
'6': number;
};
today: {
disabledTarget: {
target: string;
targetId: string;
startTime: Date;
endTime: Date;
}[];
enabledTarget: {
target: string;
targetId: string;
startTime: Date;
endTime: Date;
}[];
};
}
Loading