Skip to content

Commit

Permalink
Widok profilu
Browse files Browse the repository at this point in the history
  • Loading branch information
protectedvoid21 committed Oct 13, 2024
1 parent ead3007 commit e025307
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 61 deletions.
63 changes: 41 additions & 22 deletions src/BHC24.Api/Controllers/ProfileController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BHC24.Api.Models;
using BHC24.Api.Models.Profile;
using BHC24.Api.Models.Projects;
using BHC24.Api.Persistence;
using BHC24.Api.Persistence.Models;
using BHC24.Api.Services;
Expand All @@ -20,7 +21,7 @@ public ProfileController(BhcDbContext dbContext, AuthUserProvider authUser)
_dbContext = dbContext;
_authUser = authUser;
}

[HttpGet("{userId}")]
public async Task<Result<GetProfileResponse>> GetProfileAsync([FromRoute] Guid userId, CancellationToken ct)
{
Expand All @@ -33,23 +34,41 @@ public async Task<Result<GetProfileResponse>> GetProfileAsync([FromRoute] Guid u
ProfilePicture = x.ProfilePicture,
UserCv = x.UserCv,
Description = x.Description,
AppUser = x.AppUser,
Tags = x.Tags
UserName = x.AppUser.Name,
FirstName = x.AppUser.Name,
LastName = x.AppUser.Surname,
Tags = x.Tags.Select(t => new TagResponse
{
Id = t.Id,
Name = t.Name,
ImagePath = t.ImagePath
}
).ToList(),
Projects = x.AppUser.Profile.Projects.Select(p => new GetProjectResponse
{
Title = p.Title,
Description = p.Description,
Owner = p.Owner.AppUser.Name,
OwnerId = p.Owner.AppUserId,
GithubUrl = p.GithubRepositoryUrl,
CollaboratorsCount = p.CollaboratorsCount,
Tags = p.Tags.Select(t => new TagResponse
{
Id = t.Id,
Name = t.Name,
ImagePath = t.ImagePath
}
).ToList(),
}).ToList()
}).FirstOrDefaultAsync(ct);

if (profile.AppUser.Id != (await _authUser.GetAsync()).Id)
{
return Result<GetProfileResponse>.Forbidden<GetProfileResponse>("Forbidden");
}

return Result.Ok(profile);
}

