Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…nto dev
  • Loading branch information
ttthanhf committed Nov 12, 2023
2 parents 5f9c33b + 07727ff commit ce4a6c4
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ src/main/resources/*.json
**/src/test/
nbactions.xml
nb-configuration.xml
bin/
7 changes: 0 additions & 7 deletions src/main/java/housemate/constants/Enum.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ public static enum ServiceField {
private String fieldName;
}


public enum AccountStatus {
ACTIVE,
INACTIVE,
BANNED;
}

public enum TaskStatus {
PENDING_APPLICATION,//waiting for staff apply apply for job
PENDING_WORKING,//found staff - waiting for staff coming
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/housemate/entities/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.hibernate.annotations.Where;

import housemate.constants.Enum.AccountStatus;
import housemate.constants.AccountStatus;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -36,7 +36,5 @@ public class Customer {
@Column(name = "account_status")
@Enumerated(EnumType.STRING)
private AccountStatus accountStatus;

@Column(name = "is_banned")
private boolean isBanned;

}
7 changes: 1 addition & 6 deletions src/main/java/housemate/entities/Staff.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package housemate.entities;

import housemate.constants.Role;

import org.hibernate.annotations.Where;

import housemate.constants.Enum.AccountStatus;
import housemate.constants.AccountStatus;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -43,8 +41,5 @@ public class Staff {
@Enumerated(EnumType.STRING)
private AccountStatus accountStatus;

@Column(name = "is_banned")
private boolean isBanned;


}
3 changes: 0 additions & 3 deletions src/main/java/housemate/entities/UserAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public class UserAccount {
@Enumerated(EnumType.STRING)
private AccountStatus accountStatus = AccountStatus.ACTIVE; // Default: active

@Column(name = "is_banned")
private boolean isBanned = false; // Default isBanned is false

@Column(name = "created_at")
private LocalDateTime createdAt = LocalDateTime.now();

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/housemate/services/AccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
Expand Down Expand Up @@ -100,7 +99,7 @@ public ResponseEntity<String> ban(HttpServletRequest request, int userId) {
}

// Change isBanned to true
account.setBanned(true);
account.setAccountStatus(AccountStatus.BANNED);
userRepository.save(account);
return ResponseEntity.status(HttpStatus.OK).body("Deleted successfully!");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/housemate/services/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ResponseEntity<String> login(LoginAccountDTO loginAccountDTO) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("This email haven't been created");
}

if (accountDB.isBanned() || accountDB.getAccountStatus().equals(AccountStatus.INACTIVE)) {
if (accountDB.getAccountStatus().equals(AccountStatus.BANNED) || accountDB.getAccountStatus().equals(AccountStatus.INACTIVE)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("You are banned");
}

Expand Down Expand Up @@ -201,7 +201,7 @@ public ResponseEntity<String> loginWithGoogle(OAuth2AuthenticationToken oAuth2Au
userAccount = userRepository.save(newUser);
}

if (userAccount.isBanned() || userAccount.getAccountStatus().equals(AccountStatus.INACTIVE)) {
if (userAccount.getAccountStatus().equals(AccountStatus.BANNED) || userAccount.getAccountStatus().equals(AccountStatus.INACTIVE)) {
//Create uri with token for redirect
String url = URL_CLIENT + "/" + "?success=false&message=You%20are%20banned";
URI uri = URI.create(url);
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/housemate/services/TaskBuildupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
Expand All @@ -24,6 +23,8 @@
import org.springframework.stereotype.Component;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import static housemate.constants.ServiceConfiguration.*;

import housemate.constants.AccountStatus;
import housemate.constants.Enum.TaskMessType;
import housemate.constants.Enum.TaskReportType;
import housemate.constants.Enum.TaskStatus;
Expand Down Expand Up @@ -687,7 +688,8 @@ public void run() {
TaskReport arrivedReport = taskReportRepo.findByTaskIdAndTaskStatus(task.getTaskId(), TaskStatus.ARRIVED);
if (task.getStaffId() != null && !task.getTaskStatus().equals("CANCELLED") && arrivedReport == null) {
Staff staff = staffRepo.findById(task.getStaffId()).get();
bannedStaff(staff);
staffRepo.save(staff);
bannedStaff(staff.getStaffId());
staff.setProfiencyScore(staff.getProfiencyScore() - MINUS_POINTS_FOR_NOT_COMPLETE_REPORT_TASK.getNum());
staff.setProfiencyScore(staff.getProfiencyScore() < 0 ? 0 : staff.getProfiencyScore());
staffRepo.save(staff);
Expand Down Expand Up @@ -727,7 +729,8 @@ public void run() {
Staff staff = staffRepo.findById(task.getStaffId()).get();
staff.setProfiencyScore(staff.getProfiencyScore() - MINUS_POINTS_FOR_NOT_COMPLETE_REPORT_TASK.getNum());
staff.setProfiencyScore(staff.getProfiencyScore() < 0 ? 0 : staff.getProfiencyScore());
bannedStaff(staff);
staffRepo.save(staff);
bannedStaff(staff.getStaffId());
Schedule schedule = scheduleRepo.findById(task.getScheduleId()).get();
schedule.setStatus(ScheduleStatus.CANCEL);
schedule.setNote(schedule.getNote()
Expand Down Expand Up @@ -779,7 +782,8 @@ public void run() {
Staff staff = staffRepo.findById(task.getStaffId()).get();
staff.setProfiencyScore(staff.getProfiencyScore() - MINUS_POINTS_FOR_NOT_COMPLETE_REPORT_TASK.getNum());
staff.setProfiencyScore(staff.getProfiencyScore() < 0 ? 0 : staff.getProfiencyScore());
bannedStaff(staff);
staffRepo.save(staff);
bannedStaff(staff.getStaffId());
Schedule schedule = scheduleRepo.findById(task.getScheduleId()).get();
schedule.setStatus(ScheduleStatus.CANCEL);
schedule.setNote(schedule.getNote()
Expand Down Expand Up @@ -832,9 +836,10 @@ private void CancelAllEventsByTaskId(int taskToBeCancelId) {
}
}

private void bannedStaff(Staff staff) {
if(staff.getProfiencyScore() == 0)
staff.setBanned(true);
public void bannedStaff(int userId) {
UserAccount user = userRepo.findByUserId(userId);
if(user.getProficiencyScore() == 0)
user.setAccountStatus(AccountStatus.BANNED);
}

public Schedule checkIsDuplicateTask(Task newTask, Staff staff){
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/housemate/services/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.stereotype.Component;
import housemate.constants.ScheduleStatus;
import static housemate.constants.ServiceConfiguration.*;
import housemate.constants.AccountStatus;
import housemate.constants.Enum.TaskMessType;
import housemate.constants.Enum.TaskReportType;
import housemate.constants.Enum.TaskStatus;
Expand Down Expand Up @@ -266,7 +267,7 @@ public ResponseEntity<?> cancelTask(HttpServletRequest request, int scheduleId)
.body("Bạn đã hủy lịch này thày công !\nChú ý bạn, bạn được phép hủy lịch trước giờ làm việc trước "
+ DURATION_HOURS_CUSTOMER_SHOULD_NOT_CANCEL_TASK.getNum()
+ " tiếng để đảm bảo nhân viên của chúng tôi sắp xếp được lịch làm việc .\nSau khoảng thời gian này chúng tôi sẽ trừ điểm uy tín của bạn.\nĐiểm uy tín nếu bằng 0 tài khoản sẽ bị cấm bởi hệ thống");
if (customer.isBanned())
if (customer.getAccountStatus().equals(AccountStatus.BANNED))
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body("Tài khoản của bạn đã bị cấm khỏi hệ thống vì đã vượt giới hạn số lần được hủy và điểm uy tín của bạn bằng 0 !");

Expand All @@ -278,8 +279,8 @@ public ResponseEntity<?> cancelTask(HttpServletRequest request, int scheduleId)
if (taskToBeCancelled.getStaff() != null) {
int subtract = customer.getProfiencyScore() - MINUS_POINTS_FOR_CUSTOMER_CANCEL_TASK.getNum();
customer.setProfiencyScore(subtract < 0 ? 0 : subtract);
if (customer.getProfiencyScore() == 0)
customer.setBanned(true);
customerRepo.save(customer);
taskBuildupServ.bannedStaff(customer.getCustomerId());
}
}
return ResponseEntity.ok().body("Bạn đã hủy lịch thành công !");
Expand All @@ -288,15 +289,15 @@ public ResponseEntity<?> cancelTask(HttpServletRequest request, int scheduleId)
if (userIdRequestCancel != scheduleToBeCancelled.getStaffId())
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Bạn không có quyền được xóa lịch này !");
taskToBeCancelled = taskBuildupServ.cancelTaskByRole(Role.STAFF, scheduleToBeCancelled,
"The staff has cancelled the task !");
"Nhân viên hủy lịch làm việc !");
if (taskToBeCancelled == null)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Có lỗi xảy ra ! Hủy lịch thất bại !");
if (hoursFrMinutes < DURATION_HOURS_STAFF_SHOULD_NOT_CANCEL_TASK.getNum()) {
Staff staff = staffRepo.findById(userCancel.getUserId()).get();
int subtract = staff.getProfiencyScore() - MINUS_POINTS_FOR_STAFF_CANCEL_TASK.getNum();
staff.setProfiencyScore(subtract < 0 ? 0 : subtract);
if (staff.getProfiencyScore() == 0)
staff.setBanned(true);
staffRepo.save(staff);
taskBuildupServ.bannedStaff(staff.getStaffId());
}
return ResponseEntity.ok().body("Bạn đã hủy lịch thành công !");
}
Expand All @@ -311,7 +312,6 @@ public ResponseEntity<?> updateTaskTimeWorking(HttpServletRequest request,
if (newSchedule == null)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Lịch không tồn tại");


TaskRes taskRes = taskBuildupServ.updateTaskOnScheduleChangeTime(scheduleNewTimeWorking);
if (taskRes.getMessType().equals(TaskMessType.REJECT_UPDATE_TASK)) {
return ResponseEntity.badRequest().body(taskRes.getMessage());
Expand All @@ -328,12 +328,11 @@ public ResponseEntity<?> approveStaff(HttpServletRequest request, int taskId) {
String role = authorizationUtil.getRoleFromAuthorizationHeader(request);
if (!role.equals(Role.STAFF.name()))
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("Truy cập thất bại - Chỉ cho phép tài khoản nhân viên mới được ứng tuyển !");

int staffId = authorizationUtil.getUserIdFromAuthorizationHeader(request);
Staff staff = staffRepo.findById(staffId).orElse(null);
if (staff == null)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Nhân viên không tồn tại !");
if (staff.isBanned())
if (staff.getAccountStatus().equals(AccountStatus.BANNED))
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Tài khoản của bạn đã bị cấm ! Bạn không được phép mua hàng hay ứng tuyển công việc từ tài khoản này được nữa !");
Task task = taskRepo.findById(taskId).orElse(null);
if (task == null)
Expand All @@ -352,6 +351,7 @@ public ResponseEntity<?> approveStaff(HttpServletRequest request, int taskId) {
+ dateFormat.format(Date.from(dupSchedule.getStartDate().atZone(dateTimeZone).toInstant())) + " và kết thúc ngày "
+ dateFormat.format(Date.from(dupSchedule.getEndDate().atZone(dateTimeZone).toInstant()))
+ " ! ");

if (task.getStaffId() != null && task.getStaffId() != staffId)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Lịch này đã có nhân viên khác ứng tuyển !");

Expand Down

0 comments on commit ce4a6c4

Please sign in to comment.