Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop backend #121

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f7d673f
feat: MoimSwagger 인터페이스 구현
hoyeonyy Jul 18, 2024
a35b98c
refactor: Swagger 코드 분리
hoyeonyy Jul 18, 2024
d499e8f
style: 클래스 선언부 아래 개행 추가
pricelees Jul 18, 2024
ee33702
refactor: 반환 타입 void를 ResponseEntity<Void> 타입으로 수정
pricelees Jul 18, 2024
6f9192e
style: return문 위 개행 추가
pricelees Jul 18, 2024
31b0447
style: 모든 id 변수명을 moimId로 수정
pricelees Jul 18, 2024
f08981d
feat: 커스텀 예외 및 핸들러 추가
ay-eonii Jul 18, 2024
7adaf43
feat: 모임 커스텀 예외 및 메시지
ay-eonii Jul 18, 2024
4a03621
feat: 모임 커스텀 예외 적용
ay-eonii Jul 18, 2024
2a5587a
refactor: 모든 원시타입 변수 포장
pricelees Jul 18, 2024
7007393
refactor: 원시값 포장에서 발생하는 NPE 해결
pricelees Jul 18, 2024
9102746
refactor: 테스트 Assertion에서 Service가 아닌 Repository를 사용하도록 수정
pricelees Jul 18, 2024
a50b08f
refactor: 메서드 파라미터로 쓰이는 service 코드를 별도의 변수로 추출
pricelees Jul 18, 2024
794490f
Merge pull request #74 from woowacourse-teams/refactor/#72
hoyeonyy Jul 18, 2024
898a780
refactor: 요청 및 응답에 사용되는 날짜 및 시간 형식 통일 및 테스트 추가
pricelees Jul 19, 2024
23ff318
merge: 최신 상태 반영
pricelees Jul 19, 2024
c52c39b
refactor: 반환 타입 수정 및 원시타입 변수 포장
pricelees Jul 19, 2024
4e35807
feat: 전역 에러 핸들러 추가
ay-eonii Jul 19, 2024
900c367
fix: static import 제거
ay-eonii Jul 19, 2024
e1d8e57
fix: MoudaException 클래스명 변경
ay-eonii Jul 19, 2024
10b4f6e
refactor: 반환 타입 수정
pricelees Jul 20, 2024
39674b5
Merge branch 'develop-backend' into feature/#71
ay-eonii Jul 20, 2024
7942162
Merge pull request #76 from woowacourse-teams/feature/#71
ay-eonii Jul 20, 2024
d32a546
refactor: CORS 설정을 팀 상황에 맞게 수정
ksk0605 Jul 22, 2024
c4e8022
refactor: https 오리진 삭제
ksk0605 Jul 22, 2024
1d99f69
Merge branch 'develop-backend' into refactor/#73
pricelees Jul 22, 2024
e82cd1e
feat: Member 엔티티 생성
hoyeonyy Jul 22, 2024
237f9d6
refactor: property에 지정한 날짜, 시간 포맷 제거
pricelees Jul 22, 2024
aa54ad6
refactor: 도메인에서의 wrapper type 언박싱 및 빌더 사용 생성자 추가
pricelees Jul 22, 2024
3d6a9d6
refactor: 응답에서의 wrapper type 언박싱
pricelees Jul 22, 2024
db12372
style: 코드 컨벤션 통일
pricelees Jul 22, 2024
31a432c
refactor: 테스트에서의 Optional 처리 수정
pricelees Jul 22, 2024
739202a
Merge pull request #78 from woowacourse-teams/refactor/#73
pricelees Jul 23, 2024
84d8ec7
merge: 최신 변경 사항 반영
hoyeonyy Jul 23, 2024
6b6c535
feat: MemberRepository 생성
hoyeonyy Jul 23, 2024
85c400e
refactor: 맴버 닉네임 추가
hoyeonyy Jul 23, 2024
7911373
test: 테스트 케이스 추가
hoyeonyy Jul 23, 2024
98ab8d6
test: 모임 조회 테스트 시 서비스 레이어에서 검증하도록 수정
Mingyum-Kim Jul 17, 2024
fd47477
refactor: OPTIONS 오리진 추가
ksk0605 Jul 23, 2024
2ad4b4d
refactor: currentPeople 필드 제거
hoyeonyy Jul 23, 2024
1f8655d
refactor: 카멜케이스 적용
hoyeonyy Jul 23, 2024
60666b2
refactor: String을 반환하지 않고 객체 반환
hoyeonyy Jul 23, 2024
3984e66
refactor: delete 메서드 수정
hoyeonyy Jul 23, 2024
93393cd
Merge pull request #100 from woowacourse-teams/test/#99
Mingyum-Kim Jul 24, 2024
122178b
style: 카멜 케이스 수정
hoyeonyy Jul 24, 2024
2968d2a
refactor: 메서드 명 수정
hoyeonyy Jul 24, 2024
1e54ed8
refactor: 주석 코드 제거
hoyeonyy Jul 24, 2024
6de6293
merge: 최신 변경 사항 반영
hoyeonyy Jul 24, 2024
4e2447c
Merge pull request #96 from woowacourse-teams/feature/#90
hoyeonyy Jul 24, 2024
a660d09
Merge pull request #88 from woowacourse-teams/refactor/#87
ksk0605 Jul 25, 2024
57b72b3
Update ci-dev.yml
Mingyum-Kim Jul 25, 2024
b833170
Merge pull request #119 from woowacourse-teams/chore-ci-test
Mingyum-Kim Jul 25, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: chmod +x ./gradlew

