adding project page

This commit is contained in:
2025-02-17 07:52:50 -06:00
parent f6daf6e7d3
commit fd5dcf5756
94 changed files with 2097 additions and 2126 deletions

View File

@@ -1,7 +0,0 @@
*.js.map
*.ts
.git*
.vscode
local.settings.json
test
tsconfig.json

View File

@@ -1,3 +0,0 @@
{
"version": "2.0"
}

View File

@@ -1,13 +0,0 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"AZURE_STORAGE_CONNECTION_STRING": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;TableEndpoint=http://localhost:10002/devstoreaccount1;",
"FUNCTIONS_WORKER_RUNTIME": "node",
"GITHUB_API_USERNAME": "noahspannbauer",
"GITHUB_API_PAT": "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"
},
"Host": {
"CORS": "*"
}
}

View File

@@ -1,17 +0,0 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "{*segments}"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/main/index.js"
}

View File

@@ -1,7 +0,0 @@
import { Context, HttpRequest } from '@azure/functions';
import { AzureHttpAdapter } from '@nestjs/azure-func-http';
import { createApp } from '../src/main.azure';
export default function(context: Context, req: HttpRequest): void {
AzureHttpAdapter.handle(createApp, context, req);
}

View File

@@ -1,3 +0,0 @@
{
"name": "Azure"
}

View File

@@ -17,8 +17,7 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"start:azure": "npm run build && func host start"
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@azure/functions": "^1.0.3",

View File

@@ -1,4 +0,0 @@
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {}
}

View File

