-
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 #17 from ecolink-JOIN/feature/study
[Feat] 스터디 모집 API 추가
- Loading branch information
Showing
24 changed files
with
445 additions
and
11 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/join/core/address/repository/AddressReaderImpl.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,24 @@ | ||
package com.join.core.address.repository; | ||
|
||
import com.join.core.address.domain.Address; | ||
import com.join.core.address.service.AddressReader; | ||
import com.join.core.common.exception.ErrorCode; | ||
import com.join.core.common.exception.impl.InvalidSelectionException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class AddressReaderImpl implements AddressReader { | ||
|
||
private final AddressRepository addressRepository; | ||
|
||
@Transactional(readOnly = true) | ||
@Override | ||
public Address getAddressByLocation(String province, String city) { | ||
return addressRepository.findByProvinceAndCity(province, city) | ||
.orElseThrow(() -> new InvalidSelectionException(ErrorCode.ADDRESS_SELECTION_REQUIRED)); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/join/core/address/repository/AddressRepository.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,11 @@ | ||
package com.join.core.address.repository; | ||
|
||
import com.join.core.address.domain.Address; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface AddressRepository extends JpaRepository<Address, Long> { | ||
Optional<Address> findByProvinceAndCity(String province, String city); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/join/core/address/service/AddressReader.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,8 @@ | ||
package com.join.core.address.service; | ||
|
||
import com.join.core.address.domain.Address; | ||
|
||
public interface AddressReader { | ||
Address getAddressByLocation(String province, String city); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/join/core/auth/repository/AvatarReaderImpl.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,24 @@ | ||
package com.join.core.auth.repository; | ||
|
||
import com.join.core.auth.service.AvatarReader; | ||
import com.join.core.avatar.domain.Avatar; | ||
import com.join.core.common.exception.ErrorCode; | ||
import com.join.core.common.exception.impl.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class AvatarReaderImpl implements AvatarReader { | ||
|
||
private final AvatarRepository avatarRepository; | ||
|
||
@Transactional(readOnly = true) | ||
@Override | ||
public Avatar getAvatarByToken(String avatarToken) { | ||
return avatarRepository.findByAvatarToken(avatarToken) | ||
.orElseThrow(() -> new EntityNotFoundException(ErrorCode.AVATAR_NOT_FOUND)); | ||
} | ||
|
||
} |
5 changes: 4 additions & 1 deletion
5
src/main/java/com/join/core/auth/repository/AvatarRepository.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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.join.core.auth.repository; | ||
|
||
import com.join.core.avatar.domain.Avatar; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.join.core.avatar.domain.Avatar; | ||
import java.util.Optional; | ||
|
||
public interface AvatarRepository extends JpaRepository<Avatar, Long> { | ||
Optional<Avatar> findByAvatarToken(String avatarToken); | ||
|
||
} |
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,8 @@ | ||
package com.join.core.auth.service; | ||
|
||
import com.join.core.avatar.domain.Avatar; | ||
|
||
public interface AvatarReader { | ||
Avatar getAvatarByToken(String avatarToken); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/join/core/category/repository/CategoryReaderImpl.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,24 @@ | ||
package com.join.core.category.repository; | ||
|
||
import com.join.core.category.domain.Category; | ||
import com.join.core.category.service.CategoryReader; | ||
import com.join.core.common.exception.ErrorCode; | ||
import com.join.core.common.exception.impl.InvalidSelectionException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class CategoryReaderImpl implements CategoryReader { | ||
|
||
private final CategoryRepository categoryRepository; | ||
|
||
@Transactional(readOnly = true) | ||
@Override | ||
public Category getCategoryByName(String categoryName) { | ||
return categoryRepository.findByCategoryName(categoryName) | ||
.orElseThrow(() -> new InvalidSelectionException(ErrorCode.CATEGORY_SELECTION_REQUIRED)); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/join/core/category/repository/CategoryRepository.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,11 @@ | ||
package com.join.core.category.repository; | ||
|
||
import com.join.core.category.domain.Category; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface CategoryRepository extends JpaRepository<Category, Long> { | ||
Optional<Category> findByCategoryName(String categoryName); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/join/core/category/service/CategoryReader.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,8 @@ | ||
package com.join.core.category.service; | ||
|
||
import com.join.core.category.domain.Category; | ||
|
||
public interface CategoryReader { | ||
Category getCategoryByName(String categoryName); | ||
|
||
} |
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 |
---|---|---|
@@ -1,6 +1,21 @@ | ||
package com.join.core.common.constant; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum DayType { | ||
MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY | ||
SUN("일"), | ||
MON("월"), | ||
TUE("화"), | ||
WED("수"), | ||
THU("목"), | ||
FRI("금"), | ||
SAT("토"); | ||
|
||
private final String name; | ||
|
||
DayType(String name) { | ||
this.name = name; | ||
} | ||
|
||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/join/core/common/exception/impl/EntityNotFoundException.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.join.core.common.exception.impl; | ||
|
||
import com.join.core.common.exception.ErrorCode; | ||
import com.join.core.common.exception.GeneralException; | ||
|
||
public class EntityNotFoundException extends GeneralException { | ||
|
||
public EntityNotFoundException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/join/core/common/exception/impl/InvalidSelectionException.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.join.core.common.exception.impl; | ||
|
||
import com.join.core.common.exception.ErrorCode; | ||
import com.join.core.common.exception.GeneralException; | ||
|
||
public class InvalidSelectionException extends GeneralException { | ||
|
||
public InvalidSelectionException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/join/core/schedule/dto/request/StudyScheduleRequest.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,27 @@ | ||
package com.join.core.schedule.dto.request; | ||
|
||
import com.join.core.common.constant.DayType; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalTime; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class StudyScheduleRequest { | ||
|
||
@Schema(description = "요일", example = "MON") | ||
@NotNull | ||
private DayType weekOfDay; | ||
|
||
@Schema(description = "시작 시간", example = "10:00") | ||
@NotNull | ||
private LocalTime stTime; | ||
|
||
@Schema(description = "종료 시간", example = "12:00") | ||
@NotNull | ||
private LocalTime endTime; | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/join/core/study/controller/StudyController.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 com.join.core.study.controller; | ||
|
||
import com.join.core.auth.domain.UserPrincipal; | ||
import com.join.core.common.response.ApiResponse; | ||
import com.join.core.study.dto.request.StudyRecruitRequest; | ||
import com.join.core.study.service.StudyRecruitService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("${api.prefix}/study") | ||
public class StudyController { | ||
|
||
private final StudyRecruitService studyRecruitService; | ||
|
||
@Tag(name = "${swagger.tag.study}") | ||
@Operation(summary = "스터디 모집 - 인증 필수", | ||
description = "스터디 모집 - 인증 필수", | ||
security = {@SecurityRequirement(name = "session-token")}) | ||
@PreAuthorize("hasRole('USER')") | ||
@PostMapping("/recruit") | ||
public ApiResponse<Void> createStudy(@AuthenticationPrincipal UserPrincipal principal, | ||
@RequestBody StudyRecruitRequest recruitRequest) { | ||
studyRecruitService.createStudy(principal.getAvatarToken(), recruitRequest); | ||
return ApiResponse.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
Oops, something went wrong.