Skip to content

Commit

Permalink
Chore : 제목, 설명 중복 제외 #96
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoree912 committed Apr 19, 2024
1 parent 091a458 commit 8478051
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import com.drm.server.common.enums.SuccessCode;
import com.drm.server.controller.dto.request.ApplyRequest;
import com.drm.server.controller.dto.response.MediaApplicationResponse;
import com.drm.server.domain.dashboard.Dashboard;
import com.drm.server.domain.location.Location;
import com.drm.server.domain.media.Media;
import com.drm.server.domain.mediaApplication.MediaApplication;
import com.drm.server.domain.user.CustomUserDetails;
import com.drm.server.domain.user.User;
import com.drm.server.service.LocationService;
import com.drm.server.service.MediaApplicationService;
import com.drm.server.service.MediaService;
import com.drm.server.service.UserService;
import com.drm.server.service.*;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -42,6 +40,7 @@ public class ApplyController {
private final UserService userService;
private final LocationService locationService;
private final MediaApplicationService mediaApplicationService;
private final DashboardService dashboardService;
@PostMapping("{mediaId}/apply")
@Operation(summary = "광고 신청")
@ApiResponses(value = {
Expand Down Expand Up @@ -118,6 +117,25 @@ public void updateApply (@PathVariable Long mediaId, @PathVariable Long applyId,
User getUser = userService.getUser(userDetails.getUsername());

}
// @GetMapping("applies")
// @Operation(summary = "신청 리스트 조회")
// @ApiResponses(value = {
// @ApiResponse(responseCode = "200", description = "성공"),
// @ApiResponse(responseCode = "400", description = "요청 형식 혹은 요청 콘텐츠가 올바르지 않을 때,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
// @ApiResponse(responseCode = "401", description = "토큰 시간 만료, 형식 오류,로그아웃한 유저 접근,헤더에 값이 없을때",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
// @ApiResponse(responseCode = "403", description = "권한이 없는 경우",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
// @ApiResponse(responseCode = "404", description = "요청한 URL/URI와 일치하는 항목을 찾지 못함,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
// @ApiResponse(responseCode = "500", description = "외부 API 요청 실패, 정상적 수행을 할 수 없을 때,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
// })
// public ResponseEntity<APIResponse<List<MediaApplicationResponse.MediaApplicationInfo>>> getAllApplications( @AuthenticationPrincipal CustomUserDetails userDetails){
// User getUser = userService.getUser(userDetails.getUsername());
// List<Dashboard> dashboards = dashboardService.findByUser(getUser);
// List<MediaApplication> mediaApplications = mediaApplicationService.findByDashBoad(dashboards);
// List<MediaApplicationResponse.MediaApplicationInfo> totalApplicationInfos = mediaApplications.stream().map(MediaApplicationResponse.MediaApplicationInfo::new).collect(Collectors.toList());
// APIResponse response = APIResponse.of(SuccessCode.SELECT_SUCCESS, totalApplicationInfos);
// return new ResponseEntity<>(response, HttpStatus.OK);
// }

@GetMapping("{mediaId}/apply")
@Operation(summary = "신청 리스트 조회")
@ApiResponses(value = {
Expand All @@ -136,20 +154,8 @@ public ResponseEntity<APIResponse<List<MediaApplicationResponse.MediaApplication
APIResponse response = APIResponse.of(SuccessCode.SELECT_SUCCESS, totalApplicationInfos);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@PostMapping("/compare")
@Operation(summary = "비교하기")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(responseCode = "400", description = "요청 형식 혹은 요청 콘텐츠가 올바르지 않을 때,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "401", description = "토큰 시간 만료, 형식 오류,로그아웃한 유저 접근,헤더에 값이 없을때",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "403", description = "권한이 없는 경우",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", description = "요청한 URL/URI와 일치하는 항목을 찾지 못함,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "외부 API 요청 실패, 정상적 수행을 할 수 없을 때,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
public void compareApplication(@RequestBody ApplyRequest.MediaApplicationList mediaApplicationList ,@AuthenticationPrincipal CustomUserDetails userDetails ){
User getUser = userService.getUser(userDetails.getUsername());

}



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.drm.server.common.APIResponse;
import com.drm.server.common.ErrorResponse;
import com.drm.server.common.enums.SuccessCode;
import com.drm.server.controller.dto.request.ApplyRequest;
import com.drm.server.controller.dto.response.DashboardResponse;
import com.drm.server.domain.user.CustomUserDetails;
import com.drm.server.domain.user.User;
import com.drm.server.service.DashboardService;
import com.drm.server.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -28,7 +30,7 @@
@RequestMapping("api/v1/dashboard")
@RequiredArgsConstructor
@Tag(name = "Dashboard",description = "대시보드 API")
//@CrossOrigin(origins = "http://localhost:5173")
@CrossOrigin(origins = "http://localhost:5173")
public class DashBoardController {
@Autowired
UserService userService;
Expand Down Expand Up @@ -104,6 +106,18 @@ ResponseEntity<APIResponse<List<DashboardResponse.DashboardDataInfo>>> getBoardP
APIResponse response = APIResponse.of(SuccessCode.SELECT_SUCCESS, boards);
return new ResponseEntity<>(response, HttpStatus.OK);
}
@PostMapping("/compare")
@Operation(summary = "비교하기")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(responseCode = "400", description = "요청 형식 혹은 요청 콘텐츠가 올바르지 않을 때,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "401", description = "토큰 시간 만료, 형식 오류,로그아웃한 유저 접근,헤더에 값이 없을때",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "403", description = "권한이 없는 경우",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "404", description = "요청한 URL/URI와 일치하는 항목을 찾지 못함,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "외부 API 요청 실패, 정상적 수행을 할 수 없을 때,",content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
public void compareApplication(@RequestBody ApplyRequest.MediaApplicationList mediaApplicationList , @AuthenticationPrincipal CustomUserDetails userDetails ){

}

}
} bn b
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ public ResponseEntity<APIResponse<List<LocationResponse.LocationInfo>>> getLocat
return ResponseEntity.ok(response);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ResponseEntity<APIResponse<MediaApplicationResponse.TotalApplicationInfo>
User getUser =userService.getUser(userDetails.getUsername());
Location location = locationService.findById(create.getLocationId());

Dashboard dashboard = dashboardService.createDashboard(create, getUser);
Dashboard dashboard = dashboardService.createDashboard( getUser);
Media media= mediaService.createMedia(create, dashboard,multipartFile);
MediaApplication mediaApplication = mediaApplicationService.createMediaApplication(media,location,create.getStartDate(),create.getEndDate());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ public class MediaRequest {
@Setter
@Builder
public static class Create{
@Schema(description = "대시보드 제목",example = "이거슨 대시보드 제목")
private String dashboardTitle;
@Schema(description = "대시보드 설명",example = "이거슨 대시보드 설명")
private String dashboardDescription;
@Schema(description = "광고 제목",example = "이거슨 광고 제목")
private String advertisementTitle;
@Schema(description = "광고 설명",example = "이거슨 광고 설명")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ public static class DashboardInfo{
private String mediaUrl;

@Builder
public DashboardInfo(Dashboard dashboard){
this.title = dashboard.getTitle();
this.description = dashboard.getDescription();
this.dashboardId = dashboard.getDashboardId();
}
@Builder
public DashboardInfo(String title, String description, Long dashboardId, String mediaUrl){
public DashboardInfo(Dashboard dashboard, String mediaUrl){
this.title = title;
this.description = description;
this.dashboardId = dashboardId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ public static class MediaInfo{
private String title;
@Schema(description = "광고 설명",example = "이것은 광고 설명")
private String description;
private DashboardResponse.DashboardInfo dashboard;
@Schema(description = "광고 id",example = "1")
private Long dashboardId;

public MediaInfo(Dashboard dashboard) {
this.mediaId = dashboard.getMedia().getMediaId();
this.mediaLink = dashboard.getMedia().getMediaLink();
this.title = dashboard.getMedia().getTitle();
this.description = dashboard.getMedia().getDescription();
this.dashboard = new DashboardResponse.DashboardInfo(dashboard);
this.dashboardId = dashboard.getDashboardId();
}

public MediaInfo(Media media) {
this.mediaId = media.getMediaId();
this.mediaLink = media.getMediaLink();
this.title = media.getTitle();
this.description = media.getDescription();
this.dashboard = new DashboardResponse.DashboardInfo(media.getDashboard());
this.dashboardId = media.getDashboard().getDashboardId();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.drm.server.domain.dashboard;

import com.drm.server.common.BaseTimeEntity;
import com.drm.server.domain.dailyMediaBoard.DailyMediaBoard;
import com.drm.server.domain.detectedface.DataConverter;
import com.drm.server.domain.media.Media;
import com.drm.server.domain.user.User;
import jakarta.persistence.*;
Expand All @@ -9,6 +11,10 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Entity
@Builder
@NoArgsConstructor
Expand All @@ -20,8 +26,14 @@ public class Dashboard extends BaseTimeEntity {
private Long dashboardId;

@Column
private String title;
private String description;
@Convert(converter = DataConverter.class)
private List<Long> avgHourlyPassedCount;
private float avgStaringTime;
private Long maleInterestCnt;
// 관심을 표현한 여자의 인원 수
private Long femaleInterestCnt;



@ManyToOne
@JoinColumn(name = "user_id")
Expand All @@ -30,8 +42,13 @@ public class Dashboard extends BaseTimeEntity {
@OneToOne(mappedBy = "dashboard",orphanRemoval = true)
private Media media;

public static Dashboard toEntity(String title, String description, User user){
return Dashboard.builder().title(title).description(description).user(user).build();
public static Dashboard toEntity( User user){
return Dashboard.builder()
.user(user)
.avgHourlyPassedCount( new ArrayList<>(Collections.nCopies(24, 0L)))
.maleInterestCnt(0L).femaleInterestCnt(0L)
.avgStaringTime(0F)
.build();
}

public void setMedia(Media media) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ public interface DashboardRepository extends JpaRepository<Dashboard, Long> {
Optional<List<Dashboard>> findByUser(User user);
Optional<List<Dashboard>> findAllByUser(User user);

boolean existsByTitle(String title);

void deleteByTitle(String title);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class Media extends BaseTimeEntity {
@OneToMany(mappedBy = "media")
private List<MediaApplication> mediaApplicationList = new ArrayList<>();

public Media(Dashboard dashboard) {
dashboard.getMedia();
}

public static Media toEntity(MediaRequest.Create mediaRequest,String fileName, String mediaLink,Dashboard dashboard){
return Media.builder().fileName(fileName).mediaLink(mediaLink).title(mediaRequest.getAdvertisementTitle()).description(mediaRequest.getAdvertisementDescription()).dashboard(dashboard).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

@Repository
public interface MediaRepository extends JpaRepository<Media, Long> {
Media findByTitle(String titleName);
Boolean existsByTitle(String title);

Optional<Media> findByDashboard(Dashboard dashboard);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class DashboardService {
private final MediaApplicationService mediaApplicationService;
private final LocationService locationService;

public Dashboard createDashboard(MediaRequest.Create create, User user){
Dashboard dashboard = Dashboard.toEntity(create.getDashboardTitle(), create.getDashboardDescription(), user);
public Dashboard createDashboard( User user){
Dashboard dashboard = Dashboard.toEntity(user);
dashboardRepository.save(dashboard);
String msg = "DASHBOARD CREATED :" + Long.toString(dashboard.getDashboardId());
log.info(msg);
Expand All @@ -45,11 +45,6 @@ public void deleteDashboardById(Long dashboardId){
log.info(msg);
}

public void deleteDashboardByTitle(String title){
dashboardRepository.deleteByTitle(title);
String msg = "DASHBOARD DELETED :" + title;
log.info(msg);
}

public List<Dashboard> findByUser(User user){
List<Dashboard> dashboards = dashboardRepository.findByUser(user).orElse(Collections.emptyList());
Expand All @@ -64,8 +59,7 @@ public List<DashboardResponse.DashboardInfo> getDashboardsByUserId(Long userId)

for(Dashboard dashboard : dashboards){
Media media = mediaService.findOneMediaByDashboard(dashboard);
DashboardResponse.DashboardInfo info = new DashboardResponse.DashboardInfo(dashboard.getTitle(), dashboard.getDescription(),
dashboard.getDashboardId(), media.getMediaLink());
DashboardResponse.DashboardInfo info = new DashboardResponse.DashboardInfo(dashboard,media.getMediaLink());
dashboardInfos.add(info);
}
String msg = "DASHBOARD SEARCHED MADE BY USER:" + Long.toString(userId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.drm.server.service;

import com.drm.server.controller.dto.response.MediaApplicationResponse;
import com.drm.server.domain.dashboard.Dashboard;
import com.drm.server.domain.location.Location;
import com.drm.server.domain.location.LocationRepository;
import com.drm.server.domain.media.Media;
Expand Down Expand Up @@ -96,4 +97,5 @@ public void deleteVerify(MediaApplication mediaApplication, User user){
// > accept의 경우 삭제되면 안되기때문에 해당 verify는 삭제방지용으로 했던것 , accept가 된 상태에서 Return해버리면 accept가 된 신청목록 삭제됨
if(!mediaApplication.getStatus().equals(WAITING)) throw new ForbiddenException("신청 대기일때만 삭제 가능합니다");
}

}

0 comments on commit 8478051

Please sign in to comment.