-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from GDSC-KNU/feat/channel
채널 CRUD 구현 #4
- Loading branch information
Showing
25 changed files
with
904 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,5 @@ out/ | |
.vscode/ | ||
|
||
### env ### | ||
.env | ||
.env | ||
application-test.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/gdsc/comunity/controller/ChannelController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package gdsc.comunity.controller; | ||
|
||
import gdsc.comunity.annotation.UserId; | ||
import gdsc.comunity.dto.channel.*; | ||
import gdsc.comunity.service.channel.ChannelServiceImpl; | ||
import gdsc.comunity.util.ListWrapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/channel") | ||
@RequiredArgsConstructor | ||
public class ChannelController { | ||
private final ChannelServiceImpl channelServiceImpl; | ||
|
||
@PostMapping | ||
ResponseEntity<String> createChannel(@RequestBody ChannelCreateDto channelCreateDto, @UserId Long id) { | ||
String channelName = channelCreateDto.getChannelName(); | ||
String nickname = channelCreateDto.getNickname(); | ||
channelServiceImpl.createChannel(id, channelName, nickname); | ||
return new ResponseEntity<>("Channel created.", HttpStatus.CREATED); | ||
} | ||
|
||
@GetMapping("/{channelId}") | ||
ResponseEntity<ChannelInfoDto> searchChannel(@PathVariable Long channelId, @UserId Long id) { | ||
ChannelInfoDto channelInfoDto = channelServiceImpl.searchChannel(channelId); | ||
return new ResponseEntity<>(channelInfoDto, HttpStatus.OK); | ||
} | ||
|
||
@GetMapping("/join/{channelId}") | ||
ResponseEntity<ListWrapper<List<ChannelJoinRequestDto>>> searchJoinRequest(@PathVariable Long channelId, @UserId Long id) { | ||
List<ChannelJoinRequestDto> userList = channelServiceImpl.searchJoinRequest(id, channelId); | ||
return new ResponseEntity<>(new ListWrapper<>(userList), HttpStatus.OK); | ||
} | ||
|
||
@PostMapping("/join/{channelId}") | ||
ResponseEntity<String> sendJoinRequest(@RequestBody String nickname, @PathVariable Long channelId, @UserId Long id) { | ||
channelServiceImpl.sendJoinRequest(nickname, id, channelId); | ||
return new ResponseEntity<>("Channel joined.", HttpStatus.OK); | ||
} | ||
|
||
@PutMapping("/join/{channelId}") | ||
ResponseEntity<String> leaveChannel(@PathVariable Long channelId, @UserId Long id) { | ||
channelServiceImpl.leaveChannel(id, channelId); | ||
return new ResponseEntity<>("Channel left.", HttpStatus.OK); | ||
} | ||
|
||
@DeleteMapping("/join/{channelId}") | ||
ResponseEntity<String> deleteChannel(@PathVariable Long channelId, @UserId Long id) { | ||
channelServiceImpl.deleteChannel(id, channelId); | ||
return new ResponseEntity<>("Channel deleted.", HttpStatus.OK); | ||
} | ||
|
||
@PutMapping("/approve") | ||
ResponseEntity<String> approveJoinChannel(@RequestBody ApproveJoinChannelDto approveJoinChannelDto, @UserId Long userId) { | ||
Long targetUserId = approveJoinChannelDto.getUserId(); | ||
Long channelId = approveJoinChannelDto.getChannelId(); | ||
channelServiceImpl.approveJoinChannel(userId, targetUserId, channelId); | ||
return new ResponseEntity<>("Channel joined.", HttpStatus.OK); | ||
} | ||
|
||
@PutMapping("/nickname") | ||
ResponseEntity<String> changeNickname(@RequestBody ChannelNicknameDto channelNicknameDto, @UserId Long id) { | ||
String nickname = channelNicknameDto.getNickname(); | ||
Long channelId = channelNicknameDto.getChannelId(); | ||
channelServiceImpl.changeNickname(id, channelId, nickname); | ||
return new ResponseEntity<>("Nickname changed.", HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/gdsc/comunity/dto/channel/ApproveJoinChannelDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gdsc.comunity.dto.channel; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ApproveJoinChannelDto { | ||
private Long userId; | ||
private Long channelId; | ||
|
||
public ApproveJoinChannelDto(Long userId, Long channelId) { | ||
this.userId = userId; | ||
this.channelId = channelId; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/gdsc/comunity/dto/channel/ChannelCreateDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gdsc.comunity.dto.channel; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ChannelCreateDto { | ||
private String channelName; | ||
private String nickname; | ||
|
||
public ChannelCreateDto(String channelName, String nickname) { | ||
this.channelName = channelName; | ||
this.nickname = nickname; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/gdsc/comunity/dto/channel/ChannelInfoDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package gdsc.comunity.dto.channel; | ||
|
||
import gdsc.comunity.entity.user.User; | ||
import gdsc.comunity.entity.userchannel.UserChannel; | ||
import lombok.Getter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
public class ChannelInfoDto { | ||
|
||
@Getter | ||
public static class UserDto { | ||
private Long id; | ||
private String email; | ||
private String nickname; | ||
private String profileImageUrl; | ||
|
||
public UserDto(String nickname, User user) { | ||
this.id = user.getId(); | ||
this.email = user.getEmail(); | ||
this.nickname = nickname; | ||
this.profileImageUrl = user.getProfileImageUrl(); | ||
} | ||
} | ||
|
||
private String channelName; | ||
private String openDate; | ||
private String managerNickname; | ||
private List<UserDto> channelUsers; | ||
|
||
public ChannelInfoDto(String channelName, String openDate, String managerNickname, List<UserChannel> userChannelList, List<User> userList) { | ||
this.channelName = channelName; | ||
this.openDate = openDate; | ||
this.managerNickname = managerNickname; | ||
this.channelUsers = new ArrayList<>(); | ||
|
||
for (UserChannel userChannel : userChannelList) { | ||
for (User user : userList) { | ||
channelUsers.add(new UserDto(userChannel.getNickname(), user)); | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/gdsc/comunity/dto/channel/ChannelJoinRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package gdsc.comunity.dto.channel; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ChannelJoinRequestDto { | ||
Long id; | ||
Long userId; | ||
Long channelId; | ||
String nickname; | ||
|
||
public ChannelJoinRequestDto(Long id, Long userId, Long channelId, String nickname) { | ||
this.id = id; | ||
this.userId = userId; | ||
this.channelId = channelId; | ||
this.nickname = nickname; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/gdsc/comunity/dto/channel/ChannelNicknameDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package gdsc.comunity.dto.channel; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ChannelNicknameDto { | ||
private String nickname; | ||
private Long channelId; | ||
|
||
public ChannelNicknameDto(String nickname, Long channelId) { | ||
this.nickname = nickname; | ||
this.channelId = channelId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/gdsc/comunity/entity/channel/ChannelJoinRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gdsc.comunity.entity.channel; | ||
|
||
import gdsc.comunity.entity.common.BaseTimeEntity; | ||
import gdsc.comunity.entity.user.User; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
public class ChannelJoinRequest extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "channel_id") | ||
private Channel channel; | ||
|
||
@Column(nullable = false) | ||
String nickname; | ||
|
||
@Builder | ||
private ChannelJoinRequest(User user, Channel channel, String nickname){ | ||
this.user = user; | ||
this.channel = channel; | ||
this.nickname = nickname; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/gdsc/comunity/repository/channel/ChannelJoinRequestRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package gdsc.comunity.repository.channel; | ||
|
||
import gdsc.comunity.entity.channel.ChannelJoinRequest; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface ChannelJoinRequestRepository extends JpaRepository<ChannelJoinRequest, Long> { | ||
Optional<ChannelJoinRequest> findByUserIdAndChannelId(Long targetUserId, Long userId); | ||
|
||
List<ChannelJoinRequest> findAllByChannelId(Long channelId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.