Skip to content

Commit

Permalink
Merge pull request #246 from techeer-sv/BE/#245
Browse files Browse the repository at this point in the history
BE/#245 쪽지 상제 조회 기능 구현
  • Loading branch information
youKeon committed Oct 1, 2023
2 parents 1d22b1e + 875a67f commit 2e1e8b8
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.graphy.backend.domain.auth.util.annotation.CurrentUser;
import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.message.dto.request.CreateMessageRequest;
import com.graphy.backend.domain.message.dto.response.GetMessageDetailResponse;
import com.graphy.backend.domain.message.service.MessageService;
import com.graphy.backend.global.result.ResultCode;
import com.graphy.backend.global.result.ResultResponse;
Expand All @@ -13,10 +14,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
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 org.springframework.web.bind.annotation.*;

@Tag(name = "MessageController", description = "쪽지 관련 API")
@RestController
Expand All @@ -33,4 +31,10 @@ public ResponseEntity<ResultResponse> messageAdd(@Validated @RequestBody CreateM
.body(ResultResponse.of(ResultCode.MESSAGE_CREATE_SUCCESS));
}

@Operation(summary = "findMessage", description = "쪽지 상세 조회")
@GetMapping("/{messageId}")
public ResponseEntity<ResultResponse> messageDetails(@PathVariable Long messageId) {
GetMessageDetailResponse result = messageService.findMessageById(messageId);
return ResponseEntity.ok(ResultResponse.of(ResultCode.MESSAGE_GET_SUCCESS, result));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.graphy.backend.domain.message.domain;

import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.global.common.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -13,7 +14,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Message {
public class Message extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.graphy.backend.domain.message.dto.response;

import com.graphy.backend.domain.message.domain.Message;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GetMessageDetailResponse {
private Long senderId;
private String memberNickname;
private String content;
private LocalDateTime sentAt;

public static GetMessageDetailResponse from(Message message) {
return GetMessageDetailResponse.builder()
.senderId(message.getSender().getId())
.memberNickname(message.getSender().getNickname())
.content(message.getContent())
.sentAt(message.getCreatedAt())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import com.graphy.backend.domain.member.domain.Member;
import com.graphy.backend.domain.member.service.MemberService;
import com.graphy.backend.domain.message.domain.Message;
import com.graphy.backend.domain.message.dto.request.CreateMessageRequest;
import com.graphy.backend.domain.message.dto.response.GetMessageDetailResponse;
import com.graphy.backend.domain.message.repository.MessageRepository;
import com.graphy.backend.domain.notification.domain.NotificationType;
import com.graphy.backend.domain.notification.dto.NotificationDto;
import com.graphy.backend.domain.notification.service.NotificationService;
import com.graphy.backend.global.error.ErrorCode;
import com.graphy.backend.global.error.exception.EmptyResultException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -30,4 +34,11 @@ public void addMessage(CreateMessageRequest request, Member loginUser) {

notificationService.addNotification(notificationDto, receiver.getId());
}

public GetMessageDetailResponse findMessageById(Long messageId) {
Message message = messageRepository.findById(messageId).orElseThrow(
() -> new EmptyResultException(ErrorCode.MESSAGE_NOT_EXIST)
);
return GetMessageDetailResponse.from(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class ApplicationService {
private final NotificationService notificationService;
private final TagService tagService;

/**
*TODO
* @Transactional 적용
* 중복 지원 방지 로직 추가
*/
public void addApplication(CreateApplicationRequest request, Member loginUser) {
Recruitment recruitment = recruitmentService.getRecruitmentById(request.getRecruitmentId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public enum ErrorCode {
APPLICATION_NOT_EXIST(HttpStatus.NOT_FOUND, "AP001", "존재하지 않는 프로젝트 참가 신청서"),

// ChatGPT,
REQUEST_TOO_MUCH_TOKENS(HttpStatus.BAD_REQUEST, "AI001", "GPT에 보내야 할 요청 길이 제한 초과");
REQUEST_TOO_MUCH_TOKENS(HttpStatus.BAD_REQUEST, "AI001", "GPT에 보내야 할 요청 길이 제한 초과"),

// Message
MESSAGE_NOT_EXIST(HttpStatus.NOT_FOUND, "MSG001", "존재하지 않는 메세지");


private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ public enum ResultCode {
APPLICATION_PAGING_GET_SUCCESS("AP003", "프로젝트 참가 신청서 페이징 조회 성공"),

// Message
MESSAGE_CREATE_SUCCESS("MSG001", "쪽지 전송 성공");



MESSAGE_CREATE_SUCCESS("MSG001", "쪽지 전송 성공"),
MESSAGE_GET_SUCCESS("MSG002", "쪽지 단건 조회 성공");

private final String code;
private final String message;
Expand Down

0 comments on commit 2e1e8b8

Please sign in to comment.