@@ -2,10 +2,12 @@ import { Module } from '@nestjs/common';
import { GitHubApiModule } from './github/github.module';
import { APP_FILTER } from '@nestjs/core';
import { HttpExceptionFilter } from './filters/http-exception.filter';
import { ProjectModule } from './project/project.module';
@Module({
imports: [
GitHubApiModule
GitHubApiModule,
ProjectModule
],
providers: [
{

View File

@@ -1,20 +0,0 @@
export interface Content {
name: string
path: string
sha: string
size: number
url: string
html_url: string
git_url: string
download_url: string
type: string
content: string
encoding: string
_links: Links
}
interface Links {
self: string
git: string
html: string
}

View File

@@ -1,120 +0,0 @@
export interface Repo {
id: number
node_id: string
name: string
full_name: string
private: boolean
owner: Owner
html_url: string
description?: string
fork: boolean
url: string
forks_url: string
keys_url: string
collaborators_url: string
teams_url: string
hooks_url: string
issue_events_url: string
events_url: string
assignees_url: string
branches_url: string
tags_url: string
blobs_url: string
git_tags_url: string
git_refs_url: string
trees_url: string
statuses_url: string
languages_url: string
stargazers_url: string
contributors_url: string
subscribers_url: string
subscription_url: string
commits_url: string
git_commits_url: string
comments_url: string
issue_comment_url: string
contents_url: string
compare_url: string
merges_url: string
archive_url: string
downloads_url: string
issues_url: string
pulls_url: string
milestones_url: string
notifications_url: string
labels_url: string
releases_url: string
deployments_url: string
created_at: string
updated_at: string
pushed_at: string
git_url: string
ssh_url: string
clone_url: string
svn_url: string
homepage?: string
size: number
stargazers_count: number
watchers_count: number
language?: string
has_issues: boolean
has_projects: boolean
has_downloads: boolean
has_wiki: boolean
has_pages: boolean
has_discussions: boolean
forks_count: number
mirror_url: any
archived: boolean
disabled: boolean
open_issues_count: number
license?: License
allow_forking: boolean
is_template: boolean
web_commit_signoff_required: boolean
topics: any[]
visibility: string
forks: number
open_issues: number
watchers: number
default_branch: string
permissions: Permissions
}
interface Owner {
login: string
id: number
node_id: string
avatar_url: string
gravatar_id: string
url: string
html_url: string
followers_url: string
following_url: string
gists_url: string
starred_url: string
subscriptions_url: string
organizations_url: string
repos_url: string
events_url: string
received_events_url: string
type: string
user_view_type: string
site_admin: boolean
}
interface License {
key: string
name: string
spdx_id: string
url: string
node_id: string
}
interface Permissions {
admin: boolean
maintain: boolean
push: boolean
triage: boolean
pull: boolean
}

View File

@@ -1,35 +0,0 @@
import { Controller, Get, HttpException, Query } from '@nestjs/common';
import { GitHubApiService } from './github.service';
import { AxiosError } from 'axios'
import { Content } from './github-content.interface';
import { Repo } from './github-repo.interface';
@Controller('github')
export class GitHubApiController {
constructor(private readonly githubApiService: GitHubApiService) {}
@Get('readme')
async getReadMe(@Query() query: any): Promise<Content> {
try {
const repoName = query['repoName'];
return await this.githubApiService.getReadMeContent(repoName)
} catch (error) {
const axiosError = error as AxiosError;
throw new HttpException(axiosError.message, axiosError.status)
}
}
@Get('repos')
async getRepos(): Promise<Repo[]> {
try {
return await this.githubApiService.getRepos();
} catch (error) {
const axiosError = error as AxiosError
throw new HttpException(axiosError.message, axiosError.status)
}
}
}

View File

@@ -1,18 +0,0 @@
import { Module } from '@nestjs/common';
import { GitHubApiController } from './github.controller';
import { GitHubApiService } from './github.service';
import { ConfigModule } from '@nestjs/config';
import configuration from '../config/configuration';
import { HttpModule } from '@nestjs/axios';
@Module({
imports: [
ConfigModule.forRoot({
load: [configuration]
}),
HttpModule
],
controllers: [GitHubApiController],
providers: [GitHubApiService],
})
export class GitHubApiModule {}

View File

@@ -1,39 +0,0 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { HttpService } from '@nestjs/axios';
import { AxiosResponse } from 'axios';
import { Repo } from './github-repo.interface';
import { Content } from './github-content.interface';
@Injectable()
export class GitHubApiService {
constructor(
private readonly configService: ConfigService,
private readonly httpService: HttpService
) {}
async getReadMeContent(repoName: string): Promise<Content> {
const githubApiUsername = this.configService.get<string>('githubApiUsername')
const response: AxiosResponse = await this.httpService.axiosRef.get(`https://api.github.com/repos/${githubApiUsername}/${repoName}/contents/README.md`, {
auth: {
username: this.configService.get<string>('githubApiUsername'),
password: this.configService.get<string>('githubApiPassword')
}
})
const content: Content = response.data
return content;
}
async getRepos(): Promise<Repo[]> {
const response: AxiosResponse = await this.httpService.axiosRef.get('https://api.github.com/user/repos', {
auth: {
username: this.configService.get<string>('githubApiUsername'),
password: this.configService.get<string>('githubApiPassword')
}
})
const repos: Repo[] = response.data
return repos;
}
}

View File

@@ -1,26 +0,0 @@
import { INestApplication, InternalServerErrorException } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpService } from '@nestjs/axios'
import { HttpExceptionFilter } from './filters/http-exception.filter';
export async function createApp(): Promise<INestApplication> {
const httpService = new HttpService();
const app = await NestFactory.create(AppModule);
app.setGlobalPrefix('api');
app.useGlobalFilters(new HttpExceptionFilter());
httpService.axiosRef.interceptors.response.use(
(response) => {
return response;
},
(error) => {
console.error('Internal server error exception', error);
throw new InternalServerErrorException();
}
);
await app.init();
return app;
}

View File

@@ -1,8 +1,26 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpService } from '@nestjs/axios';
import { HttpExceptionFilter } from './filters/http-exception.filter';
import { InternalServerErrorException } from '@nestjs/common';
async function bootstrap() {
const httpService = new HttpService();
const app = await NestFactory.create(AppModule);
app.enableCors();
app.setGlobalPrefix('api');
app.useGlobalFilters(new HttpExceptionFilter());
httpService.axiosRef.interceptors.response.use(
(response) => {
return response;
},
(error) => {
console.error('Internal server error exception', error);
throw new InternalServerErrorException();
}
);
await app.listen(3000);
}

View File

@@ -0,0 +1,92 @@
import {
Body,
Controller,
Delete,
Get,
HttpException,
Param,
Post,
Put
} from '@nestjs/common';
import { ProjectDto } from './project.dto';
import { Project } from './project.entity';
import { ProjectService } from './project.service';
import { CustomError } from '@noahspan/noahspan-modules';
@Controller('projects')
export class ProjectController {
constructor(private readonly projectService: ProjectService) {}
@Get(':partitionKey/:rowKey')
async find(
@Param('partitionKey') partitionKey: string,
@Param('rowKey') rowKey: string
) {
try {
return await this.projectService.find(partitionKey, rowKey);
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
@Get()
async findAll() {
try {
return await this.projectService.findAll();
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
@Post()
async create(@Body() projectDto: ProjectDto) {
try {
const project = new Project();
Object.assign(project, projectDto);
return await this.projectService.create(project);
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
@Put(':partitionKey/:rowKey')
async update(
@Param('partitionKey') partitionKey: string,
@Param('rowKey') rowKey: string,
@Body() projectDto: ProjectDto
) {
try {
const project = new Project();
Object.assign(project, projectDto);
return await this.projectService.update(partitionKey, rowKey, project);
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
@Delete(':partitionKey/:rowKey')
async delete(
@Param('partitionKey') partitionKey: string,
@Param('rowKey') rowKey: string
) {
try {
return await this.projectService.delete(partitionKey, rowKey);
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
}

View File

@@ -0,0 +1,6 @@
export class ProjectDto {
rowKey: string;
displayName: string;
icon: string;
summary: string;
}

View File

@@ -0,0 +1,7 @@
export class Project {
partitionKey: string;
rowKey: string;
displayName: string;
icon: string;
summary: string;
}

View File

@@ -0,0 +1,27 @@
import { Module } from '@nestjs/common';
import { ProjectController } from './project.controller';
import { ProjectService } from './project.service';
import { AzureTableStorageModule } from '@noahspan/azure-database';
import { Project } from './project.entity';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
AzureTableStorageModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
return {
connectionString: configService.get<string>('azureStorageConnectionString')
};
},
inject: [ConfigService]
}),
AzureTableStorageModule.forFeature(Project, {
createTableIfNotExists: true,
table: 'projects'
}),
],
controllers: [ProjectController],
providers: [ProjectService]
})
export class ProjectModule {}

View File

@@ -0,0 +1,38 @@
import { InjectRepository, Repository } from '@noahspan/azure-database';
import { Injectable } from '@nestjs/common';
import { Project } from './project.entity';
import { v4 as uuidv4 } from 'uuid';
@Injectable()
export class ProjectService {
constructor(
@InjectRepository(Project)
private readonly projectRepository: Repository<Project>
) {}
async find(partitionKey: string, rowKey: string): Promise<Project> {
return await this.projectRepository.find(partitionKey, rowKey);
}
async findAll(): Promise<Project[]> {
return await this.projectRepository.findAll();
}
async create(project: Project): Promise<Project> {
project.partitionKey = 'project';
return await this.projectRepository.create(project);
}
async update(
partitionKey: string,
rowKey: string,
project: Project
): Promise<Project> {
return await this.projectRepository.update(partitionKey, rowKey, project);
}
async delete(partitionKey: string, rowKey: string): Promise<void> {
await this.projectRepository.delete(partitionKey, rowKey);
}
}