Skip to content

Commit

Permalink
[feat/#62] Refactor: follow the API naming rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mjms0214 committed Aug 6, 2023
1 parent 2db6753 commit 2a2a6cd
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sookmyung.moaroom.Dto.responseAssignmentDto;
import sookmyung.moaroom.Model.Assignment;
import sookmyung.moaroom.Model.Url;
import sookmyung.moaroom.Respository.AssignmentRepository;
import sookmyung.moaroom.Service.AssignmentService;

import java.util.List;
Expand All @@ -17,33 +18,44 @@ public class AssignmentController {
@Autowired
AssignmentService assignmentService;

@PostMapping("/assignment/new")
// test용
@Autowired
AssignmentRepository assignmentRepository;

@PostMapping("/assignment")
public String addAssignment(@Validated @RequestBody requestAssignmentDto newAssignment){
return assignmentService.save(newAssignment);
}

@PutMapping("/assignment/{assignment_id}")
@PutMapping("/assignments/{assignment_id}")
public Assignment updateAssignment(@PathVariable(name = "assignment_id") String id, @Validated @RequestBody requestAssignmentDto existAssignment){
return assignmentService.modify(id, existAssignment);
}

@GetMapping("/assignment/all/{user_id}")
@GetMapping("/assignments/{user_id}")
public List<responseAssignmentDto> allLecture(@PathVariable("user_id") String id){
return assignmentService.findAll(id);
}

@GetMapping("/assignment/{assignment_id}")
@GetMapping("/assignments/{assignment_id}")
public Assignment oneAssignment(@PathVariable("assignment_id") String id){
return assignmentService.findOne(id);
}

@DeleteMapping("/assignment/{assignment_title}")
@DeleteMapping("/assignments/{assignment_title}")
public String deleteAssignment(@PathVariable("assignment_title") String title){
return assignmentService.delete(title);
}

@GetMapping("/assignment/list/{assignment_id}")
@GetMapping("/assignments/{assignment_id}/students-urls")
public List<Url> studentUrlList(@PathVariable("assignment_id") String id){
return assignmentService.findStudentUrlList(id);
}

// test용
@GetMapping("/assignments")
public List<Assignment> allLecture(){
return assignmentRepository.findAll();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,42 @@ public class LectureController {
@Autowired
EnrollService enrollService;

@PostMapping("/lecture/new")
@PostMapping("/lecture")
public String addLecture(@Validated @RequestBody requestLectureDto newLecture){
return lectureService.save(newLecture);
}

@PutMapping("/lecture/{lecture_id}")
@PutMapping("/lectures/{lecture_id}")
public Lecture updateLecture(@PathVariable(name = "lecture_id") String id, @Validated @RequestBody requestLectureDto existLecture){
return lectureService.modify(id, existLecture);
}

@GetMapping("/lecture/all/{user_id}")
@GetMapping("/lectures/{user_id}")
public List<responseLectureDto> allLecture(@PathVariable(name = "user_id") String id){
return lectureService.findAll(id);
}

@GetMapping("/lecture/{lecture_id}")
@GetMapping("/lectures/{lecture_id}")
public Lecture oneLecture(@PathVariable("lecture_id") String id){
return lectureService.findOne(id);
}

@DeleteMapping("/lecture/{lecture_title}/{lecture_room}")
public String deleteLecture(@PathVariable("lecture_title") String title, @PathVariable("lecture_room") Integer room){
@DeleteMapping("/lectures/title-class")
public String deleteLecture(@RequestParam("lecture_title") String title, @RequestParam("lecture_class") Integer room){
return lectureService.delete(title, room);
}

@PostMapping("/lecture/enroll")
@PostMapping("/lectures/students/enroll")
public String enrollLecture(@Validated @RequestBody requestEnrollDto enroll){
return enrollService.save(enroll);
}

@GetMapping("/lecture/list/{lecture_id}")
@GetMapping("/lectures/{lecture_id}/students")
public List<Users> studentList(@PathVariable("lecture_id") String id){
return enrollService.findStudentList(id);
}

@GetMapping("/lecture/info/{assignment_id}")
@GetMapping("/lectures/info/{assignment_id}")
public responseLectureInfoDto lectureInfo(@PathVariable("assignment_id") String id){
return lectureService.findLectureInfo(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public class StepController {
@Autowired
StepService stepService;

@PostMapping("/assignment/score")
@PostMapping("/assignments/score")
public void scoring(@RequestBody requestScoreDto score){
stepService.scoring(score);
}

@GetMapping("/step/{assignment_id}")
@GetMapping("/steps/{assignment_id}")
public List<responseStepDto> findStepList(@PathVariable(name = "assignment_id") String id){
return stepService.findStepList(id);
}

@GetMapping("/step/all")
@GetMapping("/steps")
public List<Step> allStep() {
return stepService.allStep();
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/sookmyung/moaroom/Controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class UserController {
@Autowired
UserService userService;

@PostMapping("/user/new")
@PostMapping("/user")
public String addUser(@Validated @RequestBody requestUserDto newUser){
return userService.save(newUser);
}
Expand All @@ -28,27 +28,27 @@ public UUID login(@Validated @RequestBody requestLoginDto loginUser){
return userService.login(loginUser);
}

@PutMapping("/user/{user_id}")
@PutMapping("/users/{user_id}")
public Users updateUser(@PathVariable(name = "user_id")String id, @Validated @RequestBody requestUserDto existUser){
return userService.modify(id, existUser);
}

@GetMapping("/user/all")
@GetMapping("/users")
public List<Users> allUser(){
return userService.findAll();
}

@GetMapping("/user/{user_id}")
@GetMapping("/users/{user_id}")
public Users oneUser(@PathVariable("user_id") String id){
return userService.findOne(id);
}

@DeleteMapping("/user/{user_id}")
@DeleteMapping("/users/{user_id}")
public String deleteUser(@PathVariable("user_id") String id){
return userService.delete(id);
}

@GetMapping("/url/{user_id}")
@GetMapping("/urls/{user_id}")
public Url getUrl(@PathVariable("user_id") String id){
return userService.getUrl(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class requestAssignmentDto {
@NotNull
private UUID lecture_id;
@NotNull
private UUID user_id;
private UUID professor_id;
@NotNull
private String title;
private LocalDateTime start_date;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/sookmyung/moaroom/Dto/requestEnrollDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@Data
public class requestEnrollDto {
@NotNull
private UUID lecture_id;
private UUID lectureId;
@NotNull
private UUID student_id;
private UUID studentId;
}
4 changes: 2 additions & 2 deletions src/main/java/sookmyung/moaroom/Dto/requestLectureDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class requestLectureDto {
@NotNull
private String title;
@NotNull
private UUID professor_id;
private UUID professorId;
@NotNull
private Integer room;
private Integer room_count;
private Integer roomCount;

}
6 changes: 3 additions & 3 deletions src/main/java/sookmyung/moaroom/Dto/requestScoreDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
@Data
public class requestScoreDto {
@NotNull
UUID lecture_id;
UUID lectureId;
@NotNull
UUID assignment_id;
UUID assignmentId;

@NotNull
UUID user_id;
UUID userId;

@NotNull
Integer score;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sookmyung/moaroom/Dto/requestUserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class requestUserDto {
private String password;
@NotNull
private String name;
private Integer user_num;
private Integer userNum;
@NotNull
private Integer role;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package sookmyung.moaroom.Service;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -61,7 +60,7 @@ public String save(requestAssignmentDto data) {

assignmentRepository.save(newAssignment);

Url professorUrl = urlRepository.findById(data.getUser_id()).get();
Url professorUrl = urlRepository.findById(data.getProfessor_id()).get();
final String user_url = professorUrl.getApiEndpoint();

// infra측에 req: users model, res: url model
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/sookmyung/moaroom/Service/EnrollService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package sookmyung.moaroom.Service;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -49,17 +48,17 @@ public void enroll(UUID professorId, UUID lectureId){
public String save(requestEnrollDto data){
try {

Users existUser = userRepository.findById(data.getStudent_id()).get();
Users existUser = userRepository.findById(data.getStudentId()).get();
if (existUser.equals(null)){
throw new Exception("존재하지 않는 사용자");
}
if(existUser.getClasses()==null){
ArrayList<String> newClass = new ArrayList<>();
newClass.add(data.getLecture_id().toString());
newClass.add(data.getLectureId().toString());
existUser.setClasses(newClass);
} else{
ArrayList<String> classList = existUser.getClasses();
classList.add(data.getLecture_id().toString());
classList.add(data.getLectureId().toString());
existUser.setClasses(classList);
}
userRepository.save(existUser);
Expand All @@ -77,7 +76,7 @@ public String save(requestEnrollDto data){

HashMap<String, Object> reqBody = new HashMap<>();
reqBody.put("student_info", student_info);
reqBody.put("lecture_id",data.getLecture_id());
reqBody.put("lecture_id",data.getLectureId());
ResponseEntity<responseUrlDto> response = restTemplate.postForEntity(
"http://59.15.113.146:8003/student/",
reqBody,
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/sookmyung/moaroom/Service/LectureService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public String save(requestLectureDto data) {
Lecture newLecture = new Lecture();
newLecture.setLectureId(UUID.randomUUID());
newLecture.setTitle(data.getTitle());
newLecture.setProfessorId(data.getProfessor_id());
newLecture.setProfessorId(data.getProfessorId());
newLecture.setRoom(data.getRoom());

if (data.getRoom_count()!= null){
newLecture.setRoomCount(data.getRoom_count());
if (data.getRoomCount()!= null){
newLecture.setRoomCount(data.getRoomCount());
} else {
newLecture.setRoomCount(30);
}
Expand All @@ -58,13 +58,13 @@ public Lecture modify(String lecture_id, requestLectureDto data){
if (lectureRepository.findById(UUID.fromString(lecture_id)).isEmpty()){
throw new Exception("존재하지 않는 강의");
}
if (!data.getProfessor_id().equals(existLecture.getProfessorId())){
if (!data.getProfessorId().equals(existLecture.getProfessorId())){
throw new Exception("수정 권한이 없는 사용자");
}

existLecture.setTitle(data.getTitle());
existLecture.setRoom(data.getRoom());
existLecture.setRoomCount(data.getRoom_count());
existLecture.setRoomCount(data.getRoomCount());

return lectureRepository.save(existLecture);
} catch (Exception e){
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/sookmyung/moaroom/Service/StepService.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public void startAssignmentLater(UUID lectureId, UUID assignmentId, LocalDateTim
}

public void scoring(requestScoreDto data){
Users student = userRepository.findById(data.getUser_id()).get();
if(student.getClasses()!=null&student.getClasses().contains(data.getLecture_id().toString())){
StepPK stepPK = new StepPK(data.getAssignment_id(), data.getLecture_id(), data.getUser_id());
Users student = userRepository.findById(data.getUserId()).get();
if(student.getClasses()!=null&student.getClasses().contains(data.getLectureId().toString())){
StepPK stepPK = new StepPK(data.getAssignmentId(), data.getLectureId(), data.getUserId());
Step existStep = stepRepository.findById(stepPK).get();
existStep.setStep(Process.DONE.getRole());
existStep.setScore(data.getScore());
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/sookmyung/moaroom/Service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package sookmyung.moaroom.Service;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -40,8 +39,8 @@ public String save(requestUserDto data) {
newUser.setRole(2);
}

if (data.getUser_num() != null) {
newUser.setUserNum(data.getUser_num());
if (data.getUserNum() != null) {
newUser.setUserNum(data.getUserNum());
} else{
newUser.setUserNum(null);
}
Expand Down Expand Up @@ -99,8 +98,8 @@ public Users modify(String user_id, requestUserDto data){
existUser.setRole(2);
}

if(data.getUser_num() != null){
existUser.setUserNum(data.getUser_num());
if(data.getUserNum() != null){
existUser.setUserNum(data.getUserNum());
}
return userRepository.save(existUser);
} catch (Exception e){
Expand Down
Loading

0 comments on commit 2a2a6cd

Please sign in to comment.