Skip to content

Commit

Permalink
Merge pull request #44 from Team-Tiki/feat/#38-time-blocks
Browse files Browse the repository at this point in the history
[FEAT] 타임라인 조회
  • Loading branch information
Chan531 authored Jul 12, 2024
2 parents 3707bcd + ae989e8 commit 5f3bec3
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.tiki.server.document.adapter;

import java.util.List;

import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.document.entity.Document;
import com.tiki.server.document.repository.DocumentRepository;
import com.tiki.server.document.vo.DocumentVO;

import lombok.RequiredArgsConstructor;

Expand All @@ -10,4 +14,8 @@
public class DocumentFinder {

private final DocumentRepository documentRepository;

public List<DocumentVO> findAllByTimeBlockId(long timeBlockId) {
return documentRepository.findAllByTimeBlockId(timeBlockId).stream().map(DocumentVO::from).toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.tiki.server.document.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import com.tiki.server.document.entity.Document;

public interface DocumentRepository extends JpaRepository<Document, Long> {
List<Document> findAllByTimeBlockId(long timeBlockId);
}
24 changes: 24 additions & 0 deletions src/main/java/com/tiki/server/document/vo/DocumentVO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.tiki.server.document.vo;

import static lombok.AccessLevel.PRIVATE;

import com.tiki.server.document.entity.Document;

import lombok.Builder;
import lombok.NonNull;

@Builder(access = PRIVATE)
public record DocumentVO(
long documentId,
@NonNull String fileName,
@NonNull String fileUrl
) {

public static DocumentVO from(Document document) {
return DocumentVO.builder()
.documentId(document.getId())
.fileName(document.getFileName())
.fileUrl(document.getFileUrl())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.tiki.server.timeblock.adapter;

import java.util.List;

import com.tiki.server.common.entity.Position;
import com.tiki.server.common.support.RepositoryAdapter;
import com.tiki.server.team.entity.Team;
import com.tiki.server.timeblock.repository.TimeBlockRepository;
import com.tiki.server.timeblock.vo.TimeBlockVO;

import lombok.RequiredArgsConstructor;

Expand All @@ -10,4 +15,14 @@
public class TimeBlockFinder {

private final TimeBlockRepository timeBlockRepository;

public List<TimeBlockVO> findByTeamAndAccessiblePositionAndDate(
long teamId,
String accessiblePosition,
String date
) {
return timeBlockRepository.findByTeamAndAccessiblePositionAndDate(teamId, accessiblePosition, date).stream()
.map(TimeBlockVO::from)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import static com.tiki.server.common.dto.SuccessResponse.*;
import static com.tiki.server.timeblock.message.SuccessMessage.SUCCESS_CREATE_TIME_BLOCK;
import static com.tiki.server.timeblock.message.SuccessMessage.SUCCESS_GET_TIMELINE;

import java.security.Principal;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -16,8 +18,9 @@
import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.common.support.UriGenerator;
import com.tiki.server.timeblock.controller.docs.TimeBlockControllerDocs;
import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest;
import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse;
import com.tiki.server.timeblock.dto.request.TimeBlockCreateRequest;
import com.tiki.server.timeblock.dto.response.TimeBlockCreateResponse;
import com.tiki.server.timeblock.dto.response.TimelineGetResponse;
import com.tiki.server.timeblock.service.TimeBlockService;

import lombok.RequiredArgsConstructor;
Expand All @@ -32,16 +35,29 @@ public class TimeBlockController implements TimeBlockControllerDocs {

@Override
@PostMapping("/team/{teamId}/time-block")
public ResponseEntity<SuccessResponse<TimeBlockCreationResponse>> createTimeBlock(
public ResponseEntity<SuccessResponse<TimeBlockCreateResponse>> createTimeBlock(
Principal principal,
@PathVariable long teamId,
@RequestParam String type,
@RequestBody TimeBlockCreationRequest request
@RequestBody TimeBlockCreateRequest request
) {
val memberId = Long.parseLong(principal.getName());
val response = timeBlockService.createTimeBlock(memberId, teamId, type, request);
return ResponseEntity.created(
UriGenerator.getUri("/api/v1/time-blocks/team/" + teamId + "/time-block")
).body(success(SUCCESS_CREATE_TIME_BLOCK.getMessage(), response));
}

@Override
@GetMapping("team/{teamId}/timeline")
public ResponseEntity<SuccessResponse<TimelineGetResponse>> getTimeline(
Principal principal,
@PathVariable long teamId,
@RequestParam String type,
@RequestParam String date
) {
val memberId = Long.parseLong(principal.getName());
val response = timeBlockService.getTimeline(memberId, teamId, type, date);
return ResponseEntity.ok().body(success(SUCCESS_GET_TIMELINE.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

import com.tiki.server.common.dto.ErrorResponse;
import com.tiki.server.common.dto.SuccessResponse;
import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest;
import com.tiki.server.timeblock.dto.response.TimeBlockCreationResponse;
import com.tiki.server.timeblock.dto.request.TimeBlockCreateRequest;
import com.tiki.server.timeblock.dto.response.TimeBlockCreateResponse;
import com.tiki.server.timeblock.dto.response.TimelineGetResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand Down Expand Up @@ -56,7 +57,7 @@ public interface TimeBlockControllerDocs {
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<TimeBlockCreationResponse>> createTimeBlock(
ResponseEntity<SuccessResponse<TimeBlockCreateResponse>> createTimeBlock(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "teamId",
Expand All @@ -71,6 +72,62 @@ ResponseEntity<SuccessResponse<TimeBlockCreationResponse>> createTimeBlock(
in = ParameterIn.QUERY,
example = "executive, member"
) @RequestParam String type,
@RequestBody TimeBlockCreationRequest request
@RequestBody TimeBlockCreateRequest request
);

@Operation(
summary = "타임라인 조회",
description = "타임라인을 조회한다.",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공",
content = @Content(schema = @Schema(implementation = SuccessResponse.class))),
@ApiResponse(
responseCode = "400",
description = "타입 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "403",
description = "접근 권한 없음",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "404",
description = "팀에 존재하지 않는 회원",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "404",
description = "유효하지 않은 팀",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<TimelineGetResponse>> getTimeline(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "teamId",
description = "팀 id",
in = ParameterIn.PATH,
example = "1"
)
@PathVariable long teamId,
@Parameter(
name = "type",
description = "타임라인 타입",
in = ParameterIn.QUERY,
example = "executive, member"
) @RequestParam String type,
@Parameter(
name = "date",
description = "조회할 타임라인의 년도와 월 정보",
in = ParameterIn.QUERY,
example = "2024-07"
) @RequestParam String date
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import lombok.NonNull;

public record TimeBlockCreationRequest(
public record TimeBlockCreateRequest(
@NonNull String name,
@NonNull String color,
@NonNull LocalDate startDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import lombok.Builder;

@Builder(access = PRIVATE)
public record TimeBlockCreationResponse(
public record TimeBlockCreateResponse(
long timeBlockId
) {

public static TimeBlockCreationResponse of(long timeBlockId) {
return TimeBlockCreationResponse.builder()
public static TimeBlockCreateResponse of(long timeBlockId) {
return TimeBlockCreateResponse.builder()
.timeBlockId(timeBlockId)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.tiki.server.timeblock.dto.response;

import static lombok.AccessLevel.PRIVATE;

import java.time.LocalDate;
import java.util.List;

import com.tiki.server.timeblock.vo.TimeBlockVO;

import lombok.Builder;
import lombok.NonNull;

@Builder(access = PRIVATE)
public record TimelineGetResponse(
List<TimeBlockGetResponse> timeBlocks
) {

public static TimelineGetResponse from(List<TimeBlockVO> timeBlockVOs) {
return TimelineGetResponse.builder()
.timeBlocks(timeBlockVOs.stream().map(TimeBlockGetResponse::from).toList())
.build();
}

@Builder(access = PRIVATE)
public record TimeBlockGetResponse(
long timeBlockId,
@NonNull String name,
@NonNull String color,
@NonNull LocalDate startDate,
@NonNull LocalDate endDate
) {

public static TimeBlockGetResponse from(TimeBlockVO timeBlockVO) {
return TimeBlockGetResponse.builder()
.timeBlockId(timeBlockVO.timeBlockId())
.name(timeBlockVO.name())
.color(timeBlockVO.color())
.startDate(timeBlockVO.startDate())
.endDate(timeBlockVO.endDate())
.build();
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.tiki.server.common.entity.BaseTime;
import com.tiki.server.common.entity.Position;
import com.tiki.server.team.entity.Team;
import com.tiki.server.timeblock.dto.request.TimeBlockCreationRequest;
import com.tiki.server.timeblock.dto.request.TimeBlockCreateRequest;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -52,7 +52,7 @@ public class TimeBlock extends BaseTime {
@JoinColumn(name = "team_id")
private Team team;

public static TimeBlock of(Team team, Position accessiblePosition, TimeBlockCreationRequest request) {
public static TimeBlock of(Team team, Position accessiblePosition, TimeBlockCreateRequest request) {
return TimeBlock.builder()
.name(request.name())
.color(request.color())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@RequiredArgsConstructor
public enum SuccessMessage {

SUCCESS_CREATE_TIME_BLOCK("타임 블록 생성 성공");
SUCCESS_CREATE_TIME_BLOCK("타임 블록 생성 성공"),
SUCCESS_GET_TIMELINE("타임라인 조회 성공");

private final String message;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.tiki.server.timeblock.repository;

import org.springframework.data.repository.CrudRepository;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.tiki.server.timeblock.entity.TimeBlock;

public interface TimeBlockRepository extends CrudRepository<TimeBlock, Long> {
public interface TimeBlockRepository extends JpaRepository<TimeBlock, Long> {

@Query(value = "select * from time_block "
+ "where team_id = :teamId and accessible_position = :position and to_char(created_at, 'YYYY-MM') = :date "
+ "order by start_date DESC", nativeQuery = true)
List<TimeBlock> findByTeamAndAccessiblePositionAndDate(long teamId, String position, String date);
}
Loading

0 comments on commit 5f3bec3

Please sign in to comment.