chore: update
This commit is contained in:
Vendored
+2
-1
@@ -7,7 +7,8 @@
|
||||
"**/Thumbs.db": true,
|
||||
"**/target": true,
|
||||
"**/docker": true,
|
||||
"node_modules": true
|
||||
"node_modules": true,
|
||||
"**/.mvn": true
|
||||
},
|
||||
"explorerExclude.backup": {},
|
||||
"java.compile.nullAnalysis.mode": "automatic",
|
||||
|
||||
@@ -3,11 +3,20 @@ package com.drinkool.entities;
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.models.UserModel;
|
||||
import jakarta.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = Role.Manager)
|
||||
public class ManagerEntity extends UserModel {
|
||||
|
||||
@OneToMany(
|
||||
mappedBy = "serve",
|
||||
cascade = CascadeType.ALL,
|
||||
orphanRemoval = true
|
||||
)
|
||||
public List<StaffEntity> staffs = new ArrayList<>();
|
||||
|
||||
public ManagerEntity() {
|
||||
super(Role.Manager);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.models.UserModel;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
@Entity
|
||||
@Table(name = Role.Staff)
|
||||
public class StaffEntity extends UserModel {
|
||||
|
||||
@Transactional
|
||||
public void signup(
|
||||
String name,
|
||||
String phone,
|
||||
String rawPassword,
|
||||
ManagerEntity serve
|
||||
) {
|
||||
this.serve = serve;
|
||||
super.signup(name, phone, rawPassword);
|
||||
}
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "managerId")
|
||||
public ManagerEntity serve;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.drinkool.filters;
|
||||
|
||||
|
||||
import com.drinkool.lib.utils.BaseHeaderAuthentication;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class HeaderRolesFilter extends BaseHeaderAuthentication {}
|
||||
@@ -44,25 +44,25 @@ public class ManagerService extends BaseService<ManagerEntity> {
|
||||
@POST
|
||||
@Path(Url.Login)
|
||||
public Response login(Login input) {
|
||||
ManagerEntity customer = ManagerEntity.find(
|
||||
ManagerEntity manager = ManagerEntity.find(
|
||||
"phone",
|
||||
input.phone
|
||||
).firstResult();
|
||||
|
||||
if (customer == null) return Response.status(Response.Status.BAD_REQUEST)
|
||||
if (manager == null) return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity("InvalidPhoneNumber")
|
||||
.build();
|
||||
|
||||
if (!customer.login(input.password)) return Response.status(
|
||||
if (!manager.login(input.password)) return Response.status(
|
||||
Response.Status.BAD_REQUEST
|
||||
)
|
||||
.entity("InvalidPassword")
|
||||
.build();
|
||||
|
||||
return Response.accepted()
|
||||
.header(InternalValue.userId, customer.id.toString())
|
||||
.header(InternalValue.userId, manager.id.toString())
|
||||
.header(InternalValue.role, Role.Manager)
|
||||
.entity(customer)
|
||||
.entity(manager)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.drinkool.services;
|
||||
|
||||
import com.drinkool.InternalValue;
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.Url;
|
||||
import com.drinkool.entities.ManagerEntity;
|
||||
import com.drinkool.entities.StaffEntity;
|
||||
import com.drinkool.lib.dtos.Login;
|
||||
import com.drinkool.lib.dtos.Signup;
|
||||
import io.vertx.core.http.HttpServerRequest;
|
||||
import jakarta.annotation.security.RolesAllowed;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path(Role.Staff)
|
||||
public class StaffService extends BaseService<StaffEntity> {
|
||||
|
||||
@Inject
|
||||
HttpServerRequest request;
|
||||
|
||||
public StaffService() {
|
||||
super(StaffEntity.class);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path(Url.Signup)
|
||||
@RolesAllowed(Role.Manager)
|
||||
@Transactional
|
||||
public Response signup(Signup input) {
|
||||
String managerId = request.getHeader(InternalValue.userId);
|
||||
ManagerEntity manager = ManagerEntity.findById(managerId);
|
||||
|
||||
if (manager == null) return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity("InvalidManager")
|
||||
.build();
|
||||
|
||||
StaffEntity staff = new StaffEntity();
|
||||
staff.signup(input.name, input.phone, input.password, manager);
|
||||
|
||||
return Response.status(Response.Status.CREATED)
|
||||
.header(InternalValue.userId, staff.id.toString())
|
||||
.header(InternalValue.role, Role.Staff)
|
||||
.build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path(Url.Login)
|
||||
public Response login(Login input) {
|
||||
StaffEntity staff = StaffEntity.find(
|
||||
"phone",
|
||||
input.phone
|
||||
).firstResult();
|
||||
|
||||
if (staff == null) return Response.status(Response.Status.BAD_REQUEST)
|
||||
.entity("InvalidPhoneNumber")
|
||||
.build();
|
||||
|
||||
if (!staff.login(input.password)) return Response.status(
|
||||
Response.Status.BAD_REQUEST
|
||||
)
|
||||
.entity("InvalidPassword")
|
||||
.build();
|
||||
|
||||
return Response.accepted()
|
||||
.header(InternalValue.userId, staff.id.toString())
|
||||
.header(InternalValue.role, Role.Staff)
|
||||
.entity(staff)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,5 @@ public class Role {
|
||||
|
||||
public static final String Customer = "customer";
|
||||
public static final String Manager = "manager";
|
||||
public static final String Staff = "Staff";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user