-
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.
* refactor: dto 리팩토링 (#108) * refactor: 코드 리팩토링 (#108) * feat: 학과 조회 리포지토리 (#108) * feat: 학과 조회 서비스 (#108) * feat: 학과 조회 API (#108) * feat: 시큐리티 권한 설정 (#108)
- Loading branch information
1 parent
8e3c4f3
commit 4ee4256
Showing
14 changed files
with
142 additions
and
22 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
src/main/java/com/smunity/server/domain/course/repository/course/CourseQueryRepository.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
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
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
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/smunity/server/domain/department/controller/DepartmentController.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,25 @@ | ||
package com.smunity.server.domain.department.controller; | ||
|
||
import com.smunity.server.domain.department.dto.DepartmentResponseDto; | ||
import com.smunity.server.domain.department.service.DepartmentService; | ||
import com.smunity.server.global.common.dto.ListResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/departments") | ||
public class DepartmentController { | ||
|
||
private final DepartmentService departmentService; | ||
|
||
@GetMapping | ||
public ResponseEntity<ListResponseDto<DepartmentResponseDto>> readDepartments(@RequestParam(required = false) Boolean isEditable) { | ||
ListResponseDto<DepartmentResponseDto> responseDto = departmentService.readDepartments(isEditable); | ||
return ResponseEntity.ok(responseDto); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/smunity/server/domain/department/dto/DepartmentResponseDto.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,34 @@ | ||
package com.smunity.server.domain.department.dto; | ||
|
||
import com.smunity.server.global.common.entity.Department; | ||
import com.smunity.server.global.common.entity.enums.SubDomain; | ||
import lombok.Builder; | ||
|
||
import java.util.List; | ||
|
||
@Builder | ||
public record DepartmentResponseDto( | ||
Long id, | ||
String college, | ||
String name, | ||
SubDomain subDomain, | ||
boolean isEditable, | ||
String code | ||
) { | ||
|
||
public static DepartmentResponseDto from(Department department) { | ||
return DepartmentResponseDto.builder() | ||
.id(department.getId()) | ||
.college(department.getCollege()) | ||
.name(department.getName()) | ||
.subDomain(department.getSubDomain()) | ||
.isEditable(department.isEditable()) | ||
.code(department.getCode()) | ||
.build(); | ||
} | ||
|
||
|
||
public static List<DepartmentResponseDto> from(List<Department> departments) { | ||
return departments.stream().map(DepartmentResponseDto::from).toList(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/smunity/server/domain/department/repository/DepartmentQueryRepository.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,10 @@ | ||
package com.smunity.server.domain.department.repository; | ||
|
||
import com.smunity.server.global.common.entity.Department; | ||
|
||
import java.util.List; | ||
|
||
public interface DepartmentQueryRepository { | ||
|
||
List<Department> findByIsEditable(Boolean isEditable); | ||
} |
29 changes: 29 additions & 0 deletions
29
...n/java/com/smunity/server/domain/department/repository/DepartmentQueryRepositoryImpl.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,29 @@ | ||
package com.smunity.server.domain.department.repository; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.smunity.server.global.common.entity.Department; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static com.smunity.server.global.common.entity.QDepartment.department; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class DepartmentQueryRepositoryImpl implements DepartmentQueryRepository { | ||
|
||
private final JPAQueryFactory query; | ||
|
||
@Override | ||
public List<Department> findByIsEditable(Boolean isEditable) { | ||
return query.selectFrom(department) | ||
.where(isEditableEq(isEditable)) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression isEditableEq(Boolean isEditable) { | ||
return isEditable != null ? department.isEditable.eq(isEditable) : null; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/smunity/server/domain/department/service/DepartmentService.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,25 @@ | ||
package com.smunity.server.domain.department.service; | ||
|
||
import com.smunity.server.domain.department.dto.DepartmentResponseDto; | ||
import com.smunity.server.domain.department.repository.DepartmentQueryRepository; | ||
import com.smunity.server.global.common.dto.ListResponseDto; | ||
import com.smunity.server.global.common.entity.Department; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class DepartmentService { | ||
|
||
private final DepartmentQueryRepository departmentQueryRepository; | ||
|
||
public ListResponseDto<DepartmentResponseDto> readDepartments(Boolean isEditable) { | ||
List<Department> departments = departmentQueryRepository.findByIsEditable(isEditable); | ||
List<DepartmentResponseDto> responseDtoList = DepartmentResponseDto.from(departments); | ||
return ListResponseDto.from(responseDtoList); | ||
} | ||
} |
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
1 change: 0 additions & 1 deletion
1
src/main/java/com/smunity/server/domain/major/repository/MajorQueryRepository.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
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
8 changes: 4 additions & 4 deletions
8
...domain/member/dto/SubjectResponseDto.java → ...er/global/common/dto/ListResponseDto.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
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