添加成功响应,在获取成员详细信息后。

huangapple go评论131阅读模式
英文:

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 &amp;&amp; this.clientRepository.getClientByMemberNo(String.valueOf(request.getGeneratedMemberNo())) == null) ||
	    		   (request.getFirstname() != null &amp;&amp; this.clientRepository.getClientByFirstName(String.valueOf(request.getFirstname())) == null) ||
	    		   (request.getLastname() != null &amp;&amp; this.clientRepository.getClientByLastName(String.valueOf(request.getLastname())) == null)){
	    		  result = new CommandProcessingResultBuilder()
	    		    .setStatus(ResponseStatusEnum.FAILED.getValue())
	    		    .setMessage(ResponseStatusEnum.MEMBER_NOT_FOUND.getValue())
                    .setPfsRefNo(&quot;&lt;yyyyMMddhms-count&gt;)
	    		    .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 = &quot;THIS IS DATE&quot;;
		this.membershipFeePaid = false;
		this.picPath = &quot;THIS IS PICTURE&quot;;
		this.signPath = &quot;THIS IS SIGN&quot;;
		this.firstName = firstName;
		this.lastName = lastName;
		this.capConBalance = false;
		this.lastPrintedDate = &quot;THIS IS PRINTING DATE&quot;;
	}
	
	
	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(&quot;Success&quot;)
                    .setMessage(&quot;Successful Retrieval of Member Info&quot;)
                    .setPfsRefNo(&quot;&lt;yyyyMMddhms-count&gt;&quot;)
                    .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>



huangapple
  • 本文由 发表于 2020年7月23日 19:48:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63053540.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定