-
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 #52 from Domitory-CheckMate/feature/51-department
[feat] 학과정보
- Loading branch information
Showing
8 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/org/gachon/checkmate/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,30 @@ | ||
package org.gachon.checkmate.domain.department.controller; | ||
|
||
|
||
import jakarta.websocket.server.PathParam; | ||
import lombok.RequiredArgsConstructor; | ||
import org.gachon.checkmate.domain.department.dto.response.DepartmentNameResponseDto; | ||
import org.gachon.checkmate.domain.department.service.DepartmentService; | ||
import org.gachon.checkmate.global.common.SuccessResponse; | ||
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; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/department") | ||
public class DepartmentController { | ||
|
||
private final DepartmentService departmentService; | ||
|
||
@GetMapping("") | ||
public ResponseEntity<SuccessResponse<?>> getDepartments(@RequestParam(value = "univ") final String univ, | ||
@RequestParam(value = "searchText") final String searchText) { | ||
List<DepartmentNameResponseDto> responseDtos = departmentService.getDepartments(univ, searchText); | ||
return SuccessResponse.ok(responseDtos); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...n/java/org/gachon/checkmate/domain/department/dto/response/DepartmentNameResponseDto.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,14 @@ | ||
package org.gachon.checkmate.domain.department.dto.response; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
|
||
public record DepartmentNameResponseDto( | ||
String department, | ||
String college | ||
) { | ||
@QueryProjection | ||
public DepartmentNameResponseDto(String department, String college) { | ||
this.department = department; | ||
this.college = college; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/gachon/checkmate/domain/department/entity/Department.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 org.gachon.checkmate.domain.department.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder(access = AccessLevel.PRIVATE) | ||
@Getter | ||
@Entity | ||
public class Department { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "department_id") | ||
private Long id; | ||
@Column(name = "university") | ||
private String university; | ||
@Column(name = "department_name") | ||
private String departmentName; | ||
@Column(name = "college") | ||
private String college; | ||
@Column(name = "university_series") | ||
private String universitySeries; | ||
} |
10 changes: 10 additions & 0 deletions
10
...in/java/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepository.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 org.gachon.checkmate.domain.department.repository; | ||
|
||
import org.gachon.checkmate.domain.department.dto.response.DepartmentNameResponseDto; | ||
|
||
import java.util.List; | ||
|
||
public interface DepartmentCustomRepository { | ||
|
||
List<DepartmentNameResponseDto> findDepartmentName(String univ, String searchDepartText); | ||
} |
40 changes: 40 additions & 0 deletions
40
...ava/org/gachon/checkmate/domain/department/repository/DepartmentCustomRepositoryImpl.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,40 @@ | ||
package org.gachon.checkmate.domain.department.repository; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.gachon.checkmate.domain.department.dto.response.DepartmentNameResponseDto; | ||
import org.gachon.checkmate.domain.department.dto.response.QDepartmentNameResponseDto; | ||
|
||
import java.util.List; | ||
|
||
import static org.gachon.checkmate.domain.department.entity.QDepartment.department; | ||
|
||
|
||
@RequiredArgsConstructor | ||
public class DepartmentCustomRepositoryImpl implements DepartmentCustomRepository{ | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
@Override | ||
public List<DepartmentNameResponseDto> findDepartmentName(String univ, String searchDepartText) { | ||
return jpaQueryFactory | ||
.select(new QDepartmentNameResponseDto( | ||
department.departmentName, | ||
department.college | ||
)) | ||
.from(department) | ||
.where( | ||
eqUniversity(univ), | ||
containsDepartmentName(searchDepartText) | ||
) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression eqUniversity(String univ) { | ||
return department.university.eq(univ); | ||
} | ||
|
||
private BooleanExpression containsDepartmentName(String searchDepartText) { | ||
return department.departmentName.containsIgnoreCase(searchDepartText); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/gachon/checkmate/domain/department/repository/DepartmentRepository.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 org.gachon.checkmate.domain.department.repository; | ||
|
||
import org.gachon.checkmate.domain.department.entity.Department; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface DepartmentRepository extends JpaRepository<Department, Long>, DepartmentCustomRepository { | ||
List<Department> findByCollege(String college); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/gachon/checkmate/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 org.gachon.checkmate.domain.department.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.gachon.checkmate.domain.department.dto.response.DepartmentNameResponseDto; | ||
import org.gachon.checkmate.domain.department.repository.DepartmentRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional | ||
@Service | ||
public class DepartmentService { | ||
|
||
private final DepartmentRepository departmentRepository; | ||
|
||
public List<DepartmentNameResponseDto> getDepartments(String univ, String department) { | ||
return getDepartmentsName(univ, department); | ||
} | ||
|
||
private List<DepartmentNameResponseDto> getDepartmentsName(String univ, String department) { | ||
return departmentRepository.findDepartmentName(univ, department); | ||
} | ||
} |
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