This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mycompany.deleteannotation; | |
import javax.xml.bind.annotation.XmlRootElement; | |
import java.util.Date; | |
@XmlRootElement | |
public class Order { | |
private int id; | |
private String item; | |
private int qty; | |
private Date orderDate; | |
public Order() { | |
} | |
@Override | |
public String toString() { | |
return "Order{" + | |
"id=" + id + | |
", item='" + item + '\'' + | |
", qty=" + qty + | |
", orderDate=" + orderDate + | |
'}'; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getItem() { | |
return item; | |
} | |
public void setItem(String item) { | |
this.item = item; | |
} | |
public int getQty() { | |
return qty; | |
} | |
public void setQty(int qty) { | |
this.qty = qty; | |
} | |
public Date getOrderDate() { | |
return orderDate; | |
} | |
public void setOrderDate(Date orderDate) { | |
this.orderDate = orderDate; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mycompany.deleteannotation; | |
import javax.ws.rs.*; | |
import javax.ws.rs.core.MediaType; | |
import java.util.Collection; | |
@Path("/orders") | |
@Produces({MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN}) | |
public class OrderResource { | |
@GET | |
public Collection<Order> getOrders() { | |
return OrderService.Instance.getAllOrders(); | |
} | |
@DELETE | |
@Path("{id}") | |
public boolean deleteOrderById(@PathParam("id") int id) { | |
return OrderService.Instance.deleteOrderById(id); | |
} | |
@GET | |
@Path("{id}") | |
public Order getOrderById(@PathParam("id") int id) { | |
return OrderService.Instance.getOrderById(id); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mycompany.deleteannotation; | |
import java.time.*; | |
import java.util.*; | |
public enum OrderService { | |
Instance; | |
private Map<Integer,Order> orders=new HashMap<>(); | |
OrderService(){ | |
Instant instant = OffsetDateTime.now().toInstant(); | |
for (int i = 1; i <= 5; i++) { | |
Order order = new Order(); | |
order.setId(i); | |
order.setItem("item " + i); | |
order.setQty((int) (1 + Math.random() * 100)); | |
long millis = instant.minus(Period.ofDays(i)) | |
.toEpochMilli(); | |
order.setOrderDate(new Date(millis)); | |
orders.put(i, order); | |
} | |
} | |
public Collection<Order> getAllOrders(){ | |
return new ArrayList<>(orders.values()); | |
} | |
public boolean deleteOrderById(int orderId) { | |
return orders.remove(orderId) != null; | |
} | |
public Order getOrderById(int id) { | |
return orders.get(id); | |
} | |
} |
İYİ ÇALIŞMALAR...
Hiç yorum yok:
Yorum Gönder