Skip to content

Commit faa86b5

Browse files
committed
Changing implementation
1 parent 229867f commit faa86b5

6 files changed

+145
-330
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package org.kryptokrona.hugin.controller;
2+
3+
import io.swagger.v3.oas.annotations.Operation;
4+
import io.swagger.v3.oas.annotations.tags.Tag;
5+
import org.kryptokrona.hugin.http.StatisticsResponse;
6+
import org.kryptokrona.hugin.service.HashtagService;
7+
import org.kryptokrona.hugin.service.PostEncryptedGroupService;
8+
import org.kryptokrona.hugin.service.PostEncryptedService;
9+
import org.kryptokrona.hugin.service.PostService;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.http.HttpStatus;
12+
import org.springframework.http.ResponseEntity;
13+
import org.springframework.web.bind.annotation.*;
14+
15+
import static org.kryptokrona.hugin.controller.StatisticsController.VERSION;
16+
17+
/**
18+
* Statistics Post Controller.
19+
*
20+
* @author Marcus Cvjeticanin
21+
*/
22+
@RestController
23+
@CrossOrigin(origins="*")
24+
@RequestMapping("api/v" + VERSION + "/statistics")
25+
@Tag(name = "statistics", description = "Set of endpoints to get statistical data.")
26+
public class StatisticsController {
27+
28+
static final String VERSION = "1";
29+
30+
private final PostService postService;
31+
32+
private final PostEncryptedService postEncryptedService;
33+
34+
private final PostEncryptedGroupService postEncryptedGroupService;
35+
36+
private final HashtagService hashtagService;
37+
38+
@Autowired
39+
public StatisticsController(
40+
PostService postService,
41+
PostEncryptedService postEncryptedService,
42+
PostEncryptedGroupService postEncryptedGroupService,
43+
HashtagService hashtagService
44+
) {
45+
this.postService = postService;
46+
this.postEncryptedService = postEncryptedService;
47+
this.postEncryptedGroupService = postEncryptedGroupService;
48+
this.hashtagService = hashtagService;
49+
}
50+
51+
@GetMapping("/posts")
52+
@Operation(
53+
summary = "Amount of posts",
54+
description = "Gets the total amount of posts during last 24h/week/month/year."
55+
)
56+
public ResponseEntity<StatisticsResponse> getPostStatistics() {
57+
var statisticsResponseObj = new StatisticsResponse();
58+
statisticsResponseObj.setTwentyFourHours(postService.getTotalItemsBy24h());
59+
statisticsResponseObj.setWeek(postService.getTotalItemsByWeek());
60+
statisticsResponseObj.setMonth(postService.getTotalItemsByMonth());
61+
statisticsResponseObj.setYear(postService.getTotalItemsByYear());
62+
63+
return new ResponseEntity<>(statisticsResponseObj, HttpStatus.OK);
64+
}
65+
66+
@GetMapping("/posts-encrypted")
67+
@Operation(
68+
summary = "Amount of encrypted group posts",
69+
description = "Gets the total amount of encrypted group posts during last 24h/week/month/year."
70+
)
71+
public ResponseEntity<StatisticsResponse> getPostEncryptedStatistics() {
72+
var statisticsResponseObj = new StatisticsResponse();
73+
statisticsResponseObj.setTwentyFourHours(postEncryptedService.getTotalItemsBy24h());
74+
statisticsResponseObj.setWeek(postEncryptedService.getTotalItemsByWeek());
75+
statisticsResponseObj.setMonth(postEncryptedService.getTotalItemsByMonth());
76+
statisticsResponseObj.setYear(postEncryptedService.getTotalItemsByYear());
77+
78+
return new ResponseEntity<>(statisticsResponseObj, HttpStatus.OK);
79+
}
80+
81+
@GetMapping("/post-encrypted-group")
82+
@Operation(
83+
summary = "Amount of encrypted posts",
84+
description = "Gets the total amount of encrypted posts during last 24h/week/month/year."
85+
)
86+
public ResponseEntity<StatisticsResponse> getPostEncryptedGroupStatistics() {
87+
var statisticsResponseObj = new StatisticsResponse();
88+
statisticsResponseObj.setTwentyFourHours(postEncryptedGroupService.getTotalItemsBy24h());
89+
statisticsResponseObj.setWeek(postEncryptedGroupService.getTotalItemsByWeek());
90+
statisticsResponseObj.setMonth(postEncryptedGroupService.getTotalItemsByMonth());
91+
statisticsResponseObj.setYear(postEncryptedGroupService.getTotalItemsByYear());
92+
93+
return new ResponseEntity<>(statisticsResponseObj, HttpStatus.OK);
94+
}
95+
96+
@GetMapping("/hashtag")
97+
@Operation(
98+
summary = "Amount of hashtags",
99+
description = "Gets the total amount of hashtags during last 24h/week/month/year."
100+
)
101+
public ResponseEntity<StatisticsResponse> getHashtagStatistics() {
102+
var statisticsResponseObj = new StatisticsResponse();
103+
statisticsResponseObj.setTwentyFourHours(hashtagService.getTotalItemsBy24h());
104+
statisticsResponseObj.setWeek(hashtagService.getTotalItemsByWeek());
105+
statisticsResponseObj.setMonth(hashtagService.getTotalItemsByMonth());
106+
statisticsResponseObj.setYear(hashtagService.getTotalItemsByYear());
107+
108+
return new ResponseEntity<>(statisticsResponseObj, HttpStatus.OK);
109+
}
110+
111+
}

src/main/java/org/kryptokrona/hugin/controller/statistics/latest/StatisticsHashtagController.java

-81
This file was deleted.

src/main/java/org/kryptokrona/hugin/controller/statistics/latest/StatisticsPostController.java

-79
This file was deleted.

src/main/java/org/kryptokrona/hugin/controller/statistics/latest/StatisticsPostEncryptedController.java

-81
This file was deleted.

0 commit comments

Comments
 (0)