Skip to content

Commit b390582

Browse files
author
Reginald C Cole
committed
Add Rest API for Customer and PromotionMessage
1 parent b8bd8b4 commit b390582

File tree

2 files changed

+187
-0
lines changed

2 files changed

+187
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
* Copyright 2008-2012 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.mycompany.api.endpoint.customer;
18+
19+
import org.springframework.http.MediaType;
20+
import org.springframework.web.bind.annotation.PathVariable;
21+
import org.springframework.web.bind.annotation.RequestBody;
22+
import org.springframework.web.bind.annotation.RequestMapping;
23+
import org.springframework.web.bind.annotation.RequestMethod;
24+
import org.springframework.web.bind.annotation.RequestParam;
25+
import org.springframework.web.bind.annotation.RestController;
26+
27+
import com.broadleafcommerce.rest.api.wrapper.CustomerAddressWrapper;
28+
import com.broadleafcommerce.rest.api.wrapper.CustomerAttributeWrapper;
29+
import com.broadleafcommerce.rest.api.wrapper.CustomerPaymentWrapper;
30+
import com.broadleafcommerce.rest.api.wrapper.CustomerWrapper;
31+
32+
import java.util.List;
33+
34+
import javax.servlet.http.HttpServletRequest;
35+
36+
/**
37+
*
38+
*/
39+
@RestController
40+
@RequestMapping(value = "/customer",
41+
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
42+
public class CustomerEndpoint extends com.broadleafcommerce.rest.api.endpoint.customer.CustomerEndpoint {
43+
44+
@Override
45+
@RequestMapping(method = RequestMethod.GET)
46+
public CustomerWrapper findCustomerByEmail(HttpServletRequest request,
47+
@RequestParam(value = "email", required = true) String emailAddress) {
48+
return super.findCustomerByEmail(request, emailAddress);
49+
}
50+
51+
@Override
52+
@RequestMapping(method = RequestMethod.POST,
53+
consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
54+
public CustomerWrapper addCustomer(HttpServletRequest request, @RequestBody CustomerWrapper customerWrapper) {
55+
return super.addCustomer(request, customerWrapper);
56+
}
57+
58+
/**
59+
* This method is weird because we take in a customer object that has an id, but we don't
60+
* actually look the customer object up by that id to update it. We require a customer id
61+
*/
62+
@Override
63+
@RequestMapping(method = RequestMethod.PUT,
64+
consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
65+
public CustomerWrapper updateCustomer(HttpServletRequest request, @RequestBody CustomerWrapper customerWrapper) {
66+
return super.updateCustomer(request, customerWrapper);
67+
}
68+
69+
@Override
70+
@RequestMapping(value = "/attributes", method = RequestMethod.DELETE)
71+
public CustomerWrapper removeAllAttributes(HttpServletRequest request) {
72+
return super.removeAllAttributes(request);
73+
}
74+
75+
@Override
76+
@RequestMapping(value = "/attribute", method = RequestMethod.PUT,
77+
consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
78+
public CustomerWrapper addAttribute(HttpServletRequest request, @RequestBody CustomerAttributeWrapper wrapper) {
79+
return super.addAttribute(request, wrapper);
80+
}
81+
82+
@Override
83+
@RequestMapping(value = "/attribute/{attributeName}", method = RequestMethod.DELETE)
84+
public CustomerWrapper removeAttribute(HttpServletRequest request, @PathVariable("attributeName") String attributeName) {
85+
return super.removeAttribute(request, attributeName);
86+
}
87+
88+
@Override
89+
@RequestMapping(value = "/addresses", method = RequestMethod.GET)
90+
public List<CustomerAddressWrapper> findAllAddresses(HttpServletRequest request) {
91+
return super.findAllAddresses(request);
92+
}
93+
94+
@Override
95+
@RequestMapping(value = "/address", method = RequestMethod.GET)
96+
public CustomerAddressWrapper findAddress(HttpServletRequest request, @RequestParam("addressName") String addressName) {
97+
return super.findAddress(request, addressName);
98+
}
99+
100+
101+
@Override
102+
@RequestMapping(value = "/address", method = RequestMethod.PUT)
103+
public CustomerAddressWrapper addAddress(HttpServletRequest request, @RequestBody CustomerAddressWrapper wrapper) {
104+
return super.addAddress(request, wrapper);
105+
}
106+
107+
@Override
108+
@RequestMapping(value = "/address/{addressId}", method = RequestMethod.PUT)
109+
public CustomerAddressWrapper updateAddress(HttpServletRequest request, @PathVariable("addressId") Long customerAddressId,
110+
@RequestBody CustomerAddressWrapper wrapper) {
111+
return super.updateAddress(request, customerAddressId, wrapper);
112+
}
113+
114+
@Override
115+
@RequestMapping(value = "/addresses", method = RequestMethod.DELETE)
116+
public CustomerWrapper removeAllAddresses(HttpServletRequest request) {
117+
return super.removeAllAddresses(request);
118+
}
119+
120+
@Override
121+
@RequestMapping(value = "/address/{addressName}", method = RequestMethod.DELETE)
122+
public List<CustomerAddressWrapper> removeAddress(HttpServletRequest request, @PathVariable("addressName") String addressName) {
123+
return super.removeAddress(request, addressName);
124+
}
125+
126+
@Override
127+
@RequestMapping(value = "/payment", method = RequestMethod.POST)
128+
public CustomerPaymentWrapper addCustomerPayment(HttpServletRequest request,
129+
@RequestBody CustomerPaymentWrapper wrapper) {
130+
return super.addCustomerPayment(request, wrapper);
131+
}
132+
133+
@Override
134+
@RequestMapping(value = "/payments", method = RequestMethod.DELETE)
135+
public CustomerWrapper removeAllCustomerPayments(HttpServletRequest request) {
136+
return super.removeAllCustomerPayments(request);
137+
}
138+
139+
@Override
140+
@RequestMapping(value = "/payment/{paymentId}", method = RequestMethod.DELETE)
141+
public List<CustomerPaymentWrapper> removeCustomerPayment(HttpServletRequest request, @PathVariable("paymentId") Long paymentId) {
142+
return super.removeCustomerPayment(request, paymentId);
143+
}
144+
145+
@Override
146+
@RequestMapping(value = "/payment", method = RequestMethod.GET)
147+
public CustomerPaymentWrapper findCustomerPayment(HttpServletRequest request, @RequestParam("paymentId") Long paymentId) {
148+
return super.findCustomerPayment(request, paymentId);
149+
}
150+
151+
@Override
152+
@RequestMapping(value = "/payments", method = RequestMethod.GET)
153+
public List<CustomerPaymentWrapper> findAllCustomerPayments(HttpServletRequest request) {
154+
return super.findAllCustomerPayments(request);
155+
}
156+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.mycompany.api.endpoint.promotionmessage;
2+
3+
import org.springframework.http.MediaType;
4+
import org.springframework.web.bind.annotation.PathVariable;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import com.broadleafcommerce.rest.api.wrapper.PromotionMessageDTOWrapper;
10+
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
import javax.servlet.http.HttpServletRequest;
15+
16+
/**
17+
* @author Chris Kittrell (ckittrell)
18+
*/
19+
@RestController
20+
@RequestMapping(value = "/promotion-messages/",
21+
produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
22+
public class PromotionMessageEndpoint extends com.broadleafcommerce.rest.api.endpoint.promotionmessage.PromotionMessageEndpoint {
23+
24+
@Override
25+
@RequestMapping(value = "{productId}", method = RequestMethod.GET)
26+
public Map<String, List<PromotionMessageDTOWrapper>> findPromotionMessagesForProduct(HttpServletRequest request,
27+
@PathVariable("productId") Long productId) {
28+
return super.findPromotionMessagesForProduct(request, productId);
29+
}
30+
31+
}

0 commit comments

Comments
 (0)