-
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.
- Loading branch information
Showing
15 changed files
with
330 additions
and
1 deletion.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/com/sickgyun/server/coffeechat/domain/CoffeeChat.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,55 @@ | ||
package com.sickgyun.server.coffeechat.domain; | ||
|
||
import com.sickgyun.server.coffeechat.domain.value.State; | ||
import com.sickgyun.server.user.domain.User; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class CoffeeChat { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "coffee_chat_id") | ||
private Long id; | ||
|
||
private String message; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private State state; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "to_user_id") | ||
private User toUser; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "from_user_id") | ||
private User fromUser; | ||
|
||
public CoffeeChat(String message, State state, User fromUser) { | ||
this.message = message; | ||
this.state = state; | ||
this.fromUser = fromUser; | ||
} | ||
|
||
public void updateToUser(User toUser) { | ||
this.toUser = toUser; | ||
} | ||
|
||
public void updateState(State state) { | ||
this.state = state; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/sickgyun/server/coffeechat/domain/repository/CoffeeChatRepository.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,13 @@ | ||
package com.sickgyun.server.coffeechat.domain.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.sickgyun.server.coffeechat.domain.CoffeeChat; | ||
import com.sickgyun.server.coffeechat.exception.CoffeeChatNotFoundException; | ||
|
||
public interface CoffeeChatRepository extends JpaRepository<CoffeeChat, Long> { | ||
default CoffeeChat getById(Long id) { | ||
return findById(id) | ||
.orElseThrow(() -> new CoffeeChatNotFoundException(id)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/sickgyun/server/coffeechat/domain/value/State.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,7 @@ | ||
package com.sickgyun.server.coffeechat.domain.value; | ||
|
||
public enum State { | ||
PENDING, | ||
ACCEPT, | ||
REJECT | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/sickgyun/server/coffeechat/exception/CoffeeChatNotFoundException.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,12 @@ | ||
package com.sickgyun.server.coffeechat.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import com.sickgyun.server.common.exception.SickgyunException; | ||
|
||
public class CoffeeChatNotFoundException extends SickgyunException { | ||
|
||
public CoffeeChatNotFoundException(Long id) { | ||
super(HttpStatus.NOT_FOUND, String.format("%s의 아이디를 가진 커피챗을 찾을 수 없습니다.", id)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/sickgyun/server/coffeechat/exception/NotAlreadyPendingException.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,13 @@ | ||
package com.sickgyun.server.coffeechat.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import com.sickgyun.server.coffeechat.domain.CoffeeChat; | ||
import com.sickgyun.server.common.exception.SickgyunException; | ||
|
||
public class NotAlreadyPendingException extends SickgyunException { | ||
|
||
public NotAlreadyPendingException(CoffeeChat coffeeChat) { | ||
super(HttpStatus.BAD_REQUEST, String.format("%s는 이미 수락됐거나 거절된 커피챗입니다.", coffeeChat.getId())); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/sickgyun/server/coffeechat/exception/NotMatchFromUserException.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,13 @@ | ||
package com.sickgyun.server.coffeechat.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import com.sickgyun.server.common.exception.SickgyunException; | ||
import com.sickgyun.server.user.domain.User; | ||
|
||
public class NotMatchFromUserException extends SickgyunException { | ||
|
||
public NotMatchFromUserException(User user) { | ||
super(HttpStatus.FORBIDDEN, String.format("%s는 커피챗 제안을 받은 유저가 아닙니다.", user.getName())); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/sickgyun/server/coffeechat/presentation/CoffeeChatController.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,50 @@ | ||
package com.sickgyun.server.coffeechat.presentation; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.sickgyun.server.auth.annotation.LoginRequired; | ||
import com.sickgyun.server.auth.repository.AuthRepository; | ||
import com.sickgyun.server.coffeechat.presentation.dto.CoffeeChatRequest; | ||
import com.sickgyun.server.coffeechat.service.CommandCoffeeChatService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/coffee") | ||
@RequiredArgsConstructor | ||
public class CoffeeChatController { | ||
|
||
private final CommandCoffeeChatService commandCoffeeChatService; | ||
private final AuthRepository authRepository; | ||
|
||
@PostMapping("/{to-user-id}") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
@LoginRequired | ||
public void create( | ||
@PathVariable(name = "to-user-id") Long toUserId, | ||
@RequestBody CoffeeChatRequest request | ||
) { | ||
commandCoffeeChatService.create(request.toEntity(authRepository.getCurrentUser()), toUserId); | ||
} | ||
|
||
@PutMapping("/{chat-id}/accept") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
@LoginRequired | ||
public void accept(@PathVariable(name = "chat-id") Long coffeeChatId) { | ||
commandCoffeeChatService.accept(authRepository.getCurrentUser(), coffeeChatId); | ||
} | ||
|
||
@PutMapping("/{chat-id}/reject") | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
@LoginRequired | ||
public void reject(@PathVariable(name = "chat-id") Long coffeeChatId) { | ||
commandCoffeeChatService.reject(authRepository.getCurrentUser(), coffeeChatId); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/sickgyun/server/coffeechat/presentation/dto/CoffeeChatRequest.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 com.sickgyun.server.coffeechat.presentation.dto; | ||
|
||
import com.sickgyun.server.coffeechat.domain.CoffeeChat; | ||
import com.sickgyun.server.coffeechat.domain.value.State; | ||
import com.sickgyun.server.user.domain.User; | ||
|
||
public record CoffeeChatRequest( | ||
String message | ||
) { | ||
|
||
public CoffeeChat toEntity(User fromUser) { | ||
return new CoffeeChat(message, State.PENDING, fromUser); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/com/sickgyun/server/coffeechat/service/CommandCoffeeChatService.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,47 @@ | ||
package com.sickgyun.server.coffeechat.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.sickgyun.server.coffeechat.domain.CoffeeChat; | ||
import com.sickgyun.server.coffeechat.domain.value.State; | ||
import com.sickgyun.server.coffeechat.service.implementation.CoffeeChatCreator; | ||
import com.sickgyun.server.coffeechat.service.implementation.CoffeeChatReader; | ||
import com.sickgyun.server.coffeechat.service.implementation.CoffeeChatUpdater; | ||
import com.sickgyun.server.coffeechat.service.implementation.CoffeeChatValidator; | ||
import com.sickgyun.server.user.domain.User; | ||
import com.sickgyun.server.user.service.implementation.UserReader; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class CommandCoffeeChatService { | ||
|
||
private final CoffeeChatCreator coffeeChatCreator; | ||
private final CoffeeChatReader coffeeChatReader; | ||
private final CoffeeChatValidator coffeeChatValidator; | ||
private final CoffeeChatUpdater coffeeChatUpdater; | ||
private final UserReader userReader; | ||
|
||
public void create(CoffeeChat coffeeChat, Long toUserId) { | ||
User toUser = userReader.readUser(toUserId); | ||
coffeeChat.updateToUser(toUser); | ||
coffeeChatCreator.create(coffeeChat); | ||
} | ||
|
||
public void accept(User user, Long coffeeChatId) { | ||
CoffeeChat coffeeChat = coffeeChatReader.read(coffeeChatId); | ||
coffeeChatValidator.shouldBeSameUser(user, coffeeChat.getToUser()); | ||
coffeeChatValidator.shouldBePending(coffeeChat); | ||
coffeeChatUpdater.updateState(coffeeChat, State.ACCEPT); | ||
} | ||
|
||
public void reject(User user, Long coffeeChatId) { | ||
CoffeeChat coffeeChat = coffeeChatReader.read(coffeeChatId); | ||
coffeeChatValidator.shouldBeSameUser(user, coffeeChat.getToUser()); | ||
coffeeChatValidator.shouldBePending(coffeeChat); | ||
coffeeChatUpdater.updateState(coffeeChat, State.REJECT); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/sickgyun/server/coffeechat/service/implementation/CoffeeChatCreator.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,19 @@ | ||
package com.sickgyun.server.coffeechat.service.implementation; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.sickgyun.server.coffeechat.domain.CoffeeChat; | ||
import com.sickgyun.server.coffeechat.domain.repository.CoffeeChatRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CoffeeChatCreator { | ||
|
||
private final CoffeeChatRepository coffeeChatRepository; | ||
|
||
public void create(CoffeeChat coffeeChat) { | ||
coffeeChatRepository.save(coffeeChat); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/sickgyun/server/coffeechat/service/implementation/CoffeeChatReader.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,19 @@ | ||
package com.sickgyun.server.coffeechat.service.implementation; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.sickgyun.server.coffeechat.domain.CoffeeChat; | ||
import com.sickgyun.server.coffeechat.domain.repository.CoffeeChatRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CoffeeChatReader { | ||
|
||
private final CoffeeChatRepository coffeeChatRepository; | ||
|
||
public CoffeeChat read(Long coffeeChatId) { | ||
return coffeeChatRepository.getById(coffeeChatId); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/sickgyun/server/coffeechat/service/implementation/CoffeeChatUpdater.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,17 @@ | ||
package com.sickgyun.server.coffeechat.service.implementation; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.sickgyun.server.coffeechat.domain.CoffeeChat; | ||
import com.sickgyun.server.coffeechat.domain.value.State; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CoffeeChatUpdater { | ||
|
||
public void updateState(CoffeeChat coffeeChat, State state) { | ||
coffeeChat.updateState(state); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/sickgyun/server/coffeechat/service/implementation/CoffeeChatValidator.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,28 @@ | ||
package com.sickgyun.server.coffeechat.service.implementation; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.sickgyun.server.coffeechat.domain.CoffeeChat; | ||
import com.sickgyun.server.coffeechat.domain.value.State; | ||
import com.sickgyun.server.coffeechat.exception.NotAlreadyPendingException; | ||
import com.sickgyun.server.coffeechat.exception.NotMatchFromUserException; | ||
import com.sickgyun.server.user.domain.User; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CoffeeChatValidator { | ||
|
||
public void shouldBeSameUser(User user, User toUser) { | ||
if (!toUser.getId().equals(user.getId())) { | ||
throw new NotMatchFromUserException(user); | ||
} | ||
} | ||
|
||
public void shouldBePending(CoffeeChat coffeeChat) { | ||
if (!coffeeChat.getState().equals(State.PENDING)) { | ||
throw new NotAlreadyPendingException(coffeeChat); | ||
} | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/sickgyun/server/reqruit/service/implementation/ReqruitValidator.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,22 @@ | ||
package com.sickgyun.server.reqruit.service.implementation; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.sickgyun.server.recruit.domain.repository.RecruitRepository; | ||
import com.sickgyun.server.recruit.exception.RecruitIsNotExistException; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReqruitValidator { | ||
private final RecruitRepository recruitRepository; | ||
|
||
public void requiredShouldBeExist(Long requireId) { | ||
boolean isExist = recruitRepository.existsById(requireId); | ||
|
||
if (!isExist) { | ||
throw new RecruitIsNotExistException(requireId); | ||
} | ||
} | ||
} |