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
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.mtvs.devlinkbackend.channel.controller;

import com.mtvs.devlinkbackend.channel.dto.ChannelRegistRequestDTO;
import com.mtvs.devlinkbackend.channel.dto.ChannelUpdateRequestDTO;
import com.mtvs.devlinkbackend.channel.entity.Channel;
import com.mtvs.devlinkbackend.channel.dto.response.ChannelListResponseDTO;
import com.mtvs.devlinkbackend.channel.dto.request.ChannelRegistRequestDTO;
import com.mtvs.devlinkbackend.channel.dto.response.ChannelSingleResponseDTO;
import com.mtvs.devlinkbackend.channel.dto.request.ChannelUpdateRequestDTO;
import com.mtvs.devlinkbackend.channel.service.ChannelService;
import com.mtvs.devlinkbackend.util.JwtUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/channel")
public class ChannelController {
Expand All @@ -23,40 +22,39 @@ public ChannelController(ChannelService channelService, JwtUtil jwtUtil) {

// 새 채널 생성
@PostMapping
public ResponseEntity<Channel> createChannel(
public ResponseEntity<ChannelSingleResponseDTO> createChannel(
@RequestBody ChannelRegistRequestDTO channelRegistRequestDTO,
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
Channel savedChannel = channelService.saveChannel(channelRegistRequestDTO, accountId);
ChannelSingleResponseDTO savedChannel = channelService.saveChannel(channelRegistRequestDTO, accountId);
return ResponseEntity.ok(savedChannel);
}

// 모든 채널 조회
@GetMapping
public ResponseEntity<List<Channel>> getAllChannels() {
List<Channel> channels = channelService.findAllChannels();
public ResponseEntity<ChannelListResponseDTO> getAllChannels() {
ChannelListResponseDTO channels = channelService.findAllChannels();
return ResponseEntity.ok(channels);
}

// 특정 채널 조회
@GetMapping("/{channelId}")
public ResponseEntity<Channel> getChannelById(@PathVariable String channelId) {
return channelService.findChannelByChannelId(channelId)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
public ResponseEntity<ChannelSingleResponseDTO> getChannelById(@PathVariable String channelId) {
ChannelSingleResponseDTO channel = channelService.findChannelByChannelId(channelId);
return channel != null ? ResponseEntity.ok(channel) : ResponseEntity.notFound().build();
}

// 채널 업데이트
@PatchMapping
public ResponseEntity<Channel> updateChannel(
public ResponseEntity<ChannelSingleResponseDTO> updateChannel(
@RequestBody ChannelUpdateRequestDTO channelUpdateRequestDTO,
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
try {
Channel updatedChannel = channelService.updateChannel(channelUpdateRequestDTO, accountId);
return ResponseEntity.ok(updatedChannel);
ChannelSingleResponseDTO updatedChannelDTO = channelService.updateChannel(channelUpdateRequestDTO, accountId);
return ResponseEntity.ok(updatedChannelDTO);
} catch (IllegalArgumentException e) {
return ResponseEntity.badRequest().body(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mtvs.devlinkbackend.channel.dto;
package com.mtvs.devlinkbackend.channel.dto.request;

import com.mtvs.devlinkbackend.channel.entity.PositionType;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mtvs.devlinkbackend.channel.dto;
package com.mtvs.devlinkbackend.channel.dto.request;

import com.mtvs.devlinkbackend.channel.entity.PositionType;
import lombok.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mtvs.devlinkbackend.channel.dto.response;

import com.mtvs.devlinkbackend.channel.entity.Channel;
import lombok.*;

import java.util.List;

@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ChannelListResponseDTO {
private List<Channel> data;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mtvs.devlinkbackend.channel.dto.response;

import com.mtvs.devlinkbackend.channel.entity.Channel;
import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ChannelSingleResponseDTO {
private Channel data;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.mtvs.devlinkbackend.channel.service;

import com.mtvs.devlinkbackend.channel.dto.ChannelRegistRequestDTO;
import com.mtvs.devlinkbackend.channel.dto.ChannelUpdateRequestDTO;
import com.mtvs.devlinkbackend.channel.dto.response.ChannelListResponseDTO;
import com.mtvs.devlinkbackend.channel.dto.request.ChannelRegistRequestDTO;
import com.mtvs.devlinkbackend.channel.dto.response.ChannelSingleResponseDTO;
import com.mtvs.devlinkbackend.channel.dto.request.ChannelUpdateRequestDTO;
import com.mtvs.devlinkbackend.channel.entity.Channel;
import com.mtvs.devlinkbackend.channel.repository.ChannelRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
Expand All @@ -20,33 +21,33 @@ public ChannelService(ChannelRepository channelRepository) {

// 새 채널 저장
@Transactional
public Channel saveChannel(ChannelRegistRequestDTO channelRegistRequestDTO, String accountId) {
return channelRepository.save(new Channel(
public ChannelSingleResponseDTO saveChannel(ChannelRegistRequestDTO channelRegistRequestDTO, String accountId) {
return new ChannelSingleResponseDTO(channelRepository.save(new Channel(
accountId,
channelRegistRequestDTO.getPositionTypes()
));
)));
}

// 모든 채널 조회

public List<Channel> findAllChannels() {
return channelRepository.findAll();
public ChannelListResponseDTO findAllChannels() {
return new ChannelListResponseDTO(channelRepository.findAll());
}

// ID로 특정 채널 조회
public Optional<Channel> findChannelByChannelId(String channelId) {
return channelRepository.findById(channelId);
public ChannelSingleResponseDTO findChannelByChannelId(String channelId) {
return new ChannelSingleResponseDTO(channelRepository.findById(channelId).orElse(null));
}

// ID로 채널 업데이트
@Transactional
public Channel updateChannel(ChannelUpdateRequestDTO channelUpdateRequestDTO, String accountId) {
public ChannelSingleResponseDTO updateChannel(ChannelUpdateRequestDTO channelUpdateRequestDTO, String accountId) {
Optional<Channel> channel = channelRepository.findById(channelUpdateRequestDTO.getChannelId());
if (channel.isPresent()) {
Channel foundChannel = channel.get();
if(foundChannel.getOwnerId().equals(accountId)) {
foundChannel.setPositionTypes(channelUpdateRequestDTO.getPositionTypes());
return foundChannel;
return new ChannelSingleResponseDTO(foundChannel);
} else throw new IllegalArgumentException("주인이 아닌 다른 사용자 계정으로 채널 수정 시도중");
} else throw new IllegalArgumentException("요청한 channelId로 해당 채널이 존재하지 않음");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.mtvs.devlinkbackend.character.controller;

import com.mtvs.devlinkbackend.character.dto.UserCharacterRegistRequestDTO;
import com.mtvs.devlinkbackend.character.dto.UserCharacterUpdateRequestDTO;
import com.mtvs.devlinkbackend.character.entity.UserCharacter;
import com.mtvs.devlinkbackend.character.dto.request.UserCharacterRegistRequestDTO;
import com.mtvs.devlinkbackend.character.dto.response.UserCharacterSingleResponseDTO;
import com.mtvs.devlinkbackend.character.dto.request.UserCharacterUpdateRequestDTO;
import com.mtvs.devlinkbackend.character.service.UserCharacterService;
import com.mtvs.devlinkbackend.util.JwtUtil;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -25,24 +25,25 @@ public UserCharacterController(UserCharacterService userCharacterService, JwtUti
@Operation(summary = "캐릭터 등록", description = "새로운 캐릭터를 등록합니다.")
@ApiResponse(responseCode = "201", description = "캐릭터가 성공적으로 등록되었습니다.")
@PostMapping
public ResponseEntity<UserCharacter> registerCharacter(
public ResponseEntity<UserCharacterSingleResponseDTO> registerCharacter(
@RequestBody UserCharacterRegistRequestDTO userCharacterRegistRequestDTO,
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
UserCharacter userCharacter = userCharacterService.registCharacter(userCharacterRegistRequestDTO, accountId);
UserCharacterSingleResponseDTO userCharacter =
userCharacterService.registCharacter(userCharacterRegistRequestDTO, accountId);
return new ResponseEntity<>(userCharacter, HttpStatus.CREATED);
}

@Operation(summary = "캐릭터 조회", description = "계정 ID로 캐릭터를 조회합니다.")
@ApiResponse(responseCode = "200", description = "캐릭터가 성공적으로 조회되었습니다.")
@ApiResponse(responseCode = "404", description = "해당 계정 ID로 캐릭터를 찾을 수 없습니다.")
@GetMapping
public ResponseEntity<UserCharacter> getCharacter(
public ResponseEntity<UserCharacterSingleResponseDTO> getCharacter(
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
UserCharacter userCharacter = userCharacterService.findCharacterByAccountId(accountId);
UserCharacterSingleResponseDTO userCharacter = userCharacterService.findCharacterByAccountId(accountId);
if (userCharacter == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
Expand All @@ -53,13 +54,13 @@ public ResponseEntity<UserCharacter> getCharacter(
@ApiResponse(responseCode = "200", description = "캐릭터가 성공적으로 수정되었습니다.")
@ApiResponse(responseCode = "404", description = "해당 계정 ID로 캐릭터를 찾을 수 없습니다.")
@PatchMapping
public ResponseEntity<UserCharacter> updateCharacter(
public ResponseEntity<UserCharacterSingleResponseDTO> updateCharacter(
@RequestBody UserCharacterUpdateRequestDTO userCharacterUpdateRequestDTO,
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
try {
UserCharacter updatedCharacter = userCharacterService.updateCharacter(userCharacterUpdateRequestDTO, accountId);
UserCharacterSingleResponseDTO updatedCharacter = userCharacterService.updateCharacter(userCharacterUpdateRequestDTO, accountId);
return new ResponseEntity<>(updatedCharacter, HttpStatus.OK);
} catch (IllegalArgumentException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mtvs.devlinkbackend.character.dto;
package com.mtvs.devlinkbackend.character.dto.request;

import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mtvs.devlinkbackend.character.dto;
package com.mtvs.devlinkbackend.character.dto.request;

import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mtvs.devlinkbackend.character.dto.response;

import com.mtvs.devlinkbackend.character.entity.UserCharacter;
import lombok.*;

@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class UserCharacterSingleResponseDTO {
private UserCharacter data;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.mtvs.devlinkbackend.character.service;

import com.mtvs.devlinkbackend.character.dto.UserCharacterRegistRequestDTO;
import com.mtvs.devlinkbackend.character.dto.UserCharacterUpdateRequestDTO;
import com.mtvs.devlinkbackend.character.dto.request.UserCharacterRegistRequestDTO;
import com.mtvs.devlinkbackend.character.dto.response.UserCharacterSingleResponseDTO;
import com.mtvs.devlinkbackend.character.dto.request.UserCharacterUpdateRequestDTO;
import com.mtvs.devlinkbackend.character.entity.UserCharacter;
import com.mtvs.devlinkbackend.character.repository.UserCharacterRepository;
import jakarta.transaction.Transactional;
Expand All @@ -16,25 +17,25 @@ public UserCharacterService(UserCharacterRepository userCharacterRepository) {
}

@Transactional
public UserCharacter registCharacter(UserCharacterRegistRequestDTO userCharacterRegistRequestDTO, String accountId) {
return userCharacterRepository.save(new UserCharacter(
public UserCharacterSingleResponseDTO registCharacter(UserCharacterRegistRequestDTO userCharacterRegistRequestDTO, String accountId) {
return new UserCharacterSingleResponseDTO(userCharacterRepository.save(new UserCharacter(
accountId,
userCharacterRegistRequestDTO.getStatus()
));
)));
}

public UserCharacter findCharacterByAccountId(String accountId) {
return userCharacterRepository.findByAccountId(accountId);
public UserCharacterSingleResponseDTO findCharacterByAccountId(String accountId) {
return new UserCharacterSingleResponseDTO(userCharacterRepository.findByAccountId(accountId));
}

@Transactional
public UserCharacter updateCharacter(UserCharacterUpdateRequestDTO userCharacterUpdateRequestDTO, String accountId) {
public UserCharacterSingleResponseDTO updateCharacter(UserCharacterUpdateRequestDTO userCharacterUpdateRequestDTO, String accountId) {
UserCharacter userCharacter = userCharacterRepository.findByAccountId(accountId);
if(userCharacter == null)
throw new IllegalArgumentException("잘못된 계정으로 캐릭터 수정 시도");

userCharacter.setStatus(userCharacterUpdateRequestDTO.getStatus());
return userCharacter;
return new UserCharacterSingleResponseDTO(userCharacter);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.mtvs.devlinkbackend.comment.controller;

import com.mtvs.devlinkbackend.comment.dto.CommentRegistRequestDTO;
import com.mtvs.devlinkbackend.comment.dto.CommentUpdateRequestDTO;
import com.mtvs.devlinkbackend.comment.entity.Comment;
import com.mtvs.devlinkbackend.comment.dto.response.CommentListResponseDTO;
import com.mtvs.devlinkbackend.comment.dto.request.CommentRegistRequestDTO;
import com.mtvs.devlinkbackend.comment.dto.response.CommentSingleResponseDTO;
import com.mtvs.devlinkbackend.comment.dto.request.CommentUpdateRequestDTO;
import com.mtvs.devlinkbackend.comment.service.CommentService;
import com.mtvs.devlinkbackend.util.JwtUtil;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -12,8 +13,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class CommentController {
Expand All @@ -31,12 +30,12 @@ public CommentController(CommentService commentService, JwtUtil jwtUtil) {
@ApiResponse(responseCode = "404", description = "해당 요청을 찾을 수 없습니다.")
})
@PostMapping
public ResponseEntity<Comment> registComment(
public ResponseEntity<CommentSingleResponseDTO> registComment(
@RequestBody CommentRegistRequestDTO commentRegistRequestDTO,
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
Comment comment = commentService.registComment(commentRegistRequestDTO, accountId);
CommentSingleResponseDTO comment = commentService.registComment(commentRegistRequestDTO, accountId);
return ResponseEntity.status(HttpStatus.CREATED).body(comment);
}

Expand All @@ -46,27 +45,27 @@ public ResponseEntity<Comment> registComment(
@ApiResponse(responseCode = "404", description = "해당 댓글을 찾을 수 없습니다.")
})
@GetMapping("/{commentId}")
public ResponseEntity<Comment> findCommentByCommentId(@PathVariable Long commentId) {
Comment comment = commentService.findCommentByCommentId(commentId);
public ResponseEntity<CommentSingleResponseDTO> findCommentByCommentId(@PathVariable Long commentId) {
CommentSingleResponseDTO comment = commentService.findCommentByCommentId(commentId);
return comment != null ? ResponseEntity.ok(comment) : ResponseEntity.notFound().build();
}

@Operation(summary = "요청 ID로 댓글 조회", description = "특정 요청에 연관된 모든 댓글을 조회합니다.")
@ApiResponse(responseCode = "200", description = "댓글 목록이 성공적으로 조회되었습니다.")
@GetMapping("/request/{requestId}")
public ResponseEntity<List<Comment>> findCommentsByRequestId(@PathVariable Long requestId) {
List<Comment> comments = commentService.findCommentsByProjectId(requestId);
public ResponseEntity<CommentListResponseDTO> findCommentsByRequestId(@PathVariable Long requestId) {
CommentListResponseDTO comments = commentService.findCommentsByProjectId(requestId);
return ResponseEntity.ok(comments);
}

@Operation(summary = "사용자 ID로 댓글 조회", description = "특정 사용자가 작성한 모든 댓글을 조회합니다.")
@ApiResponse(responseCode = "200", description = "사용자의 댓글 목록이 성공적으로 조회되었습니다.")
@GetMapping("/account")
public ResponseEntity<List<Comment>> findCommentsByAccountId(
public ResponseEntity<CommentListResponseDTO> findCommentsByAccountId(
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
List<Comment> comments = commentService.findCommentsByAccountId(accountId);
CommentListResponseDTO comments = commentService.findCommentsByAccountId(accountId);
return ResponseEntity.ok(comments);
}

Expand All @@ -77,12 +76,12 @@ public ResponseEntity<List<Comment>> findCommentsByAccountId(
@ApiResponse(responseCode = "404", description = "해당 댓글을 찾을 수 없습니다.")
})
@PatchMapping
public ResponseEntity<Comment> updateComment(
public ResponseEntity<CommentSingleResponseDTO> updateComment(
@RequestBody CommentUpdateRequestDTO commentUpdateRequestDTO,
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
Comment updatedComment = commentService.updateComment(commentUpdateRequestDTO, accountId);
CommentSingleResponseDTO updatedComment = commentService.updateComment(commentUpdateRequestDTO, accountId);
return ResponseEntity.ok(updatedComment);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mtvs.devlinkbackend.comment.dto;
package com.mtvs.devlinkbackend.comment.dto.request;

import lombok.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mtvs.devlinkbackend.comment.dto;
package com.mtvs.devlinkbackend.comment.dto.request;

import lombok.*;

Expand Down
Loading