-
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 #169 from urinaner/feature/164
[BE] 세미나실, 시간표 CRUD 설계
- Loading branch information
Showing
18 changed files
with
773 additions
and
53 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
41 changes: 41 additions & 0 deletions
41
...rc/main/java/org/example/backend/seminarRoom/domain/controller/SeminarRoomController.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,41 @@ | ||
package org.example.backend.seminarRoom.domain.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.backend.seminarRoom.domain.dto.SeminarRoomReqDto; | ||
import org.example.backend.seminarRoom.domain.dto.SeminarRoomResDto; | ||
import org.example.backend.seminarRoom.service.SeminarRoomService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/seminar-rooms") | ||
public class SeminarRoomController { | ||
private final SeminarRoomService seminarRoomService; | ||
|
||
@PostMapping | ||
public ResponseEntity<SeminarRoomResDto> createSeminarRoom(@RequestBody SeminarRoomReqDto reqDto) { | ||
SeminarRoomResDto resDto = seminarRoomService.createSeminarRoom(reqDto); | ||
return ResponseEntity.ok(resDto); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<SeminarRoomResDto> getSeminarRoom(@PathVariable Long id) { | ||
SeminarRoomResDto resDto = seminarRoomService.getSeminarRoom(id); | ||
return ResponseEntity.ok(resDto); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<SeminarRoomResDto> updateSeminarRoom( | ||
@PathVariable Long id, | ||
@RequestBody SeminarRoomReqDto reqDto) { | ||
SeminarRoomResDto resDto = seminarRoomService.updateSeminarRoom(id, reqDto); | ||
return ResponseEntity.ok(resDto); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteSeminarRoom(@PathVariable Long id) { | ||
seminarRoomService.deleteSeminarRoom(id); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
backend/src/main/java/org/example/backend/seminarRoom/domain/dto/SeminarRoomReqDto.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,33 @@ | ||
package org.example.backend.seminarRoom.domain.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class SeminarRoomReqDto { | ||
private String name; | ||
private Integer personCapacity; | ||
private String place; | ||
private String image; | ||
|
||
@Builder | ||
private SeminarRoomReqDto(String name, Integer personCapacity, String place, String image) { | ||
this.name = name; | ||
this.personCapacity = personCapacity; | ||
this.place = place; | ||
this.image = image; | ||
} | ||
|
||
public static SeminarRoomReqDto of(String name, Integer personCapacity, String place, String image) { | ||
return SeminarRoomReqDto.builder() | ||
.name(name) | ||
.personCapacity(personCapacity) | ||
.place(place) | ||
.image(image) | ||
.build(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
backend/src/main/java/org/example/backend/seminarRoom/domain/dto/SeminarRoomResDto.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,36 @@ | ||
package org.example.backend.seminarRoom.domain.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.example.backend.seminarRoom.domain.SeminarRoom; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class SeminarRoomResDto { | ||
private Long id; | ||
private String name; | ||
private Integer personCapacity; | ||
private String place; | ||
private String image; | ||
|
||
@Builder | ||
private SeminarRoomResDto(Long id, String name, Integer personCapacity, String place, String image) { | ||
this.id = id; | ||
this.name = name; | ||
this.personCapacity = personCapacity; | ||
this.place = place; | ||
this.image = image; | ||
} | ||
|
||
public static SeminarRoomResDto of(SeminarRoom seminarRoom) { | ||
return SeminarRoomResDto.builder() | ||
.id(seminarRoom.getId()) | ||
.name(seminarRoom.getName()) | ||
.personCapacity(seminarRoom.getPersonCapacity()) | ||
.place(seminarRoom.getPlace()) | ||
.image(seminarRoom.getImage()) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/org/example/backend/seminarRoom/exception/SeminarRoomException.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,15 @@ | ||
package org.example.backend.seminarRoom.exception; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.backend.common.exception.BaseException; | ||
import org.example.backend.common.exception.BaseExceptionType; | ||
import org.example.backend.seminar.exception.SeminarExceptionType; | ||
|
||
@RequiredArgsConstructor | ||
public class SeminarRoomException extends BaseException { | ||
private final SeminarRoomExceptionType exceptionType; | ||
@Override | ||
public BaseExceptionType exceptionType() { | ||
return exceptionType; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...end/src/main/java/org/example/backend/seminarRoom/exception/SeminarRoomExceptionType.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 org.example.backend.seminarRoom.exception; | ||
|
||
import static org.springframework.http.HttpStatus.BAD_REQUEST; | ||
import static org.springframework.http.HttpStatus.NOT_FOUND; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.backend.common.exception.BaseExceptionType; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@RequiredArgsConstructor | ||
public enum SeminarRoomExceptionType implements BaseExceptionType { | ||
NOT_FOUND_SEMINAR_ROOM(NOT_FOUND, "세미나룸를 찾을 수 없습니다"), | ||
INVALID_NAME_VALUE(BAD_REQUEST, "세미나실 이름은 필수입니다."), | ||
INVALID_CAPACITY(BAD_REQUEST, "수용 인원은 1명 이상이어야 합니다."); | ||
; | ||
|
||
private final HttpStatus httpStatus; | ||
private final String errorMessage; | ||
|
||
@Override | ||
public HttpStatus httpStatus() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String errorMessage() { | ||
return null; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/org/example/backend/seminarRoom/repository/SeminarRoomRepository.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,7 @@ | ||
package org.example.backend.seminarRoom.repository; | ||
|
||
import org.example.backend.seminarRoom.domain.SeminarRoom; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SeminarRoomRepository extends JpaRepository<SeminarRoom, Long> { | ||
} |
64 changes: 64 additions & 0 deletions
64
backend/src/main/java/org/example/backend/seminarRoom/service/SeminarRoomService.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,64 @@ | ||
package org.example.backend.seminarRoom.service; | ||
|
||
import static org.example.backend.seminarRoom.exception.SeminarRoomExceptionType.INVALID_CAPACITY; | ||
import static org.example.backend.seminarRoom.exception.SeminarRoomExceptionType.INVALID_NAME_VALUE; | ||
import static org.example.backend.seminarRoom.exception.SeminarRoomExceptionType.NOT_FOUND_SEMINAR_ROOM; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.backend.seminarRoom.domain.SeminarRoom; | ||
import org.example.backend.seminarRoom.domain.dto.SeminarRoomReqDto; | ||
import org.example.backend.seminarRoom.domain.dto.SeminarRoomResDto; | ||
import org.example.backend.seminarRoom.exception.SeminarRoomException; | ||
import org.example.backend.seminarRoom.repository.SeminarRoomRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class SeminarRoomService { | ||
private final SeminarRoomRepository seminarRoomRepository; | ||
|
||
@Transactional | ||
public SeminarRoomResDto createSeminarRoom(SeminarRoomReqDto reqDto) { | ||
validateSeminarRoom(reqDto); | ||
|
||
SeminarRoom seminarRoom = SeminarRoom.of(reqDto); | ||
seminarRoomRepository.save(seminarRoom); | ||
|
||
return SeminarRoomResDto.of(seminarRoom); | ||
} | ||
|
||
public SeminarRoomResDto getSeminarRoom(Long id) { | ||
SeminarRoom seminarRoom = seminarRoomRepository.findById(id) | ||
.orElseThrow(() -> new SeminarRoomException(NOT_FOUND_SEMINAR_ROOM)); | ||
return SeminarRoomResDto.of(seminarRoom); | ||
} | ||
|
||
@Transactional | ||
public SeminarRoomResDto updateSeminarRoom(Long id, SeminarRoomReqDto reqDto) { | ||
validateSeminarRoom(reqDto); | ||
|
||
SeminarRoom seminarRoom = seminarRoomRepository.findById(id) | ||
.orElseThrow(() -> new SeminarRoomException(NOT_FOUND_SEMINAR_ROOM)); | ||
|
||
seminarRoom.update(reqDto); | ||
return SeminarRoomResDto.of(seminarRoom); | ||
} | ||
|
||
@Transactional | ||
public void deleteSeminarRoom(Long id) { | ||
SeminarRoom seminarRoom = seminarRoomRepository.findById(id) | ||
.orElseThrow(() -> new SeminarRoomException(NOT_FOUND_SEMINAR_ROOM)); | ||
seminarRoomRepository.delete(seminarRoom); | ||
} | ||
|
||
private void validateSeminarRoom(SeminarRoomReqDto reqDto) { | ||
if (reqDto.getName() == null || reqDto.getName().trim().isEmpty()) { | ||
throw new SeminarRoomException(INVALID_NAME_VALUE); | ||
} | ||
if (reqDto.getPersonCapacity() == null || reqDto.getPersonCapacity() <= 0) { | ||
throw new SeminarRoomException(INVALID_CAPACITY); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
backend/src/main/java/org/example/backend/timetable/controller/TimetableController.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,48 @@ | ||
package org.example.backend.timetable.controller; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.example.backend.timetable.domain.dto.TimetableReqDto; | ||
import org.example.backend.timetable.domain.dto.TimetableResDto; | ||
import org.example.backend.timetable.service.TimetableService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/timetables") | ||
public class TimetableController { | ||
private final TimetableService timetableService; | ||
|
||
@PostMapping | ||
public ResponseEntity<TimetableResDto> createTimetable(@RequestBody TimetableReqDto reqDto) { | ||
TimetableResDto resDto = timetableService.createTimetable(reqDto); | ||
return ResponseEntity.ok(resDto); | ||
} | ||
@GetMapping | ||
public ResponseEntity<List<TimetableResDto>> getAllTimetables() { | ||
List<TimetableResDto> timetables = timetableService.getAllTimetables(); | ||
return ResponseEntity.ok(timetables); | ||
} | ||
|
||
@PutMapping("/{timetableId}") | ||
public ResponseEntity<TimetableResDto> updateTimetable( | ||
@PathVariable Long timetableId, | ||
@RequestBody TimetableReqDto reqDto) { | ||
TimetableResDto resDto = timetableService.updateTimetable(timetableId, reqDto); | ||
return ResponseEntity.ok(resDto); | ||
} | ||
|
||
@DeleteMapping("/{timetableId}") | ||
public ResponseEntity<Void> deleteTimetable(@PathVariable Long timetableId) { | ||
timetableService.deleteTimetable(timetableId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
Oops, something went wrong.