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

Feat : 크루 등록 API 구현 #38

Merged
merged 17 commits into from
Aug 1, 2024
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
Binary file modified .gradle/8.9/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.9/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.9/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.9/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.9/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' // JSON 처리용 추가 라이브러리
implementation 'org.json:json:20210307'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'javax.servlet:javax.servlet-api:4.0.1' // 서블릿 API 추가
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
@EnableJpaRepositories
@EnableJpaAuditing
public class Likelion12Application {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.likelion12.common.exception;

import com.example.likelion12.common.response.status.ResponseStatus;
import lombok.Getter;
@Getter
public class ActivityRegionException extends RuntimeException{
private final ResponseStatus exceptionStatus;

public ActivityRegionException(ResponseStatus exceptionStatus) {
super(exceptionStatus.getMessage());
this.exceptionStatus = exceptionStatus;
}

public ActivityRegionException(ResponseStatus exceptionStatus, String message) {
super(message);
this.exceptionStatus = exceptionStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.likelion12.common.exception;

import com.example.likelion12.common.response.status.ResponseStatus;
import lombok.Getter;

@Getter
public class CrewException extends RuntimeException{
private final ResponseStatus exceptionStatus;

public CrewException(ResponseStatus exceptionStatus) {
super(exceptionStatus.getMessage());
this.exceptionStatus = exceptionStatus;
}

public CrewException(ResponseStatus exceptionStatus, String message) {
super(message);
this.exceptionStatus = exceptionStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.likelion12.common.exception;

import com.example.likelion12.common.response.status.ResponseStatus;
import lombok.Getter;

@Getter
public class ExerciseException extends RuntimeException {

private final ResponseStatus exceptionStatus;

public ExerciseException(ResponseStatus exceptionStatus) {
super(exceptionStatus.getMessage());
this.exceptionStatus = exceptionStatus;
}

public ExerciseException(ResponseStatus exceptionStatus, String message) {
super(message);
this.exceptionStatus = exceptionStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.likelion12.common.exception;

import com.example.likelion12.common.response.status.ResponseStatus;
import lombok.Getter;

@Getter
public class FacilityException extends RuntimeException {

private final ResponseStatus exceptionStatus;

public FacilityException(ResponseStatus exceptionStatus) {
super(exceptionStatus.getMessage());
this.exceptionStatus = exceptionStatus;
}

public FacilityException(ResponseStatus exceptionStatus, String message) {
super(message);
this.exceptionStatus = exceptionStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.likelion12.common.exception_handler;

import com.example.likelion12.common.exception.ActivityRegionException;
import com.example.likelion12.common.response.BaseErrorResponse;
import jakarta.annotation.Priority;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Priority(0)
@RestControllerAdvice
public class ActivityRegionExceptionControllerAdvice {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ActivityRegionException.class)
public BaseErrorResponse handle_ActivityRegionException(ActivityRegionException e) {
log.error("[handle_ActivityRegionException]", e);
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.likelion12.common.exception_handler;

import com.example.likelion12.common.exception.CrewException;
import com.example.likelion12.common.response.BaseErrorResponse;
import jakarta.annotation.Priority;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Priority(0)
@RestControllerAdvice
public class CrewExceptionControllerAdvice {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(CrewException.class)
public BaseErrorResponse handle_CrewException(CrewException e) {
log.error("[handle_CrewException]", e);
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.likelion12.common.exception_handler;

import com.example.likelion12.common.exception.ExerciseException;
import com.example.likelion12.common.response.BaseErrorResponse;
import jakarta.annotation.Priority;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Priority(0)
@RestControllerAdvice
public class ExerciseExceptionControllerAdvice {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(ExerciseException.class)
public BaseErrorResponse handle_ExerciseException(ExerciseException e) {
log.error("[handle_ExerciseException", e);
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.likelion12.common.exception_handler;

import com.example.likelion12.common.exception.FacilityException;
import com.example.likelion12.common.response.BaseErrorResponse;
import jakarta.annotation.Priority;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@Priority(0)
@RestControllerAdvice
public class FacilityExceptionControllerAdvice {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(FacilityException.class)
public BaseErrorResponse handle_FacilityException(FacilityException e) {
log.error("[handle_FacilityException]", e);
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{
* 1000: 요청 성공 (OK)
*/
SUCCESS(1000,HttpStatus.OK.value(), "요청에 성공하였습니다."),
FAILURE(2000, HttpStatus.BAD_REQUEST.value(), "요청에 실패하였습니다.");
FAILURE(2000, HttpStatus.BAD_REQUEST.value(), "요청에 실패하였습니다."),

/**
* 3000 : exercise 관련
*/
CANNOT_FOUND_EXERCISE(3000, HttpStatus.BAD_REQUEST.value(), "운동을 찾을 수 없습니다."),

/**
* 4000 : activityRegion 관련
*/
CANNOT_FOUND_ACTIVITYREGION(4000, HttpStatus.BAD_REQUEST.value(), "활동지역을 찾을 수 없습니다."),

/**
* 5000 : facility 관련
*/
CANOOT_FOUND_FACILITY(5000, HttpStatus.BAD_REQUEST.value(), "시설을 찾을 수 없습니다."),

/**
* 6000: member 관련
*/
CANNOT_FOUND_MEMBER(6000, HttpStatus.BAD_REQUEST.value(), "유저를 찾을 수 없습니다.");


private final int code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.likelion12.controller;

import com.example.likelion12.common.response.BaseResponse;
import com.example.likelion12.dto.PostCrewRequest;
import com.example.likelion12.dto.PostCrewResponse;
import com.example.likelion12.service.CrewService;
import com.example.likelion12.util.JwtProvider;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/crew")
public class CrewController {

private final JwtProvider jwtProvider;
private final CrewService crewService;

/**
* 크루 등록
*/
@PostMapping("")
public BaseResponse<PostCrewResponse> createCrew(@RequestHeader("Authorization") String authorization,
@RequestBody PostCrewRequest postCrewRequest){
log.info("[CrewController.createCrew]");
Long memberId = jwtProvider.extractIdFromHeader(authorization);
return new BaseResponse<>(crewService.createCrew(memberId, postCrewRequest));
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/example/likelion12/domain/Crew.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand Down Expand Up @@ -73,4 +74,21 @@ public class Crew extends BaseTime {
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "exercise_id")
private Exercise exercise;

public Crew(String crewName, String crewImg, int totalRecruits, int crewCost,
String commentSimple, String comment,BaseGender gender, BaseLevel level,
ActivityRegion activityRegion, Facility facility, Exercise exercise, BaseStatus status){
this.crewName = crewName;
this.crewImg = crewImg;
this.totalRecruits = totalRecruits;
this.crewCost = crewCost;
this.commentSimple = commentSimple;
this.comment = comment;
this.gender = gender;
this.level = level;
this.activityRegion = activityRegion;
this.facility = facility;
this.exercise = exercise;
this.status = status;
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/example/likelion12/domain/MemberCrew.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public class MemberCrew extends BaseTime {
@JoinColumn(name = "member_id")
private Member member;

public MemberCrew (BaseRole role, Crew crew, Member member, BaseStatus status){
this.role = role;
this.crew = crew;
this.member = member;
this.status = status;
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/example/likelion12/dto/PostCrewRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.likelion12.dto;

import com.example.likelion12.domain.base.BaseGender;
import com.example.likelion12.domain.base.BaseLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class PostCrewRequest {
/**
* 크루 등록 request dto
*/
private String crewName;
private String crewImg;
private Long activityRegionId;
private Long facilityId;
private Long exerciseId;
private int totalRecruits;
private int crewCost;
private String simpleComment;
private String comment;
private BaseGender gender;
private BaseLevel level;
}
13 changes: 13 additions & 0 deletions src/main/java/com/example/likelion12/dto/PostCrewResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.likelion12.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class PostCrewResponse {
/**
* 크루 등록 response dto
*/
private Long crewId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.likelion12.repository;

import com.example.likelion12.domain.ActivityRegion;
import com.example.likelion12.domain.base.BaseStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ActivityRegionRepository extends JpaRepository<ActivityRegion, Long> {

Optional<ActivityRegion> findByActivityRegionIdAndStatus(Long activityRegionId, BaseStatus status);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.likelion12.repository;

import com.example.likelion12.domain.Crew;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CrewRepository extends JpaRepository<Crew, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.likelion12.repository;

import com.example.likelion12.domain.Exercise;
import com.example.likelion12.domain.base.BaseStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ExerciseRepository extends JpaRepository<Exercise, Long> {

Optional<Exercise> findByExerciseIdAndStatus(Long exerciseId, BaseStatus status);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.likelion12.repository;

import com.example.likelion12.domain.Facility;
import com.example.likelion12.domain.base.BaseStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface FacilityRepository extends JpaRepository<Facility, Long> {

Optional<Facility> findByFacilityIdAndStatus(Long facilityId, BaseStatus status);
}
Loading
Loading