- name: Gradle 빌드
run: ./gradlew clean build -x test
run: ./gradlew clean build

- name: DockerHub 로그인
uses: docker/login-action@v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
@Getter
@AllArgsConstructor
public class RestResponse<T> {

private T data;
}
10 changes: 7 additions & 3 deletions backend/src/main/java/mouda/backend/config/CorsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class CorsConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowedHeaders("*");
.allowedOrigins("http://localhost:8080")
.allowedMethods("GET", "POST", "DELETE", "OPTIONS")
.allowedHeaders("Authorization", "Content-Type")
.allowCredentials(true)
.maxAge(3600);
}
}
32 changes: 32 additions & 0 deletions backend/src/main/java/mouda/backend/config/JacksonConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package mouda.backend.config;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;

@Configuration
public class JacksonConfig {

@Bean
public JavaTimeModule javaTimeModule() {
JavaTimeModule javaTimeModule = new JavaTimeModule();
DateTimeFormatter dateFormat = DateTimeFormatter.ISO_LOCAL_DATE;
DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("HH:mm");

javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(dateFormat))
.addSerializer(LocalTime.class, new LocalTimeSerializer(timeFormat))
.addDeserializer(LocalDate.class, new LocalDateDeserializer(dateFormat))
.addDeserializer(LocalTime.class, new LocalTimeDeserializer(timeFormat));

return javaTimeModule;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package mouda.backend.exception;

public record ErrorResponse(
String message
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mouda.backend.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@RestControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

@ExceptionHandler(MoudaException.class)
public ResponseEntity<ErrorResponse> handleMoudaException(MoudaException exception) {
return ResponseEntity.status(exception.getHttpStatus()).body(new ErrorResponse(exception.getMessage()));
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleException() {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ErrorResponse("서버 오류가 발생했습니다."));
}
}
14 changes: 14 additions & 0 deletions backend/src/main/java/mouda/backend/exception/MoudaException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mouda.backend.exception;

import org.springframework.http.HttpStatus;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class MoudaException extends RuntimeException {

private HttpStatus httpStatus;
private String message;
}
36 changes: 36 additions & 0 deletions backend/src/main/java/mouda/backend/member/domain/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package mouda.backend.member.domain;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mouda.backend.moim.domain.Moim;

@Entity
@Getter
@NoArgsConstructor
public class Member {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String nickname;

@ManyToOne(fetch = FetchType.LAZY)
private Moim moim;

@Builder
public Member(String nickname) {
this.nickname = nickname;
}

public void joinMoim(Moim moim) {
this.moim = moim;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package mouda.backend.member.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import mouda.backend.member.domain.Member;

public interface MemberRepository extends JpaRepository<Member, Long> {

List<Member> findAllByMoimId(long moimId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import mouda.backend.common.RestResponse;
import mouda.backend.moim.domain.Moim;
Expand All @@ -24,54 +21,47 @@
@RestController
@RequestMapping("/v1/moim")
@RequiredArgsConstructor
public class MoimController {
public class MoimController implements MoimSwagger {

private final MoimService moimService;

@Operation(summary = "모임 생성", description = "모임을 생성한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 생성 성공!"),
})
@Override
@PostMapping
public ResponseEntity<RestResponse<Long>> createMoim(@RequestBody MoimCreateRequest moimCreateRequest) {
Moim moim = moimService.createMoim(moimCreateRequest);

return ResponseEntity.ok().body(new RestResponse<>(moim.getId()));
}

@Operation(summary = "모임 전체 조회", description = "모든 모임을 조회한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 조회 성공!"),
})
@Override
@GetMapping
public ResponseEntity<RestResponse<MoimFindAllResponses>> findAllMoim() {
return ResponseEntity.ok().body(new RestResponse<>(moimService.findAllMoim()));
MoimFindAllResponses moimFindAllResponses = moimService.findAllMoim();

return ResponseEntity.ok().body(new RestResponse<>(moimFindAllResponses));
}

@Operation(summary = "모임 상세 조회", description = "모임 상세 조회한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 상세 조회 성공!"),
})
@Override
@GetMapping("/{moimId}")
public ResponseEntity<RestResponse<MoimDetailsFindResponse>> findMoimDetails(@PathVariable long moimId) {
return ResponseEntity.ok().body(new RestResponse<>(moimService.findMoimDetails(moimId)));
public ResponseEntity<RestResponse<MoimDetailsFindResponse>> findMoimDetails(@PathVariable Long moimId) {
MoimDetailsFindResponse moimDetailsFindResponse = moimService.findMoimDetails(moimId);

return ResponseEntity.ok().body(new RestResponse<>(moimDetailsFindResponse));
}

@Operation(summary = "모임 참여", description = "모임에 참여한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 참여 성공!")
})
@Override
@PostMapping("/join")
public ResponseEntity<RestResponse<Void>> joinMoim(@RequestBody MoimJoinRequest moimJoinRequest) {
public ResponseEntity<Void> joinMoim(@RequestBody MoimJoinRequest moimJoinRequest) {
moimService.joinMoim(moimJoinRequest);

return ResponseEntity.ok().build();
}

@Operation(summary = "모임 삭제", description = "해당하는 id의 모임을 삭제한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 삭제 성공!"),
})
@Override
@DeleteMapping("/{moimId}")
public void deleteMoim(@PathVariable long moimId) {
public ResponseEntity<Void> deleteMoim(@PathVariable Long moimId) {
moimService.deleteMoim(moimId);

return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package mouda.backend.moim.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import mouda.backend.common.RestResponse;
import mouda.backend.moim.dto.request.MoimCreateRequest;
import mouda.backend.moim.dto.request.MoimJoinRequest;
import mouda.backend.moim.dto.response.MoimDetailsFindResponse;
import mouda.backend.moim.dto.response.MoimFindAllResponses;

public interface MoimSwagger {

@Operation(summary = "모임 생성", description = "모임을 생성한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 생성 성공!"),
})
ResponseEntity<RestResponse<Long>> createMoim(@RequestBody MoimCreateRequest moimCreateRequest);

@Operation(summary = "모임 전체 조회", description = "모든 모임을 조회한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 조회 성공!"),
})
ResponseEntity<RestResponse<MoimFindAllResponses>> findAllMoim();

