Skip to content

Commit

Permalink
Merge pull request #11 from Da2om/develop
Browse files Browse the repository at this point in the history
[fix] :: (body확인)
  • Loading branch information
heunseoRyu authored Nov 3, 2024
2 parents c26edd7 + f540861 commit ccbeda3
Show file tree
Hide file tree
Showing 77 changed files with 1,513 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.project.dasomapi.board.handler;

import com.project.dasomapi.board.usecase.BoardUseCase;
import com.project.dasomapi.board.usecase.req.BoardReq;
import com.project.dasomapi.common.Response;
import com.project.dasomapi.common.ResponseData;
import com.project.dasomapi.inq.handler.req.SaveInqReq;
import com.project.dasomcore.board.application.res.BoardRes;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 java.util.List;

@RestController
@RequestMapping("/board")
@RequiredArgsConstructor
public class BoardController {

private final BoardUseCase useCase;

@PostMapping("")
@Operation(summary = "공지 저장", description = "공지 저장(teacher)")
public Response register(
@RequestBody BoardReq req
){
return useCase.register(req);
}

@GetMapping("")
@Operation(summary = "공지 리스트 조회", description = "공지 리스트 조회(teacher)")
public ResponseData<List<BoardRes>> getBoards(
){
return useCase.getBoards();
}

@PatchMapping("/{id}")
@Operation(summary = "공지 수정", description = "공지 수정(teacher)")
public Response modify(
@PathVariable("id") Long id,
@RequestBody BoardReq req
){
return useCase.modify(id,req);
}

@DeleteMapping("/{id}")
@Operation(summary = "공지 삭제", description = "공지 삭제(teacher)")
public Response remove(
@PathVariable("id") Long id
){
return useCase.remove(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.project.dasomapi.board.usecase;

import com.project.dasomapi.board.usecase.req.BoardReq;
import com.project.dasomapi.common.Response;
import com.project.dasomapi.common.ResponseData;
import com.project.dasomcore.board.application.BoardService;
import com.project.dasomcore.board.application.res.BoardRes;
import com.project.dasomcore.board.domain.entity.Board;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class BoardUseCase {

private final BoardService boardService;

public Response register(BoardReq req) {
boardService.save(req.toEntity());
return Response.created("공지 저장 성공");
}

public ResponseData<List<BoardRes>> getBoards() {
List<BoardRes> res = boardService.getBoards();
return ResponseData.ok("공지 리스트 조회 성공",res);
}

public Response modify(Long boardId, BoardReq req) {
Board board = boardService.getById(boardId);
board.update(req.title(),req.content());
return Response.ok("공지 수정 성공");
}

public Response remove(Long id) {
boardService.deleteById(id);
return Response.ok("공지 삭제 성공");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.project.dasomapi.board.usecase.req;

import com.project.dasomcore.board.domain.entity.Board;

import java.time.LocalDateTime;

public record BoardReq(
String title,
String content
) {
public Board toEntity() {
return Board.builder()
.title(this.title)
.content(this.content)
.writtenDt(LocalDateTime.now()).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.project.dasomapi.bus.handler;

import com.project.dasomapi.bus.usecase.BusUseCase;
import com.project.dasomapi.bus.usecase.req.ModifyBusReq;
import com.project.dasomapi.bus.usecase.req.RegisterBusReq;
import com.project.dasomapi.common.Response;
import com.project.dasomapi.common.ResponseData;
import com.project.dasomcore.bus.application.res.BusRes;
import com.project.dasomcore.bus.application.res.MyBusRes;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 java.util.List;

@RestController
@RequestMapping("/bus")
@RequiredArgsConstructor
public class BusController {

private final BusUseCase busUseCase;

@PostMapping("")
@Operation(summary = "버스 신청", description = "버스 탑승 신청 (parent)")
public Response register(
@RequestBody RegisterBusReq req
){
return busUseCase.register(req);
}

@GetMapping("/my")
@Operation(summary = "내 버스 요청", description = "내 버스 탑승 신청 리스트 (parent)")
public ResponseData<List<MyBusRes>> getMyBus(){
return busUseCase.getMyBus();
}

@GetMapping("")
@Operation(summary = "버스 신청명단 조회", description = "버스 신청명단 조회 가능 (teacher)")
public ResponseData<List<BusRes>> getBusList(){
return busUseCase.getBusList();
}

@GetMapping("/modified")
@Operation(summary = "버스 수정명단 조회", description = "버스 수정명단 조회 가능 (teacher)")
public ResponseData<List<BusRes>> getModifiedBusList(){
return busUseCase.getModifiedBusList();
}

@PatchMapping("/{id}")
@Operation(summary = "버스 신청 수정", description = "버스 탑승 신청 수정(parent)")
public Response modify(
@PathVariable("id") Long id,
@RequestBody ModifyBusReq req
){
return busUseCase.modify(id,req);
}

@DeleteMapping("/{id}")
@Operation(summary = "버스 신청 삭제", description = "버스 탑승 신청 삭제(parent)")
public Response remove(
@PathVariable("id") Long id
){
return busUseCase.remove(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.project.dasomapi.bus.usecase;

import com.project.dasomapi.bus.usecase.req.ModifyBusReq;
import com.project.dasomapi.bus.usecase.req.RegisterBusReq;
import com.project.dasomapi.common.Response;
import com.project.dasomapi.common.ResponseData;
import com.project.dasomcore.bus.application.BusService;
import com.project.dasomcore.bus.application.res.BusRes;
import com.project.dasomcore.bus.application.res.MyBusRes;
import com.project.dasomcore.bus.domain.entity.Bus;
import com.project.dasomcore.child.application.ChildService;
import com.project.dasomcore.child.domain.entity.Child;
import com.project.dasomcore.member.application.MemberSessionHolder;
import com.project.dasomcore.member.domain.entity.Member;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class BusUseCase {

private final BusService busService;
private final MemberSessionHolder memberSessionHolder;
private final ChildService childService;

public Response register(RegisterBusReq req) {
Member member = memberSessionHolder.current();
Child child = childService.getById(req.busId());
busService.save(req.toEntity(member,child));
return Response.created("버스 신청 성공");
}

public ResponseData<List<MyBusRes>> getMyBus() {
Member member = memberSessionHolder.current();
List<MyBusRes> res = busService.getMyBus(member);
return ResponseData.ok("내 탑승신청 조회 성공",res);
}

public ResponseData<List<BusRes>> getBusList() {
List<BusRes> res = busService.getBusList();
return ResponseData.ok("버스 신청명단 조회 성공",res);
}

public ResponseData<List<BusRes>> getModifiedBusList() {
List<BusRes> res = busService.getModifiedBusList();
return ResponseData.ok("버스 수정명단 조회 성공",res);
}

public Response modify(Long id, ModifyBusReq req) {
Bus bus = busService.getById(id);
bus.update(req.boardTime(),req.isBoard());
return Response.ok("탑승 신청 수정 성공");
}

public Response remove(Long id) {
busService.deleteById(id);
return Response.ok("탑승 신청 삭제 성공");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.project.dasomapi.bus.usecase.req;

import java.time.LocalDateTime;

public record ModifyBusReq(
LocalDateTime boardTime,
boolean isBoard
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.project.dasomapi.bus.usecase.req;

import com.project.dasomcore.bus.domain.entity.Bus;
import com.project.dasomcore.child.domain.entity.Child;
import com.project.dasomcore.member.domain.entity.Member;

import java.time.LocalDateTime;

public record RegisterBusReq(
Long busId,
Long childId,
LocalDateTime boardTime,
boolean isBoard
) {
public Bus toEntity(Member member, Child child) {
return Bus.builder()
.busId(this.busId)
.boardTime(this.boardTime)
.isBoard(this.isBoard)
.member(member)
.child(child).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
package com.project.dasomapi.chat.handler;

import com.project.dasomapi.chat.usecase.ChatMessage;
import com.project.dasomapi.chat.usecase.ChatUseCase;
import com.project.dasomcore.chat.domain.entity.Chat;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Controller
@RequiredArgsConstructor
@Tag(name = "채팅", description = "채팅 API")
public class ChatController {

private final SimpMessageSendingOperations messagingTemplate;
private final ChatUseCase chatUseCase;

@MessageMapping("/sendMessage") // 클라이언트가 "/app/sendMessage"로 메시지를 보내면 호출됨.
// @SendTo("/topic/public") // 해당 채널을 구독한 클라이언트에게 메시지 전송
@Operation(summary = "메시지 전송", description = "메시지 전송")
public void sendMessage(ChatMessage message) {
messagingTemplate.convertAndSend("/topic/chat/room/" + message.getRoomId(), message);
// /topic/chat/room/{roomId} + payload 데이터(message) 를 해당 채널을 구독하 클라이언트에게 메시지 전송
@MessageMapping("/{roomId}") //여기로 전송되면 메서드 호출 -> WebSocketConfig prefixes 에서 적용한건 앞에 생략
@SendTo("/room/{roomId}") //구독하고 있는 장소로 메시지 전송 (목적지) -> WebSocketConfig Broker 에서 적용한건 앞에 붙어줘야됨
public ChatMessage chat(@DestinationVariable Long roomId, ChatMessage message) {

//채팅 저장
Chat chat = chatUseCase.createChat(roomId, message.getSender(), message.getSenderEmail(), message.getMessage());
return ChatMessage.builder()
.roomId(roomId)
.sender(chat.getSender())
.senderEmail(chat.getSenderEmail())
.message(chat.getMessage())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.project.dasomapi.chat.handler;


import com.project.dasomapi.chat.usecase.ChatUseCase;
import com.project.dasomcore.chat.application.ChatService;
import com.project.dasomcore.chat.domain.entity.ChatRoom;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class ChatRoomController {
private final ChatUseCase chatUseCase;

/**
* 채팅방 리스트 보기
*/
@GetMapping("/roomList")
public List<ChatRoom> roomList() {
return chatUseCase.findAllRoom();
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package com.project.dasomapi.chat.usecase;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ChatMessage {
private String roomId;
private String name;

private Long roomId;
private String sender;
private String senderEmail;
private String message;
private LocalDateTime sendDate;

}
Loading

0 comments on commit ccbeda3

Please sign in to comment.