[HttpPost("/create")]
public async Task<Result> CreateProfileAsync([FromBody] CreateProfileRequest request, CancellationToken ct)
{
var user = await _authUser.GetAsync();

var profile = new Profile
{
GithubAccountUrl = request.GithubAccountUrl,
Expand All @@ -60,13 +79,13 @@ public async Task<Result> CreateProfileAsync([FromBody] CreateProfileRequest req
AppUserId = user.Id,
Tags = request.Tags
};

_dbContext.Profiles.Add(profile);
await _dbContext.SaveChangesAsync(ct);

return Result.Ok();
}

[HttpPut("{userId}")]
public async Task<Result> UpdateProfileAsync([FromRoute] Guid userId, [FromBody] UpdateProfileRequest request, CancellationToken ct)
{
Expand All @@ -77,11 +96,11 @@ public async Task<Result> UpdateProfileAsync([FromRoute] Guid userId, [FromBody]

var tagsToAdd = new List<Tag>();
tagsToAdd.AddRange(request.Tags);

var all_tags = await _dbContext.Profiles.Where(x => x.AppUserId == userId).SelectMany(x => x.Tags).ToListAsync(ct);

tagsToAdd.AddRange(all_tags);

var profile = await _dbContext.Profiles
.Where(p => p.AppUserId == userId)
.ExecuteUpdateAsync(b =>
Expand All @@ -91,10 +110,10 @@ public async Task<Result> UpdateProfileAsync([FromRoute] Guid userId, [FromBody]
.SetProperty(p => p.UserCv, request.UserCv)
.SetProperty(p => p.Description, request.Description)
.SetProperty(p => p.Tags, tagsToAdd.Distinct()), ct);

return Result.Ok();
}

[HttpDelete("{userId}")]
public async Task<IActionResult> DeleteProfileAsync([FromRoute] Guid userId, CancellationToken ct)
{
Expand All @@ -106,15 +125,15 @@ public async Task<IActionResult> DeleteProfileAsync([FromRoute] Guid userId, Can
var profile = await _dbContext.Profiles
.Where(p => p.AppUserId == userId)
.SingleOrDefaultAsync(ct);

if (profile == null)
{
return NotFound();
}

_dbContext.Profiles.Remove(profile);
await _dbContext.SaveChangesAsync(ct);

return Ok();
}
}
1 change: 1 addition & 0 deletions src/BHC24.Api/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public async Task<Result<PaginationResponse<GetProjectResponse>>> GetList([FromQ
Title = p.Title,
Description = p.Description,
Owner = p.Owner.AppUser.UserName,
OwnerId = p.Owner.AppUserId,
GithubUrl = p.GithubRepositoryUrl,
CollaboratorsCount = p.CollaboratorsCount,
Tags = p.Tags.Select(t => new TagResponse
Expand Down
1 change: 1 addition & 0 deletions src/BHC24.Api/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public async Task<Result<PaginationResponse<GetProjectResponse>>> SearchProjects
Title = p.Title,
Description = p.Description,
Owner = p.Owner.AppUser.UserName,
OwnerId = p.Owner.AppUserId,
GithubUrl = p.GithubRepositoryUrl,
Tags = p.Tags.Select(t => new TagResponse
{
Expand Down
9 changes: 7 additions & 2 deletions src/BHC24.Api/Models/Profile/GetProfileResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using BHC24.Api.Models.Projects;
using BHC24.Api.Persistence.Models;

namespace BHC24.Api.Models.Profile;
Expand All @@ -10,6 +11,10 @@ public class GetProfileResponse
public byte[]? UserCv { get; set; }
public string? Description { get; set; }

public AppUser AppUser { get; set; }
public ICollection<Tag>? Tags { get; set; }
public required string FirstName { get; set; }
public required string LastName { get; set; }

public required string UserName { get; set; }
public ICollection<TagResponse>? Tags { get; set; }
public ICollection<GetProjectResponse> Projects { get; set; }
}
1 change: 1 addition & 0 deletions src/BHC24.Api/Models/Projects/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public record GetProjectResponse
public string Title { get; init; }
public string Description { get; init; }
public string Owner { get; init; }
public Guid OwnerId { get; init; }
public string GithubUrl { get; init; }
public int CollaboratorsCount { get; init; }
public IEnumerable<TagResponse> Tags { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion src/BHC24.Client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const router = createBrowserRouter([
]
},
{
path: 'profile',
path: 'profile/:id',
element: <ProfilePage/>
},
{
Expand Down
18 changes: 18 additions & 0 deletions src/BHC24.Client/src/components/ProjectItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { GetProjectResponse } from "../utils/models";
import { Divider } from "./Divider/Divider";
import { TagBlock } from "./TagBlock/TagBlock";

export const ProjectItem = ({ project }: { project: GetProjectResponse }) => (
<div key={project.title} style={{ marginBlock: '1rem' }}>
<h3 style={{ color: 'var(--color-text)' }}>{project.title}</h3>
<p>{project.description}</p>
<p>Właściciel: <a href={'profile/' + project.ownerId} style={{ textDecoration: 'underline' }}>{project.owner}</a></p>
<p>Współpracownicy: {project.collaboratorsCount}</p>
<div style={{ display: 'flex', gap: '0.5rem', marginBlock: '1rem' }}>
{project.tags.map(tag => (
<TagBlock key={tag.name} tag={tag} />
))}
</div>
<Divider />
</div>
)
16 changes: 16 additions & 0 deletions src/BHC24.Client/src/components/TagBlock/TagBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { GetTagResponse } from "../../utils/models";

export const TagBlock = ({ tag }: { tag: GetTagResponse }) => (
<div style={{
width: '5rem',
height: '5rem',
padding: '0.5rem',
backgroundColor: 'white',
borderRadius: '15%',
cursor: 'pointer',
userSelect: 'none',

}}>
<img src={tag.imagePath} draggable='false' style={{ width: '100%', height: '100%' }} />
</div>
);
66 changes: 48 additions & 18 deletions src/BHC24.Client/src/pages/Profile/ProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,79 @@
import AnimatedMain from "../../components/AnimatedComps/AnimatedMain";
import styles from "./ProfilePage.module.css";
import myImg from "../../assets/pic.jpg";
import { useParams } from "react-router-dom";
import { useGetProfile } from "../../hooks/useGetProfile";
import { TagBlock } from "../../components/TagBlock/TagBlock";
import { Divider } from "../../components/Divider/Divider";
import { ProjectItem } from "../../components/ProjectItem";

export function ProfilePage() {
const params = useParams<{ id: string }>();

const { data: profile, isLoading, error } = useGetProfile(params.id!);

const UserSection = () => {
return (
<section>
<div className={styles.userHeader}>
<img src={myImg} className={styles.userImage}/>
<img src={myImg} className={styles.userImage} />
<div className={styles.userName} style={{ fontSize: '2.5rem' }}>
<h2 >Nazwa użytkownika</h2>
<p style={{ textAlign: 'center', fontSize: '1.25rem' }}>@nazwa_identyfikacyjna</p>
<h2 >{profile?.data?.firstName} {profile?.data?.lastName}</h2>
<p style={{ textAlign: 'center', fontSize: '1.25rem' }}>@{profile?.data?.userName}</p>
</div>
</div>

<div style={{ fontSize: 24, marginTop: '4rem' }}>
Opis użytkownika: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum laoreet ligula in porttitor congue. Sed euismod lectus et feugiat porta.
Proin finibus mauris ac mauris rutrum venenatis. Ut gravida condimentum accumsan.
Etiam congue nulla pellentesque lobortis dignissim. Maecenas nec nisi in nisi hendrerit aliquam.
Pellentesque placerat vitae lectus id ullamcorper.
Opis użytkownika: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum laoreet ligula in porttitor congue. Sed euismod lectus et feugiat porta.
Proin finibus mauris ac mauris rutrum venenatis. Ut gravida condimentum accumsan.
Etiam congue nulla pellentesque lobortis dignissim. Maecenas nec nisi in nisi hendrerit aliquam.
Pellentesque placerat vitae lectus id ullamcorper.
</div>
</section>
)
}

const Skills = () => {
const SkillsSection = () => {
return (
<section>
<h3>Umiejętności</h3>
<div>
<span>HTML</span>
<span>CSS</span>
<span>JavaScript</span>
<span>React</span>
<span>Node.js</span>
<h2 style={{ marginBottom: '0.5rem' }}>Umiejętności</h2>
<Divider />
<div style={{ display: 'flex', justifyContent: 'center', gap: '1rem', marginBlock: '2rem', flexWrap: 'wrap' }}>
{profile?.data?.tags.map(tag => (
<TagBlock key={tag.id} tag={tag} />
))}
</div>
</div>
</section>
);
)
}

const ProjectsSection = () => {
return (
<section>
<div>
<h2 style={{ marginBottom: '0.5rem' }}>Projekty</h2>
<Divider />
<div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', gap: '1rem', marginBlock: '2rem', flexWrap: 'wrap' }}>
{profile?.data?.projects.map(project => (
<ProjectItem key={project.title} project={project} />
))}
</div>
</div>
</section>
)
}

return (
<AnimatedMain>
<UserSection />
<Skills />
<>
{isLoading && <p>Loading...</p>}
<UserSection />
<SkillsSection />
<ProjectsSection />
</>
</AnimatedMain>
)
}
23 changes: 6 additions & 17 deletions src/BHC24.Client/src/pages/ProjectSearch/ProjectSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {GetTagResponse, PaginationRequest} from "../../utils/models";
import {isLastPage} from "../../utils/helpers";
import styles from './ProjectSearch.module.css';
import {useGetTags as useGetTags} from "../../hooks/useGetTags";
import { ProjectItem } from "../../components/ProjectItem";
import AnimatedDiv from "../../components/AnimatedComps/AnimatedDiv.tsx";
import {AnimatePresence} from "framer-motion";

Expand Down Expand Up @@ -48,19 +49,7 @@ export function ProjectSearch() {
{isLoading && searchQuery !== '' && <p>Loading...</p>}
{error && <p>Error: {error.message}</p>}
{projects && searchQuery !== '' && projects.data?.data.map((project, index) => (
<div key={index} style={{marginBlock: '1rem'}}>
<h3 style={{color: 'var(--color-text)'}}>{project.title}</h3>
<p>{project.description}</p>

<p>Właściciel: <a href='#' style={{ textDecoration: 'underline' }}>{project.owner}</a></p>
<p>Współpracownicy: {project.collaboratorsCount}</p>
<div style={{ display: 'flex', gap: '0.5rem', marginBlock: '1rem' }}>
{project.tags.map(tag => (
<TagBlock key={tag.name} tag={tag} />
))}
</div>
<Divider />
</div>
<ProjectItem key={index} project={project} />
))}
</div>
);
Expand Down Expand Up @@ -129,10 +118,10 @@ export function ProjectSearch() {
))}
</div>
</div>
{/*<div>*/}
{/* <label>Właściciel</label>*/}
{/* <input type="text" id="ownerName" onChange={(e) => setOwnerName(e.target.value)}/>*/}
{/*</div>*/}
<div style={{ marginBlock: '2rem' }}>
<label>Właściciel</label>
<input type="text" id="ownerName" onChange={(e) => setOwnerName(e.target.value)}/>
</div>
{/*<div>*/}
{/* <label>Współpracownicy</label>*/}
{/* <input type="text" id="collaborators"/>*/}
Expand Down
7 changes: 6 additions & 1 deletion src/BHC24.Client/src/utils/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export type GetProfileResponse = {
profilePicture: string;
userCv: string;
description: string;
appUser: UserModel;
firstName: string;
lastName: string;
userName: string;
projects: GetProjectResponse[];
tags: GetTagResponse[];
}

export type PaginationRequest = {
Expand All @@ -54,6 +58,7 @@ export type GetProjectResponse = {
title: string;
description: string;
owner: string;
ownerId: string;
collaboratorsCount: number;
collaborators: string[];
tags: GetTagResponse[];
Expand Down

0 comments on commit e025307

Please sign in to comment.