英文:
Adding success response after retrieval of member details
问题
这是我在 API/Controller 中的代码,我已经成功实现了错误消息(当请求的会员详细信息未找到时会显示错误消息)
if ((request.getGeneratedMemberNo() != null && this.clientRepository.getClientByMemberNo(String.valueOf(request.getGeneratedMemberNo())) == null) ||
(request.getFirstname() != null && this.clientRepository.getClientByFirstName(String.valueOf(request.getFirstname())) == null) ||
(request.getLastname() != null && this.clientRepository.getClientByLastName(String.valueOf(request.getLastname())) == null)) {
result = new CommandProcessingResultBuilder()
.setStatus(ResponseStatusEnum.FAILED.getValue())
.setMessage(ResponseStatusEnum.MEMBER_NOT_FOUND.getValue())
.setPfsRefNo("<yyyyMMddhms-count>")
.setRefNo(refNo)
.build();
return this.toApiJsonSerializer.serialize(result);
}
这是我的 MemberData.java 文件,请求正在被调用
@Data
public class MemberData {
public String generatedMemberNo;
public String idFeePaymentDate;
public boolean membershipFeePaid;
public String picPath;
public String signPath;
public String firstName;
public String lastName;
public boolean capConBalance;
public String lastPrintedDate;
public MemberData(String generatedMemberNo, String firstName, String lastName) {
this.generatedMemberNo = generatedMemberNo;
this.idFeePaymentDate = "这是日期";
this.membershipFeePaid = false;
this.picPath = "这是图片";
this.signPath = "这是签名";
this.firstName = firstName;
this.lastName = lastName;
this.capConBalance = false;
this.lastPrintedDate = "这是打印日期";
}
public static MemberData instance(final String generatedMemberNo, final String firstName,
final String lastName) {
return new MemberData(generatedMemberNo, firstName, lastName);
}
}
在哪里可以放置成功消息/这段代码块呢?
result = new CommandProcessingResultBuilder()
.setStatus("Success")
.setMessage("成功检索会员信息")
.setPfsRefNo("<yyyyMMddhms-count>")
.setRefNo(refNo)
.build();
英文:
Is there any way I could put this success message after the actual response? This is what my response should look like. This is currently what I have implemented These are the member details, still without the success message I want to be implemented.
This is my code in API/Controller where I have successfully implemented error message (which will appear when requested member details are not found)
if((request.getGeneratedMemberNo() != null && this.clientRepository.getClientByMemberNo(String.valueOf(request.getGeneratedMemberNo())) == null) ||
(request.getFirstname() != null && this.clientRepository.getClientByFirstName(String.valueOf(request.getFirstname())) == null) ||
(request.getLastname() != null && this.clientRepository.getClientByLastName(String.valueOf(request.getLastname())) == null)){
result = new CommandProcessingResultBuilder()
.setStatus(ResponseStatusEnum.FAILED.getValue())
.setMessage(ResponseStatusEnum.MEMBER_NOT_FOUND.getValue())
.setPfsRefNo("<yyyyMMddhms-count>)
.setRefNo(refNo)
.build();
return this.toApiJsonSerializer.serialize(result);
}
This is my MemberData.java where the requests are being called
@Data
public class MemberData {
public String generatedMemberNo;
public String idFeePaymentDate;
public boolean membershipFeePaid;
public String picPath;
public String signPath;
public String firstName;
public String lastName;
public boolean capConBalance;
public String lastPrintedDate;
public MemberData (String generatedMemberNo, String firstName, String lastName)
{
this.generatedMemberNo = generatedMemberNo;
this.idFeePaymentDate = "THIS IS DATE";
this.membershipFeePaid = false;
this.picPath = "THIS IS PICTURE";
this.signPath = "THIS IS SIGN";
this.firstName = firstName;
this.lastName = lastName;
this.capConBalance = false;
this.lastPrintedDate = "THIS IS PRINTING DATE";
}
public static MemberData instance(final String generatedMemberNo, final String firstName,
final String lastName) {
return new MemberData (generatedMemberNo,firstName, lastName);
}
}
Where may I possibly put success message/this block of code?
.setStatus("Success")
.setMessage("Successful Retrieval of Member Info")
.setPfsRefNo("<yyyyMMddhms-count>")
.setRefNo(refNo)
.build();
</details>
# 答案1
**得分**: 1
你需要创建一个名为`MemberResponse`的类,具有以下属性:
public MemberData member;
public String status;
public String message;
public String pfsRefNo;
public String refNo;
当你在HTTP响应中返回这个对象时,需要满足原始的需求。
<details>
<summary>英文:</summary>
You will need to create a class `MemberResponse` with these properties:
public MemberData member;
public String status;
public String message;
public String pfsRefNo;
public String refNo;
When you return this object in the HTTP response, you will match the original requirements.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论