memory: set @odata attributes only if the object is found

The existing code returns a JSON payload with @odata attributes even if
it is a 404 not found.

This commit corrects that by moving @odata after the object is found.

Tested:
1. before
```
{
    "@odata.id": "/redfish/v1/Systems/system/Memory/dimm5",
    "@odata.type": "#Memory.v1_11_0.Memory",
    "error": {
        "@Message.ExtendedInfo": [
            {
                "@odata.type": "#Message.v1_1_1.Message",
                "Message": "The requested resource of type Memory named 'dimm5' was not found.",
                "MessageArgs": [
                    "Memory",
                    "dimm5"
                ],
                "MessageId": "Base.1.11.0.ResourceNotFound",
                "MessageSeverity": "Critical",
                "Resolution": "Provide a valid resource identifier and resubmit the request."
            }
        ],
        "code": "Base.1.11.0.ResourceNotFound",
        "message": "The requested resource of type Memory named 'dimm5' was not found."
    }
}
```
after
```
{
    "error": {
        "@Message.ExtendedInfo": [
            {
                "@odata.type": "#Message.v1_1_1.Message",
                "Message": "The requested resource of type Memory named 'dimm5' was not found.",
                "MessageArgs": [
                    "Memory",
                    "dimm5"
                ],
                "MessageId": "Base.1.11.0.ResourceNotFound",
                "MessageSeverity": "Critical",
                "Resolution": "Provide a valid resource identifier and resubmit the request."
            }
        ],
        "code": "Base.1.11.0.ResourceNotFound",
        "message": "The requested resource of type Memory named 'dimm5' was not found."
    }
}
```
2. Service Validator on MemoryResource passes.

Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: Id0f912015b0ecf25cacb22e919ebe88708187677
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index 4e9b4b7..68be9a7 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -845,7 +845,12 @@
             if (!found)
             {
                 messages::resourceNotFound(aResp->res, "Memory", dimmId);
+                return;
             }
+            // Set @odata only if object is found
+            aResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
+            aResp->res.jsonValue["@odata.id"] =
+                "/redfish/v1/Systems/system/Memory/" + dimmId;
             return;
         },
         "xyz.openbmc_project.ObjectMapper",
@@ -898,11 +903,6 @@
                 {
                     return;
                 }
-                asyncResp->res.jsonValue["@odata.type"] =
-                    "#Memory.v1_11_0.Memory";
-                asyncResp->res.jsonValue["@odata.id"] =
-                    "/redfish/v1/Systems/system/Memory/" + dimmId;
-
                 getDimmData(asyncResp, dimmId);
             });
 }