-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
도서 추천 api #105
도서 추천 api #105
Changes from 7 commits
d354334
ee3d70d
bbeab3a
aba0562
25a904a
87fc65c
ed59e38
01ac3a2
e36184f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.mindway.server.v2.domain.rec.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Table(name = "recommend") | ||
public class Rec { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private String title; | ||
|
||
private String content; | ||
|
||
private String author; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Type type; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mindway.server.v2.domain.rec.entity; | ||
|
||
public enum Type { | ||
NOVEL, | ||
ESSAY | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.mindway.server.v2.domain.rec.presentation; | ||
|
||
import com.mindway.server.v2.domain.rec.entity.Type; | ||
import com.mindway.server.v2.domain.rec.presentation.dto.reqest.WriteRecRequest; | ||
import com.mindway.server.v2.domain.rec.service.WriteRecService; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v2/recommend") | ||
public class RecController { | ||
private final WriteRecService writeRecService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> writeRecBook (@RequestBody @Valid WriteRecRequest writeRecRequest, @RequestParam Type type){ | ||
writeRecService.execute(writeRecRequest, type); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.mindway.server.v2.domain.rec.presentation.dto.reqest; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class WriteRecRequest { | ||
@NotBlank | ||
private String title; | ||
|
||
@NotBlank | ||
private String content; | ||
|
||
@NotBlank | ||
private String author; | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mindway.server.v2.domain.rec.repository; | ||
|
||
import com.mindway.server.v2.domain.rec.entity.Rec; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface RecRepository extends JpaRepository<Rec, Long> { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mindway.server.v2.domain.rec.service; | ||
|
||
import com.mindway.server.v2.domain.rec.entity.Type; | ||
import com.mindway.server.v2.domain.rec.presentation.dto.reqest.WriteRecRequest; | ||
|
||
public interface WriteRecService { | ||
void execute(WriteRecRequest writeRecRequest, Type type); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mindway.server.v2.domain.rec.service.impl; | ||
|
||
import com.mindway.server.v2.domain.order.exception.NotAccessStudentException; | ||
import com.mindway.server.v2.domain.rec.entity.Rec; | ||
import com.mindway.server.v2.domain.rec.entity.Type; | ||
import com.mindway.server.v2.domain.rec.presentation.dto.reqest.WriteRecRequest; | ||
import com.mindway.server.v2.domain.rec.repository.RecRepository; | ||
import com.mindway.server.v2.domain.rec.service.WriteRecService; | ||
import com.mindway.server.v2.domain.rec.util.RecConverter; | ||
import com.mindway.server.v2.domain.user.entity.Authority; | ||
import com.mindway.server.v2.domain.user.entity.User; | ||
import com.mindway.server.v2.domain.user.util.UserUtil; | ||
import com.mindway.server.v2.global.annotation.ServiceWithTransaction; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@ServiceWithTransaction | ||
@RequiredArgsConstructor | ||
public class WriteRecServiceImpl implements WriteRecService { | ||
|
||
private final RecRepository recRepository; | ||
private final RecConverter recConverter; | ||
private final UserUtil userUtil; | ||
|
||
public void execute(WriteRecRequest writeRecRequest, Type type) { | ||
User user = userUtil.getCurrentUser(); | ||
|
||
if (user.getAuthority() == Authority.ROLE_STUDENT) { | ||
throw new NotAccessStudentException(); | ||
} | ||
|
||
recRepository.save(recConverter.toEntity(writeRecRequest, type)); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저희 코드 스타일이 컨버터로 변환하고 그걸 객체를 따로 만들어서 save하는 느낌인걸로 알고 있어요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 01ac3a2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.mindway.server.v2.domain.rec.util; | ||
|
||
import com.mindway.server.v2.domain.rec.entity.Rec; | ||
import com.mindway.server.v2.domain.rec.entity.Type; | ||
import com.mindway.server.v2.domain.rec.presentation.dto.reqest.WriteRecRequest; | ||
|
||
public interface RecConverter { | ||
Rec toEntity (WriteRecRequest writeRecRequest, Type type); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.mindway.server.v2.domain.rec.util.impl; | ||
|
||
import com.mindway.server.v2.domain.rec.entity.Rec; | ||
import com.mindway.server.v2.domain.rec.entity.Type; | ||
import com.mindway.server.v2.domain.rec.presentation.dto.reqest.WriteRecRequest; | ||
import com.mindway.server.v2.domain.rec.util.RecConverter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class RecConverterImpl implements RecConverter { | ||
|
||
public Rec toEntity(WriteRecRequest writeRecRequest, Type type) { | ||
return Rec.builder() | ||
.title(writeRecRequest.getTitle()) | ||
.content(writeRecRequest.getContent()) | ||
.author(writeRecRequest.getAuthor()) | ||
.type(type) | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | |
// rank | ||
.requestMatchers(HttpMethod.GET, "/api/v2/rank").authenticated() | ||
|
||
// recommend | ||
.requestMatchers(HttpMethod.POST, "/api/v2/recommend").hasAnyAuthority(Authority.ROLE_TEACHER.name(), Authority.ROLE_STUDENT.name()) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 권한 허용이 잘못 되어있는거같은데요? 수정부탁드려요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e36184f |
||
.anyRequest().authenticated() | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 알기론 숫자가 들어가면
@NotBlank
가 적합하지 않는 걸로 아는데 맞나요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
문자열이라 상관없는거 같아요