Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Reviewed-on: #54
This commit was merged in pull request #54.
This commit is contained in:
@@ -2,6 +2,8 @@ package com.drinkool.entities;
|
||||
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.models.UserModel;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.ArrayList;
|
||||
@@ -11,6 +13,7 @@ import java.util.List;
|
||||
@Table(name = Role.Manager)
|
||||
public class ManagerEntity extends UserModel {
|
||||
|
||||
@JsonIgnore
|
||||
@OneToMany(
|
||||
mappedBy = "serve",
|
||||
cascade = CascadeType.ALL,
|
||||
@@ -18,6 +21,7 @@ public class ManagerEntity extends UserModel {
|
||||
)
|
||||
public List<StaffEntity> staffs = new ArrayList<>();
|
||||
|
||||
@JsonIgnore
|
||||
@Column(nullable = true)
|
||||
public String bankAccount;
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ public class ManagerService extends BaseService<ManagerEntity> {
|
||||
.build();
|
||||
|
||||
return Response.accepted()
|
||||
.entity(manager)
|
||||
.header(InternalValue.userId, manager.id.toString())
|
||||
.header(InternalValue.role, Role.Manager)
|
||||
.build();
|
||||
|
||||
@@ -9,6 +9,9 @@ import jakarta.json.bind.Jsonb;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class GraphqlBase {
|
||||
|
||||
@@ -39,18 +42,25 @@ public abstract class GraphqlBase {
|
||||
gqlRequest.variables
|
||||
);
|
||||
|
||||
if (response.hasError()) {
|
||||
return Response.status(400)
|
||||
.entity(jsonb.toJson(response.getErrors()))
|
||||
.build();
|
||||
}
|
||||
Map<String, Object> gqlBody = new HashMap<>();
|
||||
|
||||
return Response.ok(jsonb.toJson(response.getData()))
|
||||
gqlBody.put("data", response.getData());
|
||||
gqlBody.put("errors", response.getErrors());
|
||||
return Response.ok(jsonb.toJson(gqlBody))
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Response.serverError().entity("Lỗi kết nối tới service").build();
|
||||
Map<String, Object> errorBody = new HashMap<>();
|
||||
errorBody.put(
|
||||
"errors",
|
||||
List.of(Map.of("message", "Lỗi kết nối tới service: " + e.getMessage()))
|
||||
);
|
||||
|
||||
return Response.serverError()
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.entity(jsonb.toJson(errorBody))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user