@Operation(summary = "모임 상세 조회", description = "모임 상세 조회한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 상세 조회 성공!"),
})
ResponseEntity<RestResponse<MoimDetailsFindResponse>> findMoimDetails(@PathVariable Long moimId);

@Operation(summary = "모임 참여", description = "모임에 참여한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 참여 성공!")
})
ResponseEntity<Void> joinMoim(@RequestBody MoimJoinRequest moimJoinRequest);

@Operation(summary = "모임 삭제", description = "해당하는 id의 모임을 삭제한다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모임 삭제 성공!"),
})
ResponseEntity<Void> deleteMoim(@PathVariable Long moimId);
}
34 changes: 26 additions & 8 deletions backend/src/main/java/mouda/backend/moim/domain/Moim.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
import java.time.LocalDate;
import java.time.LocalTime;

import org.springframework.http.HttpStatus;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import mouda.backend.moim.exception.MoimErrorMessage;
import mouda.backend.moim.exception.MoimException;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Moim {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -30,18 +32,34 @@ public class Moim {

private String place;

private int currentPeople;

private int maxPeople;

private String authorNickname;

private String description;

public void join() {
@Builder
public Moim(
String title,
LocalDate date,
LocalTime time,
String place,
int maxPeople,
String authorNickname,
String description
) {
this.title = title;
this.date = date;
this.time = time;
this.place = place;
this.maxPeople = maxPeople;
this.authorNickname = authorNickname;
this.description = description;
}

public void validateAlreadyFullMoim(int currentPeople) {
if (currentPeople + 1 > maxPeople) {
throw new IllegalArgumentException();
throw new MoimException(HttpStatus.BAD_REQUEST, MoimErrorMessage.MAX_PEOPLE);
}
currentPeople++;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ public record MoimCreateRequest(
LocalDate date,
LocalTime time,
String place,
int maxPeople,
Integer maxPeople,
String authorNickname,
String description
) {

public Moim toEntity() {
return Moim.builder()
.title(title)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mouda.backend.moim.dto.request;

public record MoimJoinRequest(
Long moimId
Long moimId,
String nickname
) {
}
Loading
Loading