1 package com.srv4pos.server.api.hairdresser;
2
3 import com.srv4pos.server.api.infrastructure.HttpMethod;
4 import com.srv4pos.server.api.infrastructure.StringConnectionWriter;
5 import com.srv4pos.server.api.infrastructure.credentials.Credentials;
6 import com.srv4pos.server.api.infrastructure.http.HttpHelper;
7 import com.srv4pos.server.api.infrastructure.http.Transport;
8 import com.srv4pos.server.api.infrastructure.request.StringResponse;
9
10 import java.net.URL;
11
12 import static com.srv4pos.server.api.infrastructure.EmptyConnectionWriter.EMPTY_CONNECTION_WRITER;
13 import static com.srv4pos.server.api.infrastructure.http.HttpHelper.CONTENT_TYPE_APPLICATION_JSON;
14 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestString;
15 import static com.srv4pos.server.api.infrastructure.request.RequestHelper.requestVoid;
16 import static java.lang.String.format;
17
18
19
20
21 public class HairdresserService {
22 private URL url;
23 private Credentials credentials;
24 private Transport transport;
25
26
27
28
29
30
31
32
33 public HairdresserService(URL url, Credentials credentials, Transport transport) {
34 this.url = url;
35 this.credentials = credentials;
36 this.transport = transport;
37 }
38
39
40
41
42
43
44
45
46
47
48 public HairdresserInfo get(String sellerId, Integer version) {
49 StringResponse response = requestString(
50 format("hairdressers/%s", sellerId),
51 HttpMethod.GET,
52 url,
53 credentials.toAuthentication(),
54 HttpHelper.integerToETag(version),
55 null,
56 EMPTY_CONNECTION_WRITER,
57 CONTENT_TYPE_APPLICATION_JSON,
58 transport
59 );
60 return response == null ? null : HairdresserInfo.fromJsonToHairdresserInfo(response.getContent());
61 }
62
63
64
65
66
67
68
69
70
71
72 public void put(int version, String sellerId, HairdresserInfo hairdresserInfo) {
73 requestVoid(
74 format("hairdressers/%s", sellerId),
75 HttpMethod.PUT,
76 url,
77 credentials.toAuthentication(),
78 HttpHelper.integerToETag(version),
79 null,
80 new StringConnectionWriter(hairdresserInfo.toJson()),
81 CONTENT_TYPE_APPLICATION_JSON,
82 transport
83 );
84 }
85
86
87
88
89
90
91 public void remove(String sellerId) {
92 requestVoid(
93 format("hairdressers/%s", sellerId),
94 HttpMethod.DELETE,
95 url,
96 credentials.toAuthentication(),
97 null,
98 null,
99 EMPTY_CONNECTION_WRITER,
100 CONTENT_TYPE_APPLICATION_JSON,
101 transport);
102 }
103 }