-
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.
* feat: Add lecture entity * feat: Add userlecture entity * feat: Add lecture, userlecture repo * feat: Add all lectures api * feat: Add 'Read User’s Lecture List' api * feat: Add 'Update User’s Lecture List' api * fix: Change word to fit API spec Co-authored-by: ParkSangJun <30718444+cosmoquester@users.noreply.github.com> * fix: Modify duplicated func name Co-authored-by: ParkSangJun <30718444+cosmoquester@users.noreply.github.com> * fix: Change lecture_id to fit API spec * fix: Remove path for authorization Co-authored-by: ParkSangJun <30718444+cosmoquester@users.noreply.github.com>
- Loading branch information
1 parent
eba09db
commit 6fe65c3
Showing
9 changed files
with
207 additions
and
4 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/com/de_alone/dokkang/controllers/LectureController.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,31 @@ | ||
package com.de_alone.dokkang.controllers; | ||
|
||
import com.de_alone.dokkang.models.Lecture; | ||
import com.de_alone.dokkang.payload.response.LectureResponse; | ||
import com.de_alone.dokkang.repository.LectureRepository; | ||
import com.de_alone.dokkang.security.jwt.JwtUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@CrossOrigin(origins = "*", maxAge = 3600) | ||
@RestController | ||
@RequestMapping("/lectures") | ||
public class LectureController { | ||
@Autowired | ||
LectureRepository lectureRepository; | ||
|
||
@Autowired | ||
JwtUtils jwtUtils; | ||
|
||
@GetMapping | ||
public ResponseEntity<?> getLectures(@RequestParam(required = false) String jwt) { | ||
|
||
List<Lecture> lectures = lectureRepository.findAll(); | ||
|
||
return ResponseEntity.status(HttpStatus.CREATED).body(new LectureResponse("ok", lectures)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.de_alone.dokkang.models; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.NotBlank; | ||
|
||
|
||
@Entity | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class Lecture { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@NotBlank | ||
private String no; | ||
|
||
@NotBlank | ||
private String name; | ||
|
||
@NotBlank | ||
private String professor; | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/com/de_alone/dokkang/models/UserLecture.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,42 @@ | ||
package com.de_alone.dokkang.models; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
|
||
@Entity | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class UserLecture { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "user_id") | ||
private User userId; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "lecture_id") | ||
private Lecture lectureId; | ||
|
||
public User getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(User userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public Lecture getLectureId() { | ||
return lectureId; | ||
} | ||
|
||
public void setLectureId(Lecture lectureId) { | ||
this.lectureId = lectureId; | ||
} | ||
|
||
} | ||
|
12 changes: 12 additions & 0 deletions
12
src/main/java/com/de_alone/dokkang/payload/request/UpdateLectureRequest.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.de_alone.dokkang.payload.request; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
public class UpdateLectureRequest { | ||
private List<Long> lecture_ids; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/de_alone/dokkang/payload/response/LectureResponse.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,18 @@ | ||
package com.de_alone.dokkang.payload.response; | ||
|
||
import com.de_alone.dokkang.models.Lecture; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class LectureResponse { | ||
private String status; | ||
|
||
private List<Lecture> lectures; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/de_alone/dokkang/repository/LectureRepository.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 com.de_alone.dokkang.repository; | ||
|
||
import com.de_alone.dokkang.models.Lecture; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface LectureRepository extends JpaRepository<Lecture, Long> { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/de_alone/dokkang/repository/UserLectureRepository.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.de_alone.dokkang.repository; | ||
|
||
import com.de_alone.dokkang.models.User; | ||
import com.de_alone.dokkang.models.UserLecture; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface UserLectureRepository extends JpaRepository<UserLecture, Long> { | ||
List<UserLecture> findByUserId(Optional<User> userId); | ||
|
||
@Query(value = "select ul.lectureId.id " + | ||
"from UserLecture ul " + | ||
"where ul.userId.id = :user_id") | ||
List<Long> findLectureById(@Param("user_id") Long user_id); | ||
@Modifying | ||
@Transactional | ||
@Query(value = "delete " + | ||
"from UserLecture ul " + | ||
"where ul.userId.id = :user_id") | ||
Integer deleteLectureById(@Param("user_id") Long user_id); | ||
} |