Skip to content

Commit

Permalink
more refactoring of updateAttributesOfShortUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhir committed Jun 5, 2021
1 parent 7f3d183 commit 6fb1f37
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions backend/src/main/java/org/bffl/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,24 @@ public int updateAttributesOfShortURL(@RequestBody POST_ShortURL body){
int id = body.getShort_url_id();

try {
if(body.getCustom_suffix().length() > 0) this.short_urlRepo.updateSuffixOfShortURL(id, body.getCustom_suffix());
if(body.getDelete_flag() != null) this.short_urlRepo.updateDeleteFlagOfShortURL(id, body.getDelete_flag());
if(body.getUpdate_flag() != null) this.short_urlRepo.updateUpdateFlagOfShortURL(id, body.getUpdate_flag());
if(body.getTarget_url().length() > 0) this.assigned_targetRepo.saveNewTargetOfShortURL(id, body.getTarget_url());
if(body.getScope() >= (System.currentTimeMillis() / 1000) + 3600) this.short_urlRepo.updateScopeOfShortURL(id, body.getScope());
if(body.getCustom_suffix().length() < 1 ||
body.getTarget_url().length() < 1 ||
body.getCustom_suffix() == null ||
body.getUpdate_flag() == null ||
body.getScope() >= (System.currentTimeMillis() / 1000) + 3600) {
return HttpStatus.BAD_REQUEST.value();
}
} catch (Exception exception) {
return HttpStatus.BAD_REQUEST.value();
} finally {
return HttpStatus.OK.value();
}

this.short_urlRepo.updateSuffixOfShortURL(id, body.getCustom_suffix());
this.short_urlRepo.updateDeleteFlagOfShortURL(id, body.getDelete_flag());
this.short_urlRepo.updateUpdateFlagOfShortURL(id, body.getUpdate_flag());
this.assigned_targetRepo.saveNewTargetOfShortURL(id, body.getTarget_url());
this.short_urlRepo.updateScopeOfShortURL(id, body.getScope());

return HttpStatus.OK.value();
}

@PostMapping("/updateTag")
Expand Down

0 comments on commit 6fb1f37

Please sign in to comment.