Skip to content

Commit

Permalink
fix: prettier error and missing endpoints (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-d-hidalgo authored May 14, 2024
1 parent 4379515 commit 752cd8e
Show file tree
Hide file tree
Showing 10 changed files with 1,186 additions and 900 deletions.
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"arrowParens": "always",
"tabWidth": 2,
"endOfLine": "auto",
"importOrderParserPlugins": ["typescript", "decorators-legacy"],
"importOrder": ["<THIRD_PARTY_MODULES>", "^@bundly/*", "^[./]"],
"importOrder": ["<THIRD_PARTY_MODULES>", "^@bundly/*", "^@app/*", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"]
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [0.2.1] - 2024-06-14

# Added

- Update Ares Dependencies

# Fixed

- Missing endpoints
- Prettier error

## [0.2.0] - 2024-06-07

### Added
Expand Down
8 changes: 7 additions & 1 deletion backend/database/entities/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export class UserEntity extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;

@Column({ type: "text", unique: true })
@Column({ type: "text", nullable: false, unique: true, readonly: true })
principal: string;

@Column({ type: "text", nullable: false, unique: true })
username: string;

@Column({ type: "text", nullable: false, unique: true })
bio: string;
}
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/node": "^20.12.10",
"@types/node": "^20.12.12",
"@types/sql.js": "^1.4.9"
}
}
29 changes: 27 additions & 2 deletions backend/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ export function CreateServer({ database }: CreateServerOptions) {
res.json(users);
});

app.get("/users/me", AuthGuard, async (req, res) => {
try {
const dataSource = await database.getDataSource();
const userRepository = dataSource.getRepository(UserEntity);
const user = await userRepository.findOneBy({ principal: ic.caller().toString() });

if (!user) {
res.status(404);
res.send("User not found.");
} else {
res.json(user);
}
} catch (error: any) {
res.status(400);
res.send(error.message);
}
});

app.get("/users/:id", async (req, res) => {
try {
const dataSource = await database.getDataSource();
Expand All @@ -58,11 +76,18 @@ export function CreateServer({ database }: CreateServerOptions) {
}
});

app.post("/users", async (req: Request, res) => {
app.post("/users", AuthGuard, async (req: Request, res) => {
try {
const dataSource = await database.getDataSource();
const userRepository = dataSource.getRepository(UserEntity);
const user = await userRepository.save(req.body);

const newUser = {
principal: ic.caller().toString(),
username: req.body.username,
bio: req.body.bio,
};

const user = await userRepository.save(newUser);
res.json(user);
} catch (error: any) {
res.status(400);
Expand Down
8 changes: 4 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"clean": "rm -rf .next && rm -rf .turbo && rm -rf build && rm -rf node_modules"
},
"dependencies": {
"@bundly/ares-core": "^0.1.1-beta.0",
"@bundly/ares-react": "^0.1.1-beta.0",
"@bundly/ares-core": "^0.2.0-beta.10",
"@bundly/ares-react": "^0.2.0-beta.9",
"@dfinity/agent": "^1.3.0",
"next": "14.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/node": "^20.12.8",
"@types/react": "^18.3.1",
"@types/node": "^20.12.11",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.19",
"eslint": "^8.57.0",
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/components/header.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { AuthButton } from "@bundly/ares-react";
import { InternetIdentityButton, LogoutButton, useAuth } from "@bundly/ares-react";

export default function Header() {
const { isAuthenticated, currentIdentity } = useAuth();

return (
<header className="bg-white">
<nav className="mx-auto flex max-w-7xl items-center justify-between p-6 lg:px-8" aria-label="Global">
<div className="flex lg:flex-1">
<a href="#" className="-m-1.5 p-1.5">
<span className="sr-only">Your Company</span>
<img
className="h-8 w-auto"
src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=600"
alt=""
/>
<span className="sr-only">Ares Connect</span>
</a>
</div>
<div className="lg:flex lg:gap-x-12"></div>
<div className="lg:flex lg:flex-1 lg:justify-end">
<AuthButton />
{isAuthenticated ? (
<LogoutButton identity={currentIdentity} />
) : (
<InternetIdentityButton>Login</InternetIdentityButton>
)}
</div>
</nav>
</header>
Expand Down
Loading

0 comments on commit 752cd8e

Please sign in to comment.