Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion PoZiomkaApp/src/app/admin/forms/forms.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h1 class="col">Lista Ankiet</h1>
<hr class="mb-5">
<div class="p-3 d-flex flex-column">
@for (form of forms(); track form.id) {
<div class="btn btn-light border p-3 m-2 rounded-2" (click)="onFormClick(form.id)">
<div class="btn btn-light border py-4 m-2 rounded-2 shadow" (click)="onFormClick(form.id)">
<h5 class="m-0">{{ form.title }}</h5>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h4>Studenci do przypisania:</h4>
<td>{{ student.phoneNumber ?? "-" }}</td>
<td>{{ student.indexNumber ?? "-" }}</td>
<td>
<app-loading-button [class]="'btn-sm btn-success mx-2 border-0'" (clicked)="onStudentAdd($index)" [isLoading]="isAdding()[$index]" [isDisabled]="room()?.capacity == room()?.students?.length">
<app-loading-button [class]="'btn-sm btn-success mx-2 border-0'" (clicked)="onStudentAdd($index)" [isLoading]="isAdding()[$index]" [isDisabled]="room()?.status == RoomStatus.Full || room()?.status == RoomStatus.Reserved">
<i class="bi bi-plus-lg"></i>
</app-loading-button>
</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, computed, effect, inject, input, output, signal } from '@angular/core';
import { PopupComponent } from '../../../common/popup/popup.component';
import { roomStatusToColorString, roomStatusToString, RoomStudentModel } from '../room.model';
import { RoomStatus, roomStatusToColorString, roomStatusToString, RoomStudentModel } from '../room.model';
import { CommonModule } from '@angular/common';
import { LoadingButtonComponent } from '../../../common/loading-button/loading-button.component';
import { StudentModel } from '../../../student/student.model';
Expand Down Expand Up @@ -40,6 +40,7 @@ export class RoomDetailsComponent {
otherStudent.lastName?.startsWith(this.lastName()))
);

RoomStatus = RoomStatus;
roomStatusToString = roomStatusToString;
roomStatusToColorString = roomStatusToColorString;

Expand Down
4 changes: 3 additions & 1 deletion PoZiomkaApp/src/app/admin/rooms/room.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export type RoomModel = {
floor: number,
number: number,
capacity: number,
studentCount: number,
reservationId?: number,
studentIds: number[],
status: RoomStatus
}

Expand All @@ -19,6 +19,8 @@ export type RoomStudentModel = {
floor: number,
number: number,
capacity: number,
studentCount: number,
reservationId?: number,
students: StudentModel[],
status: RoomStatus
}
Expand Down
2 changes: 1 addition & 1 deletion PoZiomkaApp/src/app/admin/rooms/rooms.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h4 class="card-title">
Piętro: {{ room.floor }}
</h4>
<h6 class="card-text">
Zajęte Miejsca: {{ room.studentIds.length }}/{{ room.capacity }}
Zajęte Miejsca: {{ room.studentCount }}/{{ room.capacity }}
</h6>
</div>
<div class="card-footer bg-opacity-25"
Expand Down
1 change: 0 additions & 1 deletion PoZiomkaDomain/Admin/IAdminRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ namespace PoZiomkaDomain.Admin;
public interface IAdminRepository
{
public Task<AdminModel> GetAdminByEmail(string email, CancellationToken? cancellationToken);

public Task<AdminModel> GetAdminById(int id, CancellationToken? cancellationToken);
}
1 change: 0 additions & 1 deletion PoZiomkaDomain/Form/IFormRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ public interface IFormRepository
Task UpdateForm(FormUpdate form, CancellationToken? cancellationToken);
Task DeleteForm(int id, CancellationToken? cancellationToken);
}

12 changes: 3 additions & 9 deletions PoZiomkaDomain/Match/IJudgeService.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using PoZiomkaDomain.Match.Dtos;
using PoZiomkaDomain.Reservation.Dtos;
using PoZiomkaDomain.Student.Dtos;
using PoZiomkaDomain.StudentAnswers.Dtos;

namespace PoZiomkaDomain.Match;
namespace PoZiomkaDomain.Match;

public interface IJudgeService
{
public Task<IEnumerable<MatchModel>> FindMatching(IEnumerable<StudentModel> students, IEnumerable<StudentAnswerDisplay> studentAnswers);
public Task<IEnumerable<ReservationModel>> GenerateReservations(IEnumerable<MatchModel> matches, CancellationToken? cancellationToken);
public Task<bool> IsMatch(int studentId, int otherStudentId);
public Task FindMatching(CancellationToken? cancellationToken);
public Task GenerateReservations(CancellationToken? cancellationToken);
}
3 changes: 1 addition & 2 deletions PoZiomkaDomain/Match/IMatchRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ public interface IMatchRepository
{
Task<IEnumerable<MatchModel>> GetStudentMatches(int studentId);
Task UpdateMatch(int matchId, int studentId, MatchStatus status);

Task<MatchModel> CreateMatch(int studentId1, int studentId2);
Task<bool> IsMatch(int studentId1, int studentId2);
}
1 change: 0 additions & 1 deletion PoZiomkaDomain/Reservation/IReservationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public interface IReservationRepository
{
public Task<IEnumerable<ReservationModel>> GetAllReservations(CancellationToken? cancellationToken);
public Task<ReservationDisplay> GetReservationDisplay(int id, CancellationToken? cancellationToken);
public Task<ReservationModel> CreateRoomReservation(int id, CancellationToken? cancellationToken);
public Task UpdateReservation(int id, bool isAcceptation, CancellationToken? cancellationToken);
public Task UpdateStudentReservation(int id, int studentId, bool isAcceptation, CancellationToken? cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task Handle(AddStudentCommand request, CancellationToken cancellati
throw new StudentAlreadyInRoomException("Student is already in a room");
}

RoomModel room;
RoomDisplay room;
try
{
room = await roomRepository.GetRoomById(request.Id, cancellationToken);
Expand All @@ -45,6 +45,6 @@ public async Task Handle(AddStudentCommand request, CancellationToken cancellati
throw new RoomFullException("Trying to add a student to full room");
}

await studentRepository.UpdateRoom(request.StudentId, request.Id);
await roomRepository.AddStudent(request.Id, request.StudentId, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace PoZiomkaDomain.Room.Commands.RemoveStudent;

public class RemoveStudentCommandHandler(IStudentRepository studentRepository) : IRequestHandler<RemoveStudentCommand>
public class RemoveStudentCommandHandler(IStudentRepository studentRepository, IRoomRepository roomRepository) : IRequestHandler<RemoveStudentCommand>
{
public async Task Handle(RemoveStudentCommand request, CancellationToken cancellationToken)
{
Expand All @@ -26,6 +26,6 @@ public async Task Handle(RemoveStudentCommand request, CancellationToken cancell
throw new StudentNotAssignedToRoomException("Student not assigned to this room");
}

await studentRepository.UpdateRoom(request.StudentId, null);
await roomRepository.RemoveStudent(request.Id, request.StudentId, cancellationToken);
}
}
8 changes: 5 additions & 3 deletions PoZiomkaDomain/Room/Dtos/RoomDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ public enum RoomStatus
Available, Reserved, Occupied, Full
}

public record RoomDisplay(int Id, int Floor, int Number, int Capacity, int? ReservationId, IEnumerable<int> StudentIds)
public record RoomDisplay(int Id, int Floor, int Number, int Capacity, int StudentCount, int? ReservationId)
{
public RoomStatus Status => ReservationId is not null ? RoomStatus.Reserved :
!StudentIds.Any() ? RoomStatus.Available : StudentIds.Count() == Capacity ? RoomStatus.Full : RoomStatus.Occupied;
public RoomStatus Status
{
get => ReservationId is not null ? RoomStatus.Reserved : StudentCount == 0 ? RoomStatus.Available : StudentCount == Capacity ? RoomStatus.Full : RoomStatus.Occupied;
}
};
2 changes: 1 addition & 1 deletion PoZiomkaDomain/Room/Dtos/RoomModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace PoZiomkaDomain.Room.Dtos;

public record RoomModel(int Id, int Floor, int Number, int Capacity);
public record RoomModel(int Id, int Floor, int Number, int Capacity, int StudentCount);
7 changes: 3 additions & 4 deletions PoZiomkaDomain/Room/Dtos/RoomStudentDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace PoZiomkaDomain.Room.Dtos;

public record RoomStudentDisplay(int Id, int Floor, int Number, int Capacity, int? ReservationId, IEnumerable<StudentDisplay> Students)
public record RoomStudentDisplay(int Id, int Floor, int Number, int Capacity, int StudentCount, int? ReservationId, IEnumerable<StudentDisplay> Students)
: RoomDisplay(Id, Floor, Number, Capacity, StudentCount, ReservationId)
{
public RoomStatus Status => ReservationId is not null ? RoomStatus.Reserved :
!Students.Any() ? RoomStatus.Available : Students.Count() == Capacity ? RoomStatus.Full : RoomStatus.Occupied;
}
}
3 changes: 0 additions & 3 deletions PoZiomkaDomain/Room/Dtos/RoomStudentModel.cs

This file was deleted.

7 changes: 4 additions & 3 deletions PoZiomkaDomain/Room/IRoomRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class RoomNumberNotUniqueException : Exception;
public interface IRoomRepository
{
public Task CreateRoom(RoomCreate roomCreate, CancellationToken? cancellationToken);
public Task<RoomModel> GetRoomById(int id, CancellationToken? cancellationToken);
public Task<IEnumerable<RoomModel>> GetAllRooms(CancellationToken? cancellationToken);
public Task<RoomDisplay> GetRoomById(int id, CancellationToken? cancellationToken);
public Task<IEnumerable<RoomDisplay>> GetAllRooms(CancellationToken? cancellationToken);
public Task DeleteRoom(int id, CancellationToken? cancellationToken);
public Task<IEnumerable<RoomModel>> GetEmptyRooms();
public Task RemoveStudent(int id, int studentId, CancellationToken? cancellationToken);
public Task AddStudent(int id, int studentId, CancellationToken? cancellationToken);
}
16 changes: 2 additions & 14 deletions PoZiomkaDomain/Room/Queries/GetAllRooms/GetAllRoomsQueryHandler.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
using MediatR;
using PoZiomkaDomain.Room.Dtos;
using PoZiomkaDomain.Student;

namespace PoZiomkaDomain.Room.Queries.GetAllRooms;

public class GetAllRoomsQueryHandler(IRoomRepository roomRepository, IStudentRepository studentRepository) : IRequestHandler<GetAllRoomsQuery, IEnumerable<RoomDisplay>>
public class GetAllRoomsQueryHandler(IRoomRepository roomRepository) : IRequestHandler<GetAllRoomsQuery, IEnumerable<RoomDisplay>>
{
public async Task<IEnumerable<RoomDisplay>> Handle(GetAllRoomsQuery request, CancellationToken cancellationToken)
{
var rooms = await roomRepository.GetAllRooms(cancellationToken);

List<RoomDisplay> list = [];

foreach (var room in rooms)
{
var students = await studentRepository.GetStudentIdsByRoomId(room.Id, cancellationToken);
var roomDisplay = new RoomDisplay(room.Id, room.Floor, room.Number, room.Capacity,
null, students);
list.Add(roomDisplay);
}
return list;
return await roomRepository.GetAllRooms(cancellationToken);
}
}
4 changes: 2 additions & 2 deletions PoZiomkaDomain/Room/Queries/GetRoom/GetRoomQueryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<RoomStudentDisplay> Handle(GetRoomQuery request, CancellationT
if (!isUserAuthorized)
throw new UnauthorizedException("User must be logged in as an administrator or a student that is assigned to the room");

RoomModel room;
RoomDisplay room;
try
{
room = await roomRepository.GetRoomById(request.Id, cancellationToken);
Expand All @@ -43,7 +43,7 @@ public async Task<RoomStudentDisplay> Handle(GetRoomQuery request, CancellationT

var hidePersonalInfo = !(request.User.IsInRole(Roles.Administrator));

var roomStudentDisplay = new RoomStudentDisplay(room.Id, room.Floor, room.Number, room.Capacity, null, students.Select(x => x.ToStudentDisplay(hidePersonalInfo)));
var roomStudentDisplay = new RoomStudentDisplay(room.Id, room.Floor, room.Number, room.Capacity, room.StudentCount, room.ReservationId, students.Select(x => x.ToStudentDisplay(hidePersonalInfo)));

return roomStudentDisplay;
}
Expand Down
2 changes: 0 additions & 2 deletions PoZiomkaDomain/Student/IStudentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ public interface IStudentRepository
public Task<StudentModel> GetStudentById(int id, CancellationToken? cancellationToken);
public Task<StudentModel> GetStudentByEmail(string email, CancellationToken? cancellationToken);
public Task<IEnumerable<StudentModel>> GetStudentsByRoomId(int roomId, CancellationToken? cancellationToken);
public Task<IEnumerable<int>> GetStudentIdsByRoomId(int roomId, CancellationToken? cancellationToken);
public Task<IEnumerable<StudentModel>> GetAllStudents(CancellationToken? cancellationToken);
public Task CreateStudent(StudentCreate studentCreate, CancellationToken? cancellationToken);
public Task UpdateStudent(StudentUpdate studentEdit, CancellationToken? cancellationToken);
public Task UpdateReservation(int studentId, int reservationId, bool? HasAccepted, CancellationToken? cancellationToken);
public Task ConfirmStudent(StudentConfirm studentConfirm, CancellationToken? cancellationToken);
public Task DeleteStudent(int id, CancellationToken? cancellationToken);
public Task UpdatePassword(PasswordUpdate passwordUpdate, CancellationToken? cancellationToken);
public Task UpdateRoom(int id, int? roomId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace PoZiomkaDomain.Student.Queries.GetStudent;

public class GetStudentQueryHandler(IStudentRepository studentRepository, IJudgeService judgeService) : IRequestHandler<GetStudentQuery, StudentDisplay>
public class GetStudentQueryHandler(IStudentRepository studentRepository, IMatchRepository matchRepository) : IRequestHandler<GetStudentQuery, StudentDisplay>
{
public async Task<StudentDisplay> Handle(GetStudentQuery request, CancellationToken cancellationToken)
{
Expand All @@ -16,7 +16,7 @@ public async Task<StudentDisplay> Handle(GetStudentQuery request, CancellationTo

bool isUserAuthorized = request.User.IsInRole(Roles.Administrator) ||
request.User.IsInRole(Roles.Student) &&
(loggedInUserId == userId || await judgeService.IsMatch(loggedInUserId, userId));
(loggedInUserId == userId || await matchRepository.IsMatch(loggedInUserId, userId));

if (!isUserAuthorized)
throw new UnauthorizedException("User must be logged in as an administrator or a student that has a match with the student");
Expand Down
19 changes: 17 additions & 2 deletions PoZiomkaDomain/StudentAnswers/Dtos/StudentAnswerDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PoZiomkaDomain.Form.Dtos;
using System.Text.Json.Serialization;

namespace PoZiomkaDomain.StudentAnswers.Dtos;

Expand All @@ -15,10 +16,24 @@ public StudentAnswerDisplay HideAnswers()
}
}

public record StudentAnswerStatus(int? Id, FormModel Form, FormStatus Status)
public class StudentAnswerStatus
{
public int? Id { get; set; }
public FormModel Form { get; set; }
public FormStatus Status { get; set; }

[JsonConstructor]
public StudentAnswerStatus(int? id, FormModel form, FormStatus status)
{
Id = id;
Form = form;
Status = status;
}

public StudentAnswerStatus(int? id, int formId, string title, FormStatus status)
: this(id, new FormModel(formId, title), status)
{
Id = id;
Form = new FormModel(formId, title);
Status = status;
}
}
4 changes: 0 additions & 4 deletions PoZiomkaDomain/StudentAnswers/IStudentAnswerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace PoZiomkaDomain.StudentAnswers;

public interface IStudentAnswerRepository
{

Task<IEnumerable<StudentAnswerStatus>> GetStudentFormAnswerStatus(int studentId, CancellationToken? cancellationToken);
Task<StudentAnswerDisplay> GetStudentAnswer(int formId, int studentId, CancellationToken? cancellationToken);
Task CreateAnswer(int studentId, int FormId, FormStatus status,
Expand All @@ -15,9 +14,6 @@ Task UpdateAnswer(int studentId, int FormId, FormStatus status,
IEnumerable<(string Name, bool IsHidden)> ChoosableAnswers,
IEnumerable<(int ObligatoryPreferenceId, int ObligatoryPreferenceOptionId, bool IsHidden)> ObligatoryAnswers,
CancellationToken? cancellationToken);
Task DeleteAnswer(int formId, int studentId, CancellationToken? cancellationToken);
Task DeleteAnswer(int answerId, CancellationToken? cancellationToken);

Task<IEnumerable<StudentAnswerModel>> GetStudentAnswerModels(int studentId, CancellationToken? cancellationToken);
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
using PoZiomkaDomain.StudentAnswers.Dtos;

namespace PoZiomkaDomain.StudentAnswers.Queries.GetAnswer;
public class GetAnswerQueryHandler(IStudentAnswerRepository studentAnswerRepository, IJudgeService judgeService) : IRequestHandler<GetAnswerQuery, StudentAnswerDisplay>
public class GetAnswerQueryHandler(IStudentAnswerRepository studentAnswerRepository, IMatchRepository matchRepository) : IRequestHandler<GetAnswerQuery, StudentAnswerDisplay>
{
public async Task<StudentAnswerDisplay> Handle(GetAnswerQuery request, CancellationToken cancellationToken)
{
int studentId = request.user.GetUserId() ?? throw new DomainException("Id of the user isn't known");

bool authorized = false;
if (await judgeService.IsMatch(studentId, request.studentId))
if (await matchRepository.IsMatch(studentId, request.studentId))
{
authorized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace PoZiomkaDomain.StudentAnswers.Queries.GetStudent;

public class GetStudentAnswersQueryHandler(IStudentRepository studentRepository, IJudgeService judgeService, IStudentAnswerRepository studentAnswerRepository) : IRequestHandler<GetStudentAnswersQuery, IEnumerable<StudentAnswerStatus>>
public class GetStudentAnswersQueryHandler(IStudentRepository studentRepository, IMatchRepository matchRepository, IStudentAnswerRepository studentAnswerRepository) : IRequestHandler<GetStudentAnswersQuery, IEnumerable<StudentAnswerStatus>>
{
public async Task<IEnumerable<StudentAnswerStatus>> Handle(GetStudentAnswersQuery request, CancellationToken cancellationToken)
{
Expand All @@ -19,9 +19,9 @@ public async Task<IEnumerable<StudentAnswerStatus>> Handle(GetStudentAnswersQuer
if (studentId == request.StudentId && !student.ToStudentDisplay(false).CanFillForms)
throw new UserCanNotFillFormException("Student can not fill form");

if (studentId != request.StudentId && !await judgeService.IsMatch(studentId, request.StudentId))
if (studentId != request.StudentId && !await matchRepository.IsMatch(studentId, request.StudentId))
throw new UnauthorizedException("User must be logged in as an administrator or a student that has a match with the student");

return await studentAnswerRepository.GetStudentFormAnswerStatus(request.StudentId, cancellationToken);
var a = await studentAnswerRepository.GetStudentFormAnswerStatus(request.StudentId, cancellationToken);
return a;
}
}
Loading