-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/com/snsIntegrationFeedService/post/controller/StaticsController.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.snsIntegrationFeedService.post.controller; | ||
|
||
import com.snsIntegrationFeedService.post.CountType; | ||
import com.snsIntegrationFeedService.post.DateType; | ||
import com.snsIntegrationFeedService.post.dto.request.StaticsRequest; | ||
import com.snsIntegrationFeedService.post.dto.response.StaticsResponse; | ||
import com.snsIntegrationFeedService.post.service.PostService; | ||
import com.snsIntegrationFeedService.post.service.StaticService; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class StaticsController { | ||
|
||
private final StaticService staticService; | ||
|
||
// @GetMapping(value = "/api/posts/statics") | ||
// public ResponseEntity<List<StaticsResponse>> getResponse( | ||
// @RequestParam(value = "value", required = false) CountType countType, | ||
// @RequestParam(value = "type") DateType dateType, | ||
// @RequestParam(value = "hashtag", required = false, defaultValue = "본인계정") String hashtag, | ||
// @RequestParam(value = "start", required = false) | ||
// @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, | ||
// @RequestParam(value = "start", required = false) | ||
// @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) { | ||
// | ||
// return ResponseEntity.ok() | ||
// .body(staticService.getStaticsResponse(countType, dateType, hashtag, startDate, endDate)); | ||
// | ||
// } | ||
|
||
// @GetMapping(value = "/api/posts/statics") | ||
// public ResponseEntity<List<StaticsResponse>> getResponse(@ModelAttribute StaticsRequest request) { | ||
// | ||
// return ResponseEntity.ok() | ||
// .body(staticService.getListStaticsResponse(request)); | ||
// } | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/com/snsIntegrationFeedService/post/service/StaticService.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.snsIntegrationFeedService.post.service; | ||
|
||
import com.snsIntegrationFeedService.hashtag.service.HashtagService; | ||
import com.snsIntegrationFeedService.post.CountType; | ||
import com.snsIntegrationFeedService.post.DateType; | ||
import com.snsIntegrationFeedService.post.dto.request.StaticsRequest; | ||
import com.snsIntegrationFeedService.post.dto.response.StaticsResponse; | ||
import com.snsIntegrationFeedService.post.repository.PostRepository; | ||
import com.snsIntegrationFeedService.postHashtag.service.PostHashtagService; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StaticService { | ||
|
||
private final PostRepository postRepository; | ||
private final HashtagService hashtagService; | ||
private final PostHashtagService postHashtagService; | ||
|
||
// public List<StaticsResponse> getListStaticsResponse(StaticsRequest request) { | ||
// String value = String.valueOf(request.getValue()); | ||
// String type = String.valueOf(request.getType()); | ||
// Date startDate = this.checkStartDate(request.getStart()); | ||
// Date endDate = this.checkEndDate(request.getEnd()); | ||
// String hashtag = request.getHashtag(); | ||
// | ||
// } | ||
|
||
public StaticsResponse getDateStaticsResponse(String value, Date date, String hashtag) { | ||
List<Long> postIds = postHashtagService.getPostIdsByHashtag(hashtag); | ||
long count = postRepository.findCountByValueAndDate(value, date); | ||
|
||
return StaticsResponse.builder() | ||
.date(date) | ||
.num(count) | ||
.build(); | ||
} | ||
|
||
// public StaticsResponse getHourStaticsResponse() { | ||
// | ||
// } | ||
|
||
private Date checkStartDate(Date startDate) { | ||
|
||
if (startDate == null) { | ||
// 만약 startDate가 입력되지 않은 경우, 오늘로부터 7일 전 날짜를 기본값으로 설정 | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.setTime(new Date()); // 현재 날짜 설정 | ||
calendar.add(Calendar.DAY_OF_MONTH, -7); // 7일 전 날짜로 설정 | ||
startDate = calendar.getTime(); | ||
|
||
return startDate; | ||
} else { | ||
return startDate; | ||
} | ||
} | ||
|
||
private Date checkEndDate(Date endDate) { | ||
if (endDate == null) { | ||
// 만약 startDate가 입력되지 않은 경우, 오늘로부터 7일 전 날짜를 기본값으로 설정 | ||
Calendar calendar = Calendar.getInstance(); | ||
calendar.setTime(new Date()); // 현재 날짜 설정 | ||
endDate = calendar.getTime(); | ||
|
||
return endDate; | ||
} else { | ||
return endDate; | ||
} | ||
} | ||
} |