Skip to content

Commit

Permalink
refactor(merge): merge conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobhboy committed Jan 29, 2024
2 parents fb8dabd + 08866d8 commit a412996
Show file tree
Hide file tree
Showing 15 changed files with 330 additions and 1 deletion.
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;
}
}
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));
}
}
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
}
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));
}
}
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()));
}
}
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()));
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class CommentValidator {

public void shouldBeSameUser(User commentWriter, User writer) {
if (commentWriter.getId().equals(writer.getId())) {
if (!commentWriter.getId().equals(writer.getId())) {
throw new NotMatchCommentWriterException();
}
}
Expand Down
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);
}
}
}

0 comments on commit a412996

Please sign in to comment.