Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ dependencies {

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.testcontainers:testcontainers:1.19.3'
testImplementation 'org.testcontainers:testcontainers:1.21.4'
testImplementation 'org.testcontainers:junit-jupiter:1.19.3'
testImplementation 'org.testcontainers:mysql'
testImplementation 'org.testcontainers:localstack'
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package in.koreatech.koin.domain.callvan.controller;

import static in.koreatech.koin.domain.user.model.UserType.STUDENT;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import in.koreatech.koin.domain.callvan.dto.CallvanPostCreateRequest;
import in.koreatech.koin.domain.callvan.dto.CallvanPostCreateResponse;
import in.koreatech.koin.domain.callvan.dto.CallvanPostDetailResponse;
import in.koreatech.koin.domain.callvan.dto.CallvanPostSearchResponse;
import in.koreatech.koin.domain.callvan.dto.CallvanUserReportCreateRequest;
import in.koreatech.koin.domain.callvan.model.enums.CallvanLocation;
import in.koreatech.koin.domain.callvan.model.filter.CallvanAuthorFilter;
import in.koreatech.koin.domain.callvan.model.filter.CallvanPostSortCriteria;
import in.koreatech.koin.domain.callvan.model.filter.CallvanPostStatusFilter;
import in.koreatech.koin.domain.callvan.service.CallvanPostQueryService;
import in.koreatech.koin.domain.callvan.service.CallvanPostCreateService;
import in.koreatech.koin.domain.callvan.service.CallvanPostJoinService;
import in.koreatech.koin.domain.callvan.service.CallvanPostStatusService;
import in.koreatech.koin.domain.callvan.service.CallvanChatService;
import in.koreatech.koin.domain.callvan.service.CallvanNotificationService;
import in.koreatech.koin.domain.callvan.service.CallvanUserReportService;
import in.koreatech.koin.domain.callvan.dto.CallvanChatMessageRequest;
import in.koreatech.koin.domain.callvan.dto.CallvanNotificationResponse;
import in.koreatech.koin.domain.callvan.dto.CallvanChatMessageResponse;
import in.koreatech.koin.global.auth.Auth;
import in.koreatech.koin.global.auth.UserId;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;

@RestController
@RequestMapping("/callvan")
@RequiredArgsConstructor
public class CallvanController implements CallvanApi {

private final CallvanPostCreateService callvanPostCreateService;
private final CallvanPostQueryService callvanPostQueryService;
private final CallvanPostJoinService callvanPostJoinService;
private final CallvanPostStatusService callvanPostStatusService;
private final CallvanChatService callvanChatService;
private final CallvanNotificationService callvanNotificationService;
private final CallvanUserReportService callvanUserReportService;

@PostMapping
public ResponseEntity<CallvanPostCreateResponse> createCallvanPost(
@RequestBody CallvanPostCreateRequest request,
Integer userId
) {
CallvanPostCreateResponse response = callvanPostCreateService.createCallvanPost(request, userId);
return ResponseEntity.status(HttpStatus.CREATED).body(response);
}

@GetMapping
public ResponseEntity<CallvanPostSearchResponse> getCallvanPosts(
CallvanAuthorFilter author,
List<CallvanLocation> departures,
String departureKeyword,
List<CallvanLocation> arrivals,
String arrivalKeyword,
List<CallvanPostStatusFilter> statuses,
String title,
CallvanPostSortCriteria sort,
Integer page,
Integer limit,
@UserId Integer userId
) {
CallvanPostSearchResponse response = callvanPostQueryService.getCallvanPosts(
author, departures, departureKeyword, arrivals, arrivalKeyword, statuses, title, sort, page, limit,
userId);
return ResponseEntity.ok().body(response);
}

@GetMapping("/posts/{postId}")
public ResponseEntity<CallvanPostDetailResponse> getCallvanPostDetail(
@PathVariable Integer postId,
@UserId Integer userId
) {
CallvanPostDetailResponse response = callvanPostQueryService.getCallvanPostDetail(postId, userId);
return ResponseEntity.ok(response);
}

@PostMapping("/posts/{postId}/participants")
public ResponseEntity<Void> joinCallvanPost(
@PathVariable Integer postId,
@UserId Integer userId
) {
callvanPostJoinService.join(postId, userId);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@DeleteMapping("/posts/{postId}/participants")
public ResponseEntity<Void> leaveCallvanPost(
@PathVariable Integer postId,
@UserId Integer userId
) {
callvanPostJoinService.leave(postId, userId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

@PostMapping("/posts/{postId}/reports")
public ResponseEntity<Void> reportCallvanUser(
@PathVariable Integer postId,
@RequestBody @Valid CallvanUserReportCreateRequest request,
@Auth(permit = {STUDENT}) Integer userId
) {
callvanUserReportService.reportUser(postId, userId, request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@GetMapping("/posts/{postId}/chat")
public ResponseEntity<CallvanChatMessageResponse> getCallvanChatMessages(
@PathVariable Integer postId,
@UserId Integer userId
) {
CallvanChatMessageResponse response = callvanChatService.getMessages(postId, userId);
return ResponseEntity.ok(response);
}

@PostMapping("/posts/{postId}/chat")
public ResponseEntity<Void> sendMessage(
@PathVariable Integer postId,
@RequestBody CallvanChatMessageRequest request,
@UserId Integer userId
) {
callvanChatService.sendMessage(postId, userId, request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@PutMapping("/posts/{postId}/close")
public ResponseEntity<Void> closeCallvanPost(
@PathVariable Integer postId,
@UserId Integer userId
) {
callvanPostStatusService.close(postId, userId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

@PutMapping("/posts/{postId}/reopen")
public ResponseEntity<Void> reopenCallvanPost(
@PathVariable Integer postId,
@UserId Integer userId
) {
callvanPostStatusService.reopen(postId, userId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

@PutMapping("/posts/{postId}/complete")
public ResponseEntity<Void> completeCallvanPost(
@PathVariable Integer postId,
@UserId Integer userId
) {
callvanPostStatusService.complete(postId, userId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

@GetMapping("/notifications")
public ResponseEntity<List<CallvanNotificationResponse>> getNotifications(
@Auth(permit = {STUDENT}) Integer userId
) {
List<CallvanNotificationResponse> responses = callvanNotificationService.getNotifications(userId);
return ResponseEntity.ok(responses);
}

@PostMapping("/notifications/mark-all-read")
public ResponseEntity<Void> markAllNotificationsAsRead(
@Auth(permit = {STUDENT}) Integer userId
) {
callvanNotificationService.markAllRead(userId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package in.koreatech.koin.domain.callvan.dto;

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

@JsonNaming(SnakeCaseStrategy.class)
public record CallvanChatMessageRequest(
@Schema(description = "메시지 내용 (텍스트 또는 이미지 URL)", example = "안녕하세요!")
@NotNull(message = "메시지 내용은 필수입니다.")
String content,

@Schema(description = "이미지 여부", example = "false")
@JsonProperty("is_image")
@NotNull(message = "이미지 여부는 필수입니다.")
Boolean isImage
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package in.koreatech.koin.domain.callvan.dto;

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;

import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;

import org.springframework.util.StringUtils;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import in.koreatech.koin.domain.callvan.model.CallvanChatMessage;
import in.koreatech.koin.domain.callvan.model.CallvanPost;
import io.swagger.v3.oas.annotations.media.Schema;

@JsonNaming(SnakeCaseStrategy.class)
public record CallvanChatMessageResponse(
@Schema(description = "채팅방 이름", example = "별관동 -> 천안역 (14:00) (4명)")
String roomName,

@Schema(description = "메시지 목록")
List<CallvanMessageDto> messages
) {

public static CallvanChatMessageResponse of(CallvanPost post, List<CallvanChatMessage> messages, Integer userId) {
Comment on lines 25 to 27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

줄넘김 이슈

String departure = post.getDepartureType().getName();
if (StringUtils.hasText(post.getDepartureCustomName())) {
departure = post.getDepartureCustomName();
}

String arrival = post.getArrivalType().getName();
if (StringUtils.hasText(post.getArrivalCustomName())) {
arrival = post.getArrivalCustomName();
}

String time = post.getDepartureTime().format(DateTimeFormatter.ofPattern("HH:mm"));
String roomName = String.format("%s -> %s (%s) (%d명)",
departure, arrival, time, post.getMaxParticipants());

List<CallvanMessageDto> messageDtos = messages.stream()
.map(msg -> CallvanMessageDto.from(msg, userId))
.toList();

return new CallvanChatMessageResponse(roomName, messageDtos);
}

@JsonNaming(SnakeCaseStrategy.class)
public record CallvanMessageDto(
@Schema(description = "작성자 ID", example = "1")
Integer userId,

@Schema(description = "작성자 닉네임", example = "익명_12345")
String senderNickname,

@Schema(description = "메시지 내용", example = "안녕하세요!")
String content,

@Schema(description = "작성 날짜", example = "2024. 03. 24")
String date,

@Schema(description = "작성 시간", example = "오후 2:00")
String time,

@Schema(description = "이미지 여부", example = "false")
Boolean isImage,

@Schema(description = "퇴장 유저 여부", example = "false")
Boolean isLeftUser,

@Schema(description = "내 메시지 여부", example = "true")
Boolean isMine
) {

public static CallvanMessageDto from(CallvanChatMessage message, Integer currentUserId) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

줄넘김 이슈

return new CallvanMessageDto(
message.getSender().getId(),
message.getSenderNickname(),
message.getContent(),
message.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy. MM. dd")),
message.getCreatedAt().format(DateTimeFormatter.ofPattern("a h:mm").withLocale(Locale.KOREAN)),
message.getIsImage(),
message.getIsLeftUser(),
message.getSender().getId().equals(currentUserId));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package in.koreatech.koin.domain.callvan.dto;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

import org.springframework.util.StringUtils;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import in.koreatech.koin.domain.callvan.model.CallvanNotification;
import in.koreatech.koin.domain.callvan.model.enums.CallvanNotificationType;
import io.swagger.v3.oas.annotations.media.Schema;

@JsonNaming(SnakeCaseStrategy.class)
public record CallvanNotificationResponse(
@Schema(description = "알림 ID", example = "1")
Integer id,

@Schema(description = "알림 타입", example = "RECRUITMENT_COMPLETE")
CallvanNotificationType type,

@Schema(description = "메시지 미리보기", example = "해당 콜벤팟 인원이 모두 모집되었습니다.")
String messagePreview,

@Schema(description = "읽음 여부", example = "false")
Boolean isRead,

@Schema(description = "생성 일시", example = "2024-03-24 14:00:00")
LocalDateTime createdAt,

@Schema(description = "콜벤 게시글 ID", example = "1")
Integer postId,

@Schema(description = "출발지", example = "복지관")
String departure,

@Schema(description = "도착지", example = "천안역")
String arrival,

@Schema(description = "출발 날짜", example = "2024-03-24")
LocalDate departureDate,

@Schema(description = "출발 시간", example = "14:00")
LocalTime departureTime,

@Schema(description = "현재 모집 인원", example = "2")
Integer currentParticipants,

@Schema(description = "최대 모집 인원", example = "4")
Integer maxParticipants,

@Schema(description = "발신자 닉네임", example = "익명_123")
String senderNickname,

@Schema(description = "참여자 닉네임", example = "익명_456")
String joinedMemberNickname
) {

public static CallvanNotificationResponse from(CallvanNotification notification) {
String departureName = notification.getDepartureType().getName();
if (StringUtils.hasText(notification.getDepartureCustomName())) {
departureName = notification.getDepartureCustomName();
}

String arrivalName = notification.getArrivalType().getName();
if (StringUtils.hasText(notification.getArrivalCustomName())) {
arrivalName = notification.getArrivalCustomName();
}

return new CallvanNotificationResponse(
notification.getId(),
notification.getNotificationType(),
notification.getMessagePreview(),
notification.getIsRead(),
notification.getCreatedAt(),
notification.getPost() != null ? notification.getPost().getId() : null,
departureName,
arrivalName,
notification.getDepartureDate(),
notification.getDepartureTime(),
notification.getCurrentParticipants(),
notification.getMaxParticipants(),
notification.getSenderNickname(),
notification.getJoinedMemberNickname()
);
}
}
Loading
Loading