-
Notifications
You must be signed in to change notification settings - Fork 4
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
238 changed files
with
6,466 additions
and
5,658 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
.../kirikiri/src/main/java/co/kirikiri/checkfeed/controller/GoalRoomCheckFeedController.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,45 @@ | ||
package co.kirikiri.checkfeed.controller; | ||
|
||
import co.kirikiri.checkfeed.service.GoalRoomCheckFeedService; | ||
import co.kirikiri.checkfeed.service.dto.request.CheckFeedRequest; | ||
import co.kirikiri.checkfeed.service.dto.response.GoalRoomCheckFeedResponse; | ||
import co.kirikiri.common.interceptor.Authenticated; | ||
import co.kirikiri.common.resolver.MemberIdentifier; | ||
import java.net.URI; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
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.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/goal-rooms/{goalRoomId}/checkFeeds") | ||
@RequiredArgsConstructor | ||
public class GoalRoomCheckFeedController { | ||
|
||
private final GoalRoomCheckFeedService goalRoomCheckFeedService; | ||
|
||
@PostMapping(consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}) | ||
@Authenticated | ||
public ResponseEntity<Void> createCheckFeed(@MemberIdentifier final String identifier, | ||
@PathVariable("goalRoomId") final Long goalRoomId, | ||
@ModelAttribute final CheckFeedRequest checkFeedRequest) { | ||
final String imageUrl = goalRoomCheckFeedService.createCheckFeed(identifier, goalRoomId, checkFeedRequest); | ||
return ResponseEntity.created(URI.create(imageUrl)).build(); | ||
} | ||
|
||
@GetMapping | ||
@Authenticated | ||
public ResponseEntity<List<GoalRoomCheckFeedResponse>> findGoalRoomCheckFeeds( | ||
@MemberIdentifier final String identifier, | ||
@PathVariable("goalRoomId") final Long goalRoomId) { | ||
final List<GoalRoomCheckFeedResponse> response = goalRoomCheckFeedService.findGoalRoomCheckFeeds(identifier, | ||
goalRoomId); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
backend/kirikiri/src/main/java/co/kirikiri/checkfeed/persistence/CheckFeedRepository.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,35 @@ | ||
package co.kirikiri.checkfeed.persistence; | ||
|
||
import co.kirikiri.checkfeed.domain.CheckFeed; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface CheckFeedRepository extends JpaRepository<CheckFeed, Long> { | ||
|
||
@Query("SELECT cf" | ||
+ " FROM CheckFeed cf" | ||
+ " WHERE cf.goalRoomMemberId = :goalRoomMemberId" | ||
+ " AND cf.createdAt >= :start" | ||
+ " AND cf.createdAt < :end") | ||
Optional<CheckFeed> findByGoalRoomMemberIdAndDateTime(final Long goalRoomMemberId, final LocalDateTime start, | ||
final LocalDateTime end); | ||
|
||
@Query("SELECT COUNT(cf)" | ||
+ " FROM CheckFeed cf" | ||
+ " WHERE cf.goalRoomMemberId = :goalRoomMemberId" | ||
+ " AND cf.goalRoomRoadmapNodeId = :goalRoomRoadmapNodeId") | ||
int countByGoalRoomMemberIdAndGoalRoomRoadmapNodeId(final Long goalRoomMemberId, final Long goalRoomRoadmapNodeId); | ||
|
||
@Query(value = "SELECT cf.* FROM check_feed as cf " | ||
+ "LEFT JOIN goal_room_member as gm ON cf.goal_room_member_id = gm.id " | ||
+ "JOIN goal_room as g ON gm.goal_room_id = g.id " | ||
+ "WHERE g.id = :goalRoomId " | ||
+ "ORDER BY cf.created_at DESC ", nativeQuery = true) | ||
List<CheckFeed> findByGoalRoomIdOrderByCreatedAtDesc(@Param("goalRoomId") final Long goalRoomId); | ||
|
||
List<CheckFeed> findByGoalRoomRoadmapNodeIdOrderByCreatedAtDesc(final Long goalRoomRoadmapNodeId); | ||
} |
60 changes: 60 additions & 0 deletions
60
...d/kirikiri/src/main/java/co/kirikiri/checkfeed/service/DashBoardCheckFeedServiceImpl.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,60 @@ | ||
package co.kirikiri.checkfeed.service; | ||
|
||
import co.kirikiri.checkfeed.domain.CheckFeed; | ||
import co.kirikiri.checkfeed.persistence.CheckFeedRepository; | ||
import co.kirikiri.common.aop.ExceptionConvert; | ||
import co.kirikiri.common.service.FileService; | ||
import co.kirikiri.goalroom.domain.GoalRoom; | ||
import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; | ||
import co.kirikiri.goalroom.service.DashBoardCheckFeedService; | ||
import co.kirikiri.goalroom.service.dto.response.DashBoardCheckFeedResponse; | ||
import java.net.URL; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
@ExceptionConvert | ||
public class DashBoardCheckFeedServiceImpl implements DashBoardCheckFeedService { | ||
|
||
private final CheckFeedRepository checkFeedRepository; | ||
private final FileService fileService; | ||
|
||
@Override | ||
@Transactional(readOnly = true) | ||
public List<DashBoardCheckFeedResponse> findCheckFeedsByNodeAndGoalRoomStatus(final GoalRoom goalRoom, | ||
final Optional<GoalRoomRoadmapNode> currentGoalRoomRoadmapNode) { | ||
final List<CheckFeed> checkFeeds = findCheckFeeds(goalRoom, currentGoalRoomRoadmapNode); | ||
return makeCheckFeedResponses(checkFeeds); | ||
} | ||
|
||
private List<CheckFeed> findCheckFeeds(final GoalRoom goalRoom, | ||
final Optional<GoalRoomRoadmapNode> currentGoalRoomRoadmapNode) { | ||
if (goalRoom.isCompleted()) { | ||
return checkFeedRepository.findByGoalRoomIdOrderByCreatedAtDesc(goalRoom.getId()); | ||
} | ||
if (goalRoom.isRunning() && currentGoalRoomRoadmapNode.isPresent()) { | ||
return checkFeedRepository.findByGoalRoomRoadmapNodeIdOrderByCreatedAtDesc( | ||
currentGoalRoomRoadmapNode.get().getId()); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
private List<DashBoardCheckFeedResponse> makeCheckFeedResponses(final List<CheckFeed> checkFeeds) { | ||
return checkFeeds.stream() | ||
.map(this::makeCheckFeedResponse) | ||
.toList(); | ||
} | ||
|
||
private DashBoardCheckFeedResponse makeCheckFeedResponse(final CheckFeed checkFeed) { | ||
final URL checkFeedImageUrl = fileService.generateUrl(checkFeed.getServerFilePath(), HttpMethod.GET); | ||
return new DashBoardCheckFeedResponse(checkFeed.getId(), checkFeedImageUrl.toExternalForm(), | ||
checkFeed.getDescription(), checkFeed.getCreatedAt().toLocalDate()); | ||
} | ||
} |
Oops, something went